Class: WSLight::Set::StarSet

Inherits:
ColorSet show all
Defined in:
lib/ws_light/set/star_set.rb

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

Constructor Details

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

Instance Method Details

#brightness(led_distance, frame_distance) ⇒ Object



53
54
55
56
57
# File 'lib/ws_light/set/star_set.rb', line 53

def brightness(led_distance, frame_distance)
  #return 0 if led_distance > 3
  #(2 ** ((3 - led_distance) * 3 - 1) - 1) * (1 - (frame_distance/(FRAMES_PER_STAR/2)))
  (255 * (1.0 - (frame_distance.to_f/(FRAMES_PER_STAR.to_f/2.0)))).to_i
end

#draw_star(position, star_frame) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/ws_light/set/star_set.rb', line 38

def draw_star(position, star_frame)
  #(-3..3).each do |i|
  #  white = brightness(i.abs, (star_frame - (FRAMES_PER_STAR/2)).abs)
  #  @set[position + i] = Color.new(white, white, white)
  #end
  #return if star_frame < 0
  white = brightness(0, (star_frame.to_f - (FRAMES_PER_STAR.to_f/2.0)).abs)
  #puts "#{position}, #{star_frame}, #{(star_frame.to_f - (FRAMES_PER_STAR.to_f/2.0)).abs}, #{white}"
  @set[position] = Color.new(white, white, white)
end

#frameObject



24
25
26
27
# File 'lib/ws_light/set/star_set.rb', line 24

def frame
  next_frame
  @set
end

#generate_frameObject



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

def generate_frame
  @set = []
  @full_length.times{ @set << BLACK }
  start = (@frame_count * VISIBLE_STARS / FRAMES_PER_STAR) % @max
  VISIBLE_STARS.times do |i|
      draw_star(@stars[start + i], @frame_count - ((start - VISIBLE_STARS + 1 + i) * (FRAMES_PER_STAR.to_f / VISIBLE_STARS.to_f)).to_i)
  end
end

#initObject



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_frameObject



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



49
50
51
# File 'lib/ws_light/set/star_set.rb', line 49

def pixel(number)
  @set[number]
end