Class: WSLight::Set::GradientSet

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

Overview

Creates a gradient from one color to another

Constant Summary

Constants inherited from ColorSet

ColorSet::DEFAULT_LENGTH, ColorSet::DEFAULT_TYPE

Instance Attribute Summary collapse

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 Attribute Details

#color_fromObject

Returns the value of attribute color_from.



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

def color_from
  @color_from
end

#color_toObject

Returns the value of attribute color_to.



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

def color_to
  @color_to
end

Instance Method Details

#create_frameObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/ws_light/set/gradient_set.rb', line 18

def create_frame
  set = []
  @length.times do |i|
    set << pixel(i)
  end

  set += set.reverse if type == :double # this should be faster than generating the pixel one after another

  set
end

#frameObject



14
15
16
# File 'lib/ws_light/set/gradient_set.rb', line 14

def frame
  @set ||= create_frame
end

#initObject



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

def init
  @color_from = Color.new(0, 0, 0)
  @color_to = Color.new(255, 255, 255)
end

#pixel(number) ⇒ Object



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

def pixel(number)
  number = @full_length - 1 - number if number >= @length
  @color_from.mix(@color_to, number.to_f / (@length - 1))
end