Class: WSLight::Set::RainbowSet

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

Overview

Creates a moving rainbow (actually a color circle)

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

Constructor Details

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

Instance Method Details

#frameObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ws_light/set/rainbow_set.rb', line 15

def frame
  next_frame
  set = []

  @length.times do |i|
    set << pixel(i)
  end

  set += set.reverse if type == :double

  set
end

#initObject



7
8
9
# File 'lib/ws_light/set/rainbow_set.rb', line 7

def init
  @frequency = Math::PI / @length
end

#next_frameObject



11
12
13
# File 'lib/ws_light/set/rainbow_set.rb', line 11

def next_frame
  @frame_count += 1
end

#pixel(number) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/ws_light/set/rainbow_set.rb', line 28

def pixel(number)
  number = @full_length - 1 - number if number >= @length
  x = @frequency*(number+@frame_count)
  Color.new(
      (Math.sin(x)**2 * 127),
      (Math.sin(x + 2.0*Math::PI/3.0)**2 * 127),
      (Math.sin(x + 4.0*Math::PI/3.0)**2 * 127)
  )
end