forked from rails-school/ruby-lights
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlights.rb
More file actions
41 lines (35 loc) · 754 Bytes
/
lights.rb
File metadata and controls
41 lines (35 loc) · 754 Bytes
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
require 'green_shoes'
Shoes.app {
def light(position, color)
fill gray
light = oval(left:10 + 90*position, top:10, radius:40)
light.hover do
puts "HOVER at #{position}"
light.style(fill: color)
end
light.leave do
puts "LEAVE at #{position}"
light.style(fill: gray)
end
return light
end
l0 = light(0, red)
l1 = light(1, blue)
l2 = light(2, green)
l1.click do
frames_per_second = 30
animate 3 do |frame|
frame = frame % 3
l0.style(fill: green)
l1.style(fill: green)
l2.style(fill:green)
if (frame == 0)
l0.style(fill: red)
elsif (frame == 1)
l1.style(fill: red)
else
l2.style(fill: red)
end
end
end
}