Class: WSLight::Set::WatermelonSet

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

Overview

Creates a watermelon set, some green, some white, lots of red with a few red dots

Constant Summary

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ws_light/set/watermelon_set.rb', line 7

def create_frame
  set = []

  length_red = (0.72 * @length).to_i
  length_red_to_white = (0.1 * @length).to_i
  length_white = (0.1 * @length).to_i

  white = Color.new(255, 255, 255)
  red = Color.new(255, 0, 0)

  @length.times do |i|
    if i < length_red
      set << Color.new((rand(25) < 1 ? 0 : 255), 0, 0)
    elsif i < length_red + length_red_to_white
      ratio = (i - length_red) / length_red_to_white.to_f
      set << red.mix(white, ratio)
    elsif i < length_red + length_red_to_white + length_white
      set << white
    else
      set << Color.new(0, 127, 0)
    end
  end

  set.reverse! if rand(2) == 0

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

#frameObject



35
36
37
# File 'lib/ws_light/set/watermelon_set.rb', line 35

def frame
  @set ||= create_frame
end

#pixel(number) ⇒ Object



39
40
41
# File 'lib/ws_light/set/watermelon_set.rb', line 39

def pixel(number)
  frame[number]
end