Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -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
60 changes: 56 additions & 4 deletions traffic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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