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)


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

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

#between_strips?(position) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# 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)).include?(position)
end

#create_frameObject



34
35
36
37
38
39
40
41
42
# File 'lib/ws_light/set/semolina_set.rb', line 34

def create_frame
  set = []

  @full_length.times do |i|
    set << (is_raspberry?(i) ? COLOR_RASPBERRY : COLOR_SEMOLINA)
  end

  set
end

#frameObject



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

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 do
    position = rand(@full_length)
    @raspberries << position unless (at_end?(position) || between_strips?(position) || is_raspberry?(position))
  end
end

#is_raspberry?(pixel) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/ws_light/set/semolina_set.rb', line 44

def is_raspberry?(pixel)
  @raspberries.each do |raspberry|
    return true if pixel > raspberry && pixel < (raspberry + RASPBERRY_SIZE)
  end
  false
end

#pixel(number) ⇒ Object



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

def pixel(number)
  frame[number]
end