Class: WSLight::Set::StarSet
Overview
Creates a set with all random colors
Constant Summary
collapse
- FRAMES_PER_STAR =
75
- VISIBLE_STARS =
7
- BLACK =
Color.new(0, 0, 0)
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
Instance Method Details
#brightness(frame_distance) ⇒ Object
48
49
50
|
# File 'lib/ws_light/set/star_set.rb', line 48
def brightness(frame_distance)
(255 * (1.0 - (frame_distance.to_f / (FRAMES_PER_STAR.to_f / 2.0)))).to_i
end
|
#draw_star(position, star_frame) ⇒ Object
39
40
41
42
|
# File 'lib/ws_light/set/star_set.rb', line 39
def draw_star(position, star_frame)
white = brightness((star_frame.to_f - (FRAMES_PER_STAR.to_f / 2.0)).abs)
@set[position] = Color.new(white, white, white)
end
|
#frame ⇒ Object
24
25
26
27
|
# File 'lib/ws_light/set/star_set.rb', line 24
def frame
next_frame
@set
end
|
#init ⇒ Object
11
12
13
14
15
16
|
# File 'lib/ws_light/set/star_set.rb', line 11
def init
@stars = (0..(@full_length - 4)).to_a.shuffle
@max = @stars.size
@stars += @stars[@stars.size - VISIBLE_STARS, VISIBLE_STARS]
generate_frame
end
|
#next_frame ⇒ Object
18
19
20
21
22
|
# File 'lib/ws_light/set/star_set.rb', line 18
def next_frame
@frame_count += 1
@frame_count = @frame_count % (@max * FRAMES_PER_STAR)
generate_frame
end
|
#pixel(number) ⇒ Object
44
45
46
|
# File 'lib/ws_light/set/star_set.rb', line 44
def pixel(number)
@set[number]
end
|