cryptopunks 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +3 -0
- data/config/spritesheet.csv +237 -0
- data/config/spritesheet.png +0 -0
- data/lib/cryptopunks/composite.rb +6 -5
- data/lib/cryptopunks/generator.rb +204 -0
- data/lib/cryptopunks/image.rb +1 -1
- data/lib/cryptopunks/version.rb +1 -1
- data/lib/cryptopunks.rb +25 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 40ec7d396eeeca8b4363ac52ca11cd4bb28c6ec9aa88c026e605378af16c8369
|
|
4
|
+
data.tar.gz: a111a3dbbec40626e42f86a295adc00b90979c53081b43ed8d96b30ef5e0bdba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c0b5c1ac7ffa4d0db4677f8541d1f03c72726b50abfbd2da62ef97c4047f43373f58234b8ad19b4a000c60d70f1881c2aa0719a0a3930a59387a67a6446a796
|
|
7
|
+
data.tar.gz: 8b8e1ab287df0f36543c23491e5727c688672dcc898b02086a4332bc6bcf6f46f8b5cf4ee159ad6ce7d09e344c04f5cd82510b5a7d1d697cd17626bc5914aab6
|
data/Manifest.txt
CHANGED
|
@@ -24,11 +24,14 @@ config/original/ape-male.txt
|
|
|
24
24
|
config/original/human-female.txt
|
|
25
25
|
config/original/human-male.txt
|
|
26
26
|
config/original/zombie-male.txt
|
|
27
|
+
config/spritesheet.csv
|
|
28
|
+
config/spritesheet.png
|
|
27
29
|
lib/cryptopunks.rb
|
|
28
30
|
lib/cryptopunks/attributes.rb
|
|
29
31
|
lib/cryptopunks/colors.rb
|
|
30
32
|
lib/cryptopunks/composite.rb
|
|
31
33
|
lib/cryptopunks/dataset.rb
|
|
34
|
+
lib/cryptopunks/generator.rb
|
|
32
35
|
lib/cryptopunks/image.rb
|
|
33
36
|
lib/cryptopunks/structs.rb
|
|
34
37
|
lib/cryptopunks/version.rb
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
id, name, gender, type, more_names
|
|
2
|
+
0, Male 1, m, Archetype - Human,
|
|
3
|
+
1, Male 2, m, Archetype - Human,
|
|
4
|
+
2, Male 3, m, Archetype - Human,
|
|
5
|
+
3, Male 4, m, Archetype - Human,
|
|
6
|
+
4, Female 1, f, Archetype - Human,
|
|
7
|
+
5, Female 2, f, Archetype - Human,
|
|
8
|
+
6, Female 3, f, Archetype - Human,
|
|
9
|
+
7, Female 4, f, Archetype - Human,
|
|
10
|
+
8, Zombie, m, Archetype - Zombie,
|
|
11
|
+
9, Zombie Female, f, Archetype - Zombie,
|
|
12
|
+
10, Ape, m, Archetype - Ape,
|
|
13
|
+
11, Ape Female, f, Archetype - Ape,
|
|
14
|
+
12, Alien, m, Archetype - Alien,
|
|
15
|
+
13, Alien Female, f, Archetype - Alien,
|
|
16
|
+
14, Demon, m, Archetype - Demon,
|
|
17
|
+
15, Demon Female, f, Archetype - Demon,
|
|
18
|
+
16, Mummy, m, Archetype - Mummy,
|
|
19
|
+
17, Mummy Female, f, Archetype - Mummy,
|
|
20
|
+
18, Orc, m, Archetype - Orc,
|
|
21
|
+
19, Orc Female, f, Archetype - Orc,
|
|
22
|
+
20, Robot, m, Archetype - Robot,
|
|
23
|
+
21, Robot Female, f, Archetype - Robot,
|
|
24
|
+
22, Skeleton, m, Archetype - Skeleton,
|
|
25
|
+
23, Skeleton Female, f, Archetype - Skeleton,
|
|
26
|
+
24, Vampire, m, Archetype - Vampire,
|
|
27
|
+
25, Vampire Female, f, Archetype - Vampire,
|
|
28
|
+
26, Zombie (Ape), m, Archetype - Zombie,
|
|
29
|
+
27, Alien (Ape), m, Archetype - Alien,
|
|
30
|
+
28, Alien 0°, m, Archetype - Alien,
|
|
31
|
+
29, Alien 30°, m, Archetype - Alien,
|
|
32
|
+
30, Alien 60°, m, Archetype - Alien,
|
|
33
|
+
31, Alien 90°, m, Archetype - Alien,
|
|
34
|
+
32, Alien 120°, m, Archetype - Alien,
|
|
35
|
+
33, Alien 150°, m, Archetype - Alien,
|
|
36
|
+
34, Alien 180°, m, Archetype - Alien,
|
|
37
|
+
35, Alien 210°, m, Archetype - Alien,
|
|
38
|
+
36, Alien 240°, m, Archetype - Alien,
|
|
39
|
+
37, Alien 270°, m, Archetype - Alien,
|
|
40
|
+
38, Alien 300°, m, Archetype - Alien,
|
|
41
|
+
39, Alien 330°, m, Archetype - Alien,
|
|
42
|
+
40, Alien (Ape) 0°, m, Archetype - Alien,
|
|
43
|
+
41, Alien (Ape) 30°, m, Archetype - Alien,
|
|
44
|
+
42, Alien (Ape) 60°, m, Archetype - Alien,
|
|
45
|
+
43, Alien (Ape) 90°, m, Archetype - Alien,
|
|
46
|
+
44, Alien (Ape) 120°, m, Archetype - Alien,
|
|
47
|
+
45, Alien (Ape) 150°, m, Archetype - Alien,
|
|
48
|
+
46, Alien (Ape) 180°, m, Archetype - Alien,
|
|
49
|
+
47, Alien (Ape) 210°, m, Archetype - Alien,
|
|
50
|
+
48, Alien (Ape) 240°, m, Archetype - Alien,
|
|
51
|
+
49, Alien (Ape) 270°, m, Archetype - Alien,
|
|
52
|
+
50, Alien (Ape) 300°, m, Archetype - Alien,
|
|
53
|
+
51, Alien (Ape) 330°, m, Archetype - Alien,
|
|
54
|
+
52, Alien Female 0°, f, Archetype - Alien,
|
|
55
|
+
53, Alien Female 30°, f, Archetype - Alien,
|
|
56
|
+
54, Alien Female 60°, f, Archetype - Alien,
|
|
57
|
+
55, Alien Female 90°, f, Archetype - Alien,
|
|
58
|
+
56, Alien Female 120°, f, Archetype - Alien,
|
|
59
|
+
57, Alien Female 150°, f, Archetype - Alien,
|
|
60
|
+
58, Alien Female 180°, f, Archetype - Alien,
|
|
61
|
+
59, Alien Female 210°, f, Archetype - Alien,
|
|
62
|
+
60, Alien Female 240°, f, Archetype - Alien,
|
|
63
|
+
61, Alien Female 270°, f, Archetype - Alien,
|
|
64
|
+
62, Alien Female 300°, f, Archetype - Alien,
|
|
65
|
+
63, Alien Female 330°, f, Archetype - Alien,
|
|
66
|
+
64, 3D Glasses, m, Attribute,
|
|
67
|
+
65, 3D Glasses, f, Attribute,
|
|
68
|
+
66, Bandana, m, Attribute,
|
|
69
|
+
67, Bandana, f, Attribute,
|
|
70
|
+
68, Beanie, m, Attribute,
|
|
71
|
+
69, Beanie, f, Attribute,
|
|
72
|
+
70, Big Beard, m, Attribute,
|
|
73
|
+
71, Big Shades, m, Attribute,
|
|
74
|
+
72, Big Shades, f, Attribute,
|
|
75
|
+
73, Black Lipstick, f, Attribute,
|
|
76
|
+
74, Blonde Bob, f, Attribute,
|
|
77
|
+
75, Blonde Short, f, Attribute,
|
|
78
|
+
76, Blue Eye Shadow, f, Attribute,
|
|
79
|
+
77, Buck Teeth, m, Attribute,
|
|
80
|
+
78, Cap, m, Attribute,
|
|
81
|
+
79, Cap, f, Attribute,
|
|
82
|
+
80, Cap Forward, m, Attribute,
|
|
83
|
+
81, Cap Forward, f, Attribute,
|
|
84
|
+
82, Chinstrap, m, Attribute,
|
|
85
|
+
83, Choker, f, Attribute,
|
|
86
|
+
84, Cigarette, m, Attribute,
|
|
87
|
+
85, Cigarette, f, Attribute,
|
|
88
|
+
86, Classic Shades, m, Attribute,
|
|
89
|
+
87, Classic Shades, f, Attribute,
|
|
90
|
+
88, Clown Eyes Blue, m, Attribute,
|
|
91
|
+
89, Clown Eyes Blue, f, Attribute,
|
|
92
|
+
90, Clown Eyes Green, m, Attribute,
|
|
93
|
+
91, Clown Eyes Green, f, Attribute,
|
|
94
|
+
92, Clown Hair Green, m, Attribute,
|
|
95
|
+
93, Clown Hair Green, f, Attribute,
|
|
96
|
+
94, Clown Nose, m, Attribute,
|
|
97
|
+
95, Clown Nose, f, Attribute,
|
|
98
|
+
96, Cowboy Hat, m, Attribute,
|
|
99
|
+
97, Cowboy Hat, f, Attribute,
|
|
100
|
+
98, Crazy Hair, m, Attribute,
|
|
101
|
+
99, Crazy Hair, f, Attribute,
|
|
102
|
+
100, Dark Hair, f, Attribute,
|
|
103
|
+
101, Do-rag, m, Attribute,
|
|
104
|
+
102, Do-rag, f, Attribute,
|
|
105
|
+
103, Earring, m, Attribute,
|
|
106
|
+
104, Earring, f, Attribute,
|
|
107
|
+
105, Eye Mask, m, Attribute,
|
|
108
|
+
106, Eye Mask, f, Attribute,
|
|
109
|
+
107, Eye Patch, m, Attribute,
|
|
110
|
+
108, Eye Patch, f, Attribute,
|
|
111
|
+
109, Fedora, m, Attribute,
|
|
112
|
+
110, Fedora, f, Attribute,
|
|
113
|
+
111, Front Beard, m, Attribute,
|
|
114
|
+
112, Front Beard Dark, m, Attribute,
|
|
115
|
+
113, Frown, m, Attribute,
|
|
116
|
+
114, Frumpy Hair, m, Attribute,
|
|
117
|
+
115, Frumpy Hair, f, Attribute,
|
|
118
|
+
116, Green Eye Shadow, f, Attribute,
|
|
119
|
+
117, Goat, m, Attribute,
|
|
120
|
+
118, Gold Chain, m, Attribute,
|
|
121
|
+
119, Gold Chain, f, Attribute,
|
|
122
|
+
120, Half Shaved, f, Attribute,
|
|
123
|
+
121, Handlebars, m, Attribute,
|
|
124
|
+
122, Headband, m, Attribute,
|
|
125
|
+
123, Headband, f, Attribute,
|
|
126
|
+
124, Hoodie, m, Attribute,
|
|
127
|
+
125, Hoodie, f, Attribute,
|
|
128
|
+
126, Horned Rim Glasses, m, Attribute,
|
|
129
|
+
127, Horned Rim Glasses, f, Attribute,
|
|
130
|
+
128, Hot Lipstick, f, Attribute,
|
|
131
|
+
129, Knitted Cap, m, Attribute,
|
|
132
|
+
130, Knitted Cap, f, Attribute,
|
|
133
|
+
131, Luxurious Beard, m, Attribute,
|
|
134
|
+
132, Medical Mask, m, Attribute,
|
|
135
|
+
133, Medical Mask, f, Attribute,
|
|
136
|
+
134, Messy Hair, m, Attribute,
|
|
137
|
+
135, Messy Hair, f, Attribute,
|
|
138
|
+
136, Mohawk, m, Attribute,
|
|
139
|
+
137, Mohawk, f, Attribute,
|
|
140
|
+
138, Mohawk Dark, m, Attribute,
|
|
141
|
+
139, Mohawk Dark, f, Attribute,
|
|
142
|
+
140, Mohawk Thin, m, Attribute,
|
|
143
|
+
141, Mohawk Thin, f, Attribute,
|
|
144
|
+
142, Mole, m, Attribute,
|
|
145
|
+
143, Mole, f, Attribute,
|
|
146
|
+
144, Mustache, m, Attribute,
|
|
147
|
+
145, Muttonchops, m, Attribute,
|
|
148
|
+
146, Nerd Glasses, m, Attribute,
|
|
149
|
+
147, Nerd Glasses, f, Attribute,
|
|
150
|
+
148, Normal Beard, m, Attribute,
|
|
151
|
+
149, Normal Beard Black, m, Attribute,
|
|
152
|
+
150, Orange Side, f, Attribute,
|
|
153
|
+
151, Peak Spike, m, Attribute,
|
|
154
|
+
152, Pigtails, f, Attribute,
|
|
155
|
+
153, Pilot Helmet, f, Attribute,
|
|
156
|
+
154, Pink with Hat, f, Attribute,
|
|
157
|
+
155, Pipe, m, Attribute,
|
|
158
|
+
156, Pipe, f, Attribute,
|
|
159
|
+
157, Police Cap, m, Attribute,
|
|
160
|
+
158, Police Cap, f, Attribute,
|
|
161
|
+
159, Purple Eye Shadow, f, Attribute,
|
|
162
|
+
160, Purple Hair, m, Attribute,
|
|
163
|
+
161, Purple Hair, f, Attribute,
|
|
164
|
+
162, Purple Lipstick, f, Attribute,
|
|
165
|
+
163, Red Mohawk, f, Attribute,
|
|
166
|
+
164, Regular Shades, m, Attribute,
|
|
167
|
+
165, Regular Shades, f, Attribute,
|
|
168
|
+
166, Rosy Cheeks, m, Attribute,
|
|
169
|
+
167, Rosy Cheeks, f, Attribute,
|
|
170
|
+
168, Shadow Beard, m, Attribute,
|
|
171
|
+
169, Shaved Head, m, Attribute,
|
|
172
|
+
170, Shaved Head, f, Attribute,
|
|
173
|
+
171, Silver Chain, m, Attribute,
|
|
174
|
+
172, Silver Chain, f, Attribute,
|
|
175
|
+
173, Small Shades, m, Attribute,
|
|
176
|
+
174, Small Shades, f, Attribute,
|
|
177
|
+
175, Smile, m, Attribute,
|
|
178
|
+
176, Spots, m, Attribute,
|
|
179
|
+
177, Spots, f, Attribute,
|
|
180
|
+
178, Straight Hair, f, Attribute,
|
|
181
|
+
179, Straight Hair Blonde, f, Attribute,
|
|
182
|
+
180, Straight Hair Dark, f, Attribute,
|
|
183
|
+
181, Stringy Hair, m, Attribute,
|
|
184
|
+
182, Stringy Hair, f, Attribute,
|
|
185
|
+
183, Tassle Hat, f, Attribute,
|
|
186
|
+
184, Tiara, f, Attribute,
|
|
187
|
+
185, Top Hat, m, Attribute,
|
|
188
|
+
186, Top Hat, f, Attribute,
|
|
189
|
+
187, Vampire Hair, m, Attribute,
|
|
190
|
+
188, Vape, m, Attribute,
|
|
191
|
+
189, Vape, f, Attribute,
|
|
192
|
+
190, VR, m, Attribute,
|
|
193
|
+
191, VR, f, Attribute,
|
|
194
|
+
192, Welding Goggles, f, Attribute,
|
|
195
|
+
193, Wild Blonde, f, Attribute,
|
|
196
|
+
194, Wild Hair, m, Attribute,
|
|
197
|
+
195, Wild Hair, f, Attribute,
|
|
198
|
+
196, Wild White Hair, f, Attribute,
|
|
199
|
+
197, Bear Hood, m, Attribute,
|
|
200
|
+
198, Bear Hood, f, Attribute,
|
|
201
|
+
199, Birthday Hat, m, Attribute,
|
|
202
|
+
200, Birthday Hat, f, Attribute,
|
|
203
|
+
201, Bow, f, Attribute,
|
|
204
|
+
202, Cigar, m, Attribute,
|
|
205
|
+
203, Cigar, f, Attribute,
|
|
206
|
+
204, Crown, m, Attribute,
|
|
207
|
+
205, Crown, f, Attribute,
|
|
208
|
+
206, Flowers, f, Attribute,
|
|
209
|
+
207, Frog Hood, m, Attribute,
|
|
210
|
+
208, Frog Hood, f, Attribute,
|
|
211
|
+
209, Gold Diamond Necklace, m, Attribute,
|
|
212
|
+
210, Gold Diamond Necklace, f, Attribute,
|
|
213
|
+
211, Heart Shades, m, Attribute,
|
|
214
|
+
212, Heart Shades, f, Attribute,
|
|
215
|
+
213, Jester Hat, m, Attribute,
|
|
216
|
+
214, Jester Hat, f, Attribute,
|
|
217
|
+
215, Laser Eyes, m, Attribute,
|
|
218
|
+
216, Laser Eyes Gold, m, Attribute,
|
|
219
|
+
217, Pink Lipstick, f, Attribute,
|
|
220
|
+
218, Red Lipstick, f, Attribute,
|
|
221
|
+
219, Santa Hat, m, Attribute,
|
|
222
|
+
220, Santa Hat, f, Attribute,
|
|
223
|
+
221, Silver Earring, m, Attribute,
|
|
224
|
+
222, Silver Earring, f, Attribute,
|
|
225
|
+
223, Ski Googles, m, Attribute,
|
|
226
|
+
224, Ski Googles, f, Attribute,
|
|
227
|
+
225, Sombrero, m, Attribute,
|
|
228
|
+
226, Sombrero, f, Attribute,
|
|
229
|
+
227, Sun Hat, m, Attribute,
|
|
230
|
+
228, Sun Hat, f, Attribute,
|
|
231
|
+
229, Superhero Tiara, f, Attribute,
|
|
232
|
+
230, Tears, m, Attribute,
|
|
233
|
+
231, Tears, f, Attribute,
|
|
234
|
+
232, Viking Helmet, m, Attribute,
|
|
235
|
+
233, Viking Helmet, f, Attribute,
|
|
236
|
+
234, Winter Hat, m, Attribute,
|
|
237
|
+
235, Winter Hat, f, Attribute,
|
|
Binary file
|
|
@@ -9,7 +9,11 @@ module Cryptopunks
|
|
|
9
9
|
Digest::SHA256.digest( data ).unpack( 'H*' )[0]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
PUNK_HEIGHT = 24
|
|
14
|
+
PUNK_WIDTH = 24
|
|
15
|
+
|
|
16
|
+
def self.read( path='./punks.png', width: PUNK_WIDTH, height: PUNK_HEIGHT )
|
|
13
17
|
data = File.open( path, 'rb' ) { |f| f.read }
|
|
14
18
|
|
|
15
19
|
hexdigest = sha256( data ) ## check sha256 checksum
|
|
@@ -21,13 +25,10 @@ module Cryptopunks
|
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
img = ChunkyPNG::Image.from_blob( data )
|
|
24
|
-
new( img )
|
|
28
|
+
new( img, width: width, height: height )
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
|
|
28
|
-
PUNK_HEIGHT = 24
|
|
29
|
-
PUNK_WIDTH = 24
|
|
30
|
-
|
|
31
32
|
def initialize( *args, width: PUNK_WIDTH,
|
|
32
33
|
height: PUNK_HEIGHT )
|
|
33
34
|
super
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
|
|
2
|
+
module Cryptopunks
|
|
3
|
+
|
|
4
|
+
class Metadata
|
|
5
|
+
### todo/fix:
|
|
6
|
+
## move into Punks::Metadata or such
|
|
7
|
+
class Sprite
|
|
8
|
+
attr_reader :id, :name, :type, :gender
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def initialize( id:,
|
|
12
|
+
name:,
|
|
13
|
+
type:,
|
|
14
|
+
gender: )
|
|
15
|
+
@id = id # zero-based index eg. 0,1,2,3, etc.
|
|
16
|
+
@name = name
|
|
17
|
+
@type = type
|
|
18
|
+
@gender = gender
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
## todo/check - find better names for type attribute/archetypes?
|
|
22
|
+
## use (alternate name/alias) base or face for archetypes? any others?
|
|
23
|
+
def attribute?() @type.downcase.start_with?( 'attribute' ); end
|
|
24
|
+
def archetype?() @type.downcase.start_with?( 'archetype' ); end
|
|
25
|
+
end # class Metadata::Sprite
|
|
26
|
+
end # class Metadata
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Generator
|
|
32
|
+
|
|
33
|
+
######
|
|
34
|
+
# static helpers - (turn into "true" static self.class methods - why? why not?)
|
|
35
|
+
#
|
|
36
|
+
def normalize_key( str )
|
|
37
|
+
str.downcase.gsub(/[ ()°_-]/, '').strip
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def normalize_gender( str )
|
|
41
|
+
## e.g. Female => f
|
|
42
|
+
## F => f
|
|
43
|
+
## always return f or m
|
|
44
|
+
str.downcase[0]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def build_attributes_by_name( recs )
|
|
49
|
+
h = {}
|
|
50
|
+
recs.each_with_index do |rec|
|
|
51
|
+
key = normalize_key( rec.name )
|
|
52
|
+
key << "_(#{rec.gender})" if rec.attribute?
|
|
53
|
+
|
|
54
|
+
if h[ key ]
|
|
55
|
+
puts "!!! ERROR - attribute name is not unique:"
|
|
56
|
+
pp rec
|
|
57
|
+
puts "duplicate:"
|
|
58
|
+
pp h[key]
|
|
59
|
+
exit 1
|
|
60
|
+
end
|
|
61
|
+
h[ key ] = rec
|
|
62
|
+
end
|
|
63
|
+
## pp h
|
|
64
|
+
h
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def build_recs( recs ) ## build and normalize (meta data) records
|
|
69
|
+
|
|
70
|
+
## sort by id
|
|
71
|
+
recs = recs.sort do |l,r|
|
|
72
|
+
l['id'].to_i( 10 ) <=> r['id'].to_i( 10 ) # use base10 (decimal)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
## assert all recs are in order by id (0 to size)
|
|
76
|
+
recs.each_with_index do |rec, exp_id|
|
|
77
|
+
id = rec['id'].to_i(10)
|
|
78
|
+
if id != exp_id
|
|
79
|
+
puts "!! ERROR - meta data record ids out-of-order - expected id #{exp_id}; got #{id}"
|
|
80
|
+
exit 1
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
## convert to "wrapped / immutable" kind-of struct
|
|
85
|
+
recs = recs.map do |rec|
|
|
86
|
+
id = rec['id'].to_i( 10 )
|
|
87
|
+
name = rec['name']
|
|
88
|
+
gender = normalize_gender( rec['gender'] )
|
|
89
|
+
type = rec['type']
|
|
90
|
+
|
|
91
|
+
Metadata::Sprite.new(
|
|
92
|
+
id: id,
|
|
93
|
+
name: name,
|
|
94
|
+
type: type,
|
|
95
|
+
gender: gender)
|
|
96
|
+
end
|
|
97
|
+
recs
|
|
98
|
+
end # method build_recs
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def initialize( image_path="./spritesheet.png",
|
|
104
|
+
meta_path="./spritesheet.csv" )
|
|
105
|
+
@sheet = Pixelart::ImageComposite.read( image_path )
|
|
106
|
+
recs = CsvHash.read( meta_path )
|
|
107
|
+
|
|
108
|
+
@recs = build_recs( recs )
|
|
109
|
+
|
|
110
|
+
## lookup by "case/space-insensitive" name / key
|
|
111
|
+
@attributes_by_name = build_attributes_by_name( @recs )
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def spritesheet() @sheet; end
|
|
116
|
+
alias_method :sheet, :spritesheet
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def find_meta( q, gender: nil ) ## gender (m/f) required for attributes!!!
|
|
123
|
+
|
|
124
|
+
key = normalize_key( q ) ## normalize q(uery) string/symbol
|
|
125
|
+
key << "_(#{normalize_gender( gender )})" if gender
|
|
126
|
+
|
|
127
|
+
rec = @attributes_by_name[ key ]
|
|
128
|
+
if rec
|
|
129
|
+
puts " lookup >#{key}< => #{rec.id}: #{rec.name} / #{rec.type} (#{rec.gender})"
|
|
130
|
+
# pp rec
|
|
131
|
+
else
|
|
132
|
+
puts "!! WARN - no lookup found for key >#{key}<"
|
|
133
|
+
end
|
|
134
|
+
rec
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def find( q, gender: nil ) ## gender (m/f) required for attributes!!!
|
|
139
|
+
rec = find_meta( q, gender: gender )
|
|
140
|
+
|
|
141
|
+
## return image if record found
|
|
142
|
+
rec ? @sheet[ rec.id ] : nil
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def to_recs( *values )
|
|
149
|
+
archetype_name = values[0]
|
|
150
|
+
|
|
151
|
+
### todo/fix: check for nil/not found!!!!
|
|
152
|
+
archetype = find_meta( archetype_name )
|
|
153
|
+
if archetype.nil?
|
|
154
|
+
puts "!! ERROR - archetype >#{archetype}< not found; sorry"
|
|
155
|
+
exit 1
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
recs = [archetype]
|
|
159
|
+
|
|
160
|
+
attribute_names = values[1..-1]
|
|
161
|
+
## note: attribute lookup requires gender from archetype!!!!
|
|
162
|
+
attribute_gender = archetype.gender
|
|
163
|
+
|
|
164
|
+
attribute_names.each do |attribute_name|
|
|
165
|
+
attribute = find_meta( attribute_name, gender: attribute_gender )
|
|
166
|
+
if attribute.nil?
|
|
167
|
+
puts "!! ERROR - attribute >#{attribute_name}< for (#{attribute_gender}) not found; sorry"
|
|
168
|
+
exit 1
|
|
169
|
+
end
|
|
170
|
+
recs << attribute
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
recs
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def generate_image( *values, background: nil )
|
|
180
|
+
|
|
181
|
+
ids = if values[0].is_a?( Integer ) ## assume integer number (indexes)
|
|
182
|
+
values
|
|
183
|
+
else ## assume strings (names)
|
|
184
|
+
to_recs( *values ).map { |rec| rec.id }
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
punk = Pixelart::Image.new( 24, 24 )
|
|
189
|
+
|
|
190
|
+
if background ## for now assume background is (simply) color
|
|
191
|
+
punk.compose!( Pixelart::Image.new( 24, 24, background ) )
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
ids.each do |id|
|
|
195
|
+
punk.compose!( @sheet[ id ] )
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
punk
|
|
199
|
+
end
|
|
200
|
+
alias_method :generate, :generate_image
|
|
201
|
+
|
|
202
|
+
end # class Generator
|
|
203
|
+
|
|
204
|
+
end # module Cryptopunks
|
data/lib/cryptopunks/image.rb
CHANGED
data/lib/cryptopunks/version.rb
CHANGED
data/lib/cryptopunks.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'csvreader'
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
## extra stdlibs
|
|
8
|
-
require 'digest'
|
|
8
|
+
require 'digest' ## move/add to pixelart upstream - why? why not?
|
|
9
9
|
require 'optparse'
|
|
10
10
|
|
|
11
11
|
|
|
@@ -27,6 +27,30 @@ require 'cryptopunks/dataset'
|
|
|
27
27
|
require 'cryptopunks/colors'
|
|
28
28
|
require 'cryptopunks/image'
|
|
29
29
|
|
|
30
|
+
require 'cryptopunks/generator'
|
|
31
|
+
|
|
32
|
+
###
|
|
33
|
+
## add convenience pre-configurated generatored with build-in spritesheet (see config)
|
|
34
|
+
|
|
35
|
+
module Cryptopunks
|
|
36
|
+
|
|
37
|
+
def self.generator
|
|
38
|
+
@generator ||= Generator.new( "#{root}/config/spritesheet.png",
|
|
39
|
+
"#{root}/config/spritesheet.csv" )
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Image
|
|
43
|
+
def self.generate( *values )
|
|
44
|
+
img = Cryptopunks.generator.generate( *values )
|
|
45
|
+
## note: unwrap inner image before passing on to c'tor (requires ChunkyPNG image for now)
|
|
46
|
+
new( img.image )
|
|
47
|
+
end
|
|
48
|
+
end # class Image
|
|
49
|
+
end # module Cryptopunks
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
30
54
|
|
|
31
55
|
|
|
32
56
|
module Cryptopunks
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cryptopunks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gerald Bauer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pixelart
|
|
@@ -131,11 +131,14 @@ files:
|
|
|
131
131
|
- config/original/human-female.txt
|
|
132
132
|
- config/original/human-male.txt
|
|
133
133
|
- config/original/zombie-male.txt
|
|
134
|
+
- config/spritesheet.csv
|
|
135
|
+
- config/spritesheet.png
|
|
134
136
|
- lib/cryptopunks.rb
|
|
135
137
|
- lib/cryptopunks/attributes.rb
|
|
136
138
|
- lib/cryptopunks/colors.rb
|
|
137
139
|
- lib/cryptopunks/composite.rb
|
|
138
140
|
- lib/cryptopunks/dataset.rb
|
|
141
|
+
- lib/cryptopunks/generator.rb
|
|
139
142
|
- lib/cryptopunks/image.rb
|
|
140
143
|
- lib/cryptopunks/structs.rb
|
|
141
144
|
- lib/cryptopunks/version.rb
|