-
Notifications
You must be signed in to change notification settings - Fork 1
/
colorlovers.rb
55 lines (38 loc) · 1.1 KB
/
colorlovers.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
# Generate a gallery for a colorlovers palette.
require 'open-uri'
require 'json'
require 'uri'
# For the vector class
require 'gmath3D'
DOWNLOAD = true
puts "Fetching json..."
json = JSON.parse(open("http://www.colourlovers.com/api/palettes/top?format=json").readlines.join)
xml = "<scene>\n"
xml += <<-EOF
<spawn position="0 0 0" />
EOF
i = 0
json.each do |palette|
title = palette["title"].slice(0,70)
x = i % 5
z = (i / 5).floor
v = GMath3D::Vector3.new(x, 0, -z) * 5
v += GMath3D::Vector3.new(5, 0.5, -5)
xml += <<-EOF
<billboard position="#{v.x} #{v.y} #{v.z}" rotation="0 0 0" scale="1 1 0.1">
<![CDATA[
<center style="font-size: 4em; margin-top: 40px">#{title}</center>
]]>
</billboard>
EOF
v.y = 0.2
v += GMath3D::Vector3.new(1.5, 0, 0)
palette['colors'].each do |color|
xml += "<box color='##{color}' scale='0.4 0.4 0.4' position='#{v.x} #{v.y} #{v.z}' />"
v += GMath3D::Vector3.new(0, 0.4, 0)
end
i += 1
end
xml += "</scene>"
File.open("./scenes/colorlovers.xml", "w") { |f| f.write xml }
puts "Visit /colorlovers.xml to see the gallery."