Class: WSLight::Set::SemolinaSet

Inherits:
ColorSet
  • Object
show all
Defined in:
lib/ws_light/set/semolina_set.rb

Overview

Creates semolina with raspberries

Constant Summary collapse

COLOR_SEMOLINA =
Color.new(255, 127, 15)
COLOR_RASPBERRY =
Color.new(255, 7, 15)
RASPBERRY_SIZE =
10
RASPBERRY_COUNT =
8

Constants inherited from ColorSet

ColorSet::DEFAULT_LENGTH, ColorSet::DEFAULT_TYPE

Instance Attribute Summary

Attributes inherited from ColorSet

#color, #full_length, #length, #type

Instance Method Summary collapse

Methods inherited from ColorSet

#frame_data, #initialize, #next_frame

Constructor Details

This class inherits a constructor from WSLight::Set::ColorSet

Instance Method Details

#at_end?(position) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ws_light/set/semolina_set.rb', line 25

def at_end?(position)
  position >= (@full_length - 1 - RASPBERRY_SIZE)
end

#between_strips?(position) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# 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_frameObject



33
34
35
36
37
38
39
40
41
# 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

#frameObject



29
30
31
# File 'lib/ws_light/set/semolina_set.rb', line 29

def frame
  @set ||= create_frame
end

#initObject



12
13
14
15
16
17
18
19
# 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) ⇒ Object



50
51
52
# File 'lib/ws_light/set/semolina_set.rb', line 50

def pixel(number)
  frame[number]
end

#raspberry?(pixel) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# 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