diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..7fe1396 --- /dev/null +++ b/test.rb @@ -0,0 +1,22 @@ + +def method_one + puts "Method one running" +end + +def method_two + puts "Method two running" +end + +def method_three + puts "Method three running" +end + + +while true + sleep(1) + method_one + sleep(1) + method_two + sleep(1) + method_three +end \ No newline at end of file diff --git a/traffic.rb b/traffic.rb index cdc76e3..f7a33e3 100644 --- a/traffic.rb +++ b/traffic.rb @@ -9,6 +9,13 @@ def each end end +module TL + Go = "#00FF30" + Wait = "#FFFC00" + Stop = "#FF0000" + Off = "#999999" +end + class Bulb < Shoes::Shape attr_accessor :stack attr_accessor :left @@ -34,16 +41,61 @@ def bulb_colour end end +class GoBulb < Bulb + def bulb_colour + if self.switched_on + TL::Go + else + TL::Off + end + end + +end + +class WaitBulb < Bulb + def bulb_colour + if self.switched_on + TL::Wait + else + TL::Off + end + end + +end + +class StopBulb < Bulb + def bulb_colour + if self.switched_on + TL::Stop + else + TL::Off + end + end + +end + + Shoes.app :title => "My Amazing Traffic Light", :width => 150, :height => 250 do background "#000000".."#666666", :curve => 10, :margin => 25 stroke black @traffic_light = TrafficLight.new - @top = Bulb.new self, 50, 40, true - @middle = Bulb.new self, 50, 100, true - @bottom = Bulb.new self, 50, 160, true + @top = GoBulb.new self, 50, 40, false + @middle = WaitBulb.new self, 50, 100, false + @bottom = StopBulb.new self, 50, 160, true + counter = 0 click do - + @traffic_light.each {|state| + animate(1) do + puts state.to_s + @top.switched_on = state[0] + @top.draw(@top.left, @top.top, @top.bulb_colour) + @middle.switched_on = state[1] + @middle.draw(@middle.left, @middle.top, @middle.bulb_colour) + @bottom.switched_on = state[2] + @bottom.draw(@bottom.left, @bottom.top, @bottom.bulb_colour) + end + } end end