Class: MatrixCreator::Everloop::Spinner

Inherits:
Animation
  • Object
show all
Defined in:
lib/matrix_creator/everloop/spinner.rb

Overview

Spinner animation class

Constant Summary

Constants inherited from Animation

Animation::ANIMATION_SPEED

Instance Method Summary collapse

Methods inherited from Animation

#destroy_context, run

Constructor Details

#initialize(color, code_thread) ⇒ Spinner

Initializes the variables on the instance to prepare for the loop animation

Parameters:

  • color (Hash)

    with the rgb+w values for the color

  • code_thread (Thread)

    instance with main thread



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/matrix_creator/everloop/spinner.rb', line 15

def initialize(color, code_thread)
  @everloop_comm = MatrixCreator::Comm.new(BASE_PORT)
  @code_thread = code_thread

  # Generating array of led messages
  @led_array = (1..35).map do |i|
    if i <= 5
      MatrixMalos::LedValue.new(
        red: (color[:r] * i * 2) / 10,
        green: (color[:g] * i * 2) / 10,
        blue: (color[:b] * i * 2) / 10,
        white: (color[:w] * i * 2) / 10
      )
    else
      MatrixMalos::LedValue.new(red: 0, green: 0, blue: 0, white: 0)
    end
  end
end

Instance Method Details

#loop_animationObject

Loop animation until main code thread finishes



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/matrix_creator/everloop/spinner.rb', line 36

def loop_animation
  loop do
    everloop_image = MatrixMalos::EverloopImage.new(led: @led_array)
    msg = MatrixMalos::DriverConfig.new(image: everloop_image)
    @everloop_comm.send_configuration(msg)

    sleep(ANIMATION_SPEED)

    break if @code_thread[:finished]

    # Rotate the 5 led instances order in the array
    @led_array.rotate!(-1)
  end
end