Class: WSLight::Set::StrawberrySet

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

Overview

Creates a strawberry set, some green, lots of pinkish red with a few greenish dots

Constant Summary collapse

LENGTH_RED =
0.9
COLOR_NUT =
Color.new(220, 255, 15)

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, #init, #initialize, #next_frame

Constructor Details

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

Instance Method Details

#create_frameObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ws_light/set/strawberry_set.rb', line 14

def create_frame
  set = []

  length_red = (LENGTH_RED * @length).to_i

  color_strawberry = Color.new(255, 7, 15)
  color_leaves = Color.new(15, 191, 15)

  @length.times do |i|
    set << (i < length_red ? color_strawberry : color_leaves)
  end

  set = sprinkle_nuts(set)

  set.reverse! if rand(2).zero?

  type == :double ? set + set.reverse : set
end

#frameObject



10
11
12
# File 'lib/ws_light/set/strawberry_set.rb', line 10

def frame
  @set ||= create_frame
end

#pixel(number) ⇒ Object



44
45
46
# File 'lib/ws_light/set/strawberry_set.rb', line 44

def pixel(number)
  frame[number]
end

#sprinkle_nuts(set) ⇒ Object



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

def sprinkle_nuts(set)
  length_red = (LENGTH_RED * @length).to_i
  distance = 0
  while distance < length_red - 21
    distance += rand(5..20)
    set[distance] = COLOR_NUT
  end

  set
end