-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_v2.rb
57 lines (35 loc) · 1.17 KB
/
generate_v2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
####
# to run use:
# $ ruby generate_v2.rb
require 'punks'
recs = read_csv( "./ordinalpunks_v2.csv" )
puts " #{recs.size} record(s)"
def rec_to_attributes( rec )
type = rec['type']
gender = rec['gender']
skin_tone = rec['skin_tone']
# note: merge type+gender+skin_tone into one attribute
base = "#{type} #{gender}"
base << " #{skin_tone}" unless skin_tone.empty?
accessories = rec['accessories'].split( '/' ).map { |acc| acc.strip }
attributes = [base] + accessories
attributes
end
composite = ImageComposite.new( 10, 10, width: 24,
height: 24 )
recs.each do |rec|
id = rec['id']
puts "==> generating punk ##{id}..."
pp rec
attributes = rec_to_attributes( rec )
pp attributes
img = Punk::Image.generate( *attributes )
img.save( "./tmp/#{id}_v2.png")
img.zoom(4).save( "./tmp/#{id}[email protected]")
img.zoom(8).save( "./tmp/#{id}[email protected]")
composite << img ## bonus: add to composite
end
## save all-in-one composite
composite.save( "./tmp/punks_v2.png" )
composite.zoom(4).save( "./tmp/[email protected]" )
puts "bye"