-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlights.rb
43 lines (33 loc) · 910 Bytes
/
lights.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
require 'green_shoes'
Shoes.app {
# creates a light at the given position with the given color
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
def run_chase_animation(lights = [])
frames_per_second = lights.length
animate frames_per_second do |frame|
light_idx = frame % frames_per_second
# set all the lights to green
lights.each{ |light| light.style(fill: green) }
# set the light_idx light to red
lights[light_idx].style(fill: red)
end
end
lights = [light(0, fuchsia),
light(1, blue),
light(2, green)]
lights[1].click do
run_chase_animation(lights)
end
}