class WSLight::Set::SemolinaSet
Creates semolina with raspberries
Constants
- COLOR_RASPBERRY
- COLOR_SEMOLINA
- RASPBERRY_COUNT
- RASPBERRY_SIZE
Public Instance Methods
at_end?(position)
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 25 def at_end?(position) position >= (@full_length - 1 - RASPBERRY_SIZE) end
between_strips?(position)
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 21 def between_strips?(position) @type == :double && ((@full_length / 2 - 1 - RASPBERRY_SIZE)..(@full_length / 2)).cover?(position) end
create_frame()
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 33 def create_frame set = [] @full_length.times do |i| set << (raspberry?(i) ? COLOR_RASPBERRY : COLOR_SEMOLINA) end set end
frame()
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 29 def frame @set ||= create_frame end
init()
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 12 def init @raspberries = [] while @raspberries.size < RASPBERRY_COUNT position = rand(@full_length) @raspberries << position unless at_end?(position) || between_strips?(position) || raspberry?(position) end end
pixel(number)
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 50 def pixel(number) frame[number] end
raspberry?(pixel)
click to toggle source
# File lib/ws_light/set/semolina_set.rb, line 43 def raspberry?(pixel) @raspberries.each do |raspberry| return true if pixel > raspberry && pixel < (raspberry + RASPBERRY_SIZE) end false end