class WSLight::Set::StarSet

Creates a set with all random colors

Constants

BLACK
FRAMES_PER_STAR
VISIBLE_STARS

Public Instance Methods

brightness(frame_distance) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/ws_light/set/star_set.rb, line 24
def frame
  next_frame
  @set
end
generate_frame() click to toggle source
# 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|
    star_ratio = FRAMES_PER_STAR.to_f / VISIBLE_STARS.to_f
    draw_star(@stars[start + i], @frame_count - ((start - VISIBLE_STARS + 1 + i) * star_ratio).to_i)
  end
end
init() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/ws_light/set/star_set.rb, line 44
def pixel(number)
  @set[number]
end