-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_meta.rb
103 lines (71 loc) · 2.65 KB
/
generate_meta.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'cocos'
##
# read in all meta data records of all 10 000 punks (24px)
recs = read_csv( './etc/punks24px.csv' )
puts "#{recs.size} punk(s)" #=> 10000 punk(s)
meta = []
STATS = Hash.new(0)
def generate_punk( *values )
## remove empty attibutes
values = values.select { |value| !value.empty? }
punk_type = values[0]
attribute_names = values[1..-1]
# change mid
# male to (ethscribe) green
# female to (ethscribe) green female
punk_type = case punk_type
when 'Male 2' then 'Male Green'
when 'Female 2' then 'Female Green'
else punk_type
end
# change smile to gold
# change frown to demon or skeleton or bot or orc
punk_type = 'Male Gold 1' if attribute_names.include?( 'Smile' )
specials = ['Demon', 'Skeleton', 'Robot', 'Orc']
punk_type = specials[ rand( specials.size ) ] if attribute_names.include?( 'Frown' )
### more fun
## turn every 10th male1 into blue
if punk_type == 'Male 1'
STATS['Male 1'] += 1
punk_type ='Male Blue' if STATS['Male 1'] % 10 == 0
end
## attributes - rm smile
## attributes - rm frown
attribute_names = attribute_names.select do |attribute_name|
case attribute_name
when 'Smile' then false
when 'Frown' then false
else true
end
end
attribute_names = attribute_names.map do |attribute_name|
case attribute_name
when 'Small Shades' then 'Laser Eyes Gold'
when 'Welding Goggles' then 'Laser Eyes Gold'
else attribute_name
end
end
[punk_type, *attribute_names]
end # method generate
##
# let's go - generate all 10 000 using the records
srand( 4242 ) ## make deterministic
recs.each_with_index do |rec,i|
puts "==> punk #{i}:"
pp rec
values = rec.values
attributes = generate_punk( *values )
type = attributes[0]
more_attributes = attributes[1..-1]
meta << [i.to_s, type, more_attributes.join( ' / ')]
end
headers = ['id', 'type', 'attributes']
File.open( "./etc/punks24px.i.csv", "w:utf-8" ) do |f|
f.write( headers.join( ', '))
f.write( "\n")
meta.each do |values|
f.write( values.join( ', ' ))
f.write( "\n" )
end
end
puts "bye"