Class: MatrixCreator::Everloop::Pulse
- Defined in:
- lib/matrix_creator/everloop/pulse.rb
Overview
Pulse animation class
Constant Summary
Constants inherited from Animation
Instance Method Summary collapse
-
#initialize(color, code_thread) ⇒ Pulse
constructor
Initializes the variables on the instance to prepare for the loop animation.
-
#loop_animation ⇒ Object
Loop animation until main code thread finishes.
Methods inherited from Animation
Constructor Details
#initialize(color, code_thread) ⇒ Pulse
Initializes the variables on the instance to prepare for the loop animation
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/matrix_creator/everloop/pulse.rb', line 15 def initialize(color, code_thread) @everloop_comm = MatrixCreator::Comm.new(BASE_PORT) @code_thread = code_thread @intensity = 0 @intensity_next_value = 1 # Generate everloop messages @everloop_msgs = (0..10).map do |msg_intensity| image = (1..35).map do MatrixMalos::LedValue.new( red: ((color[:r] / 10) * msg_intensity).round, green: ((color[:g] / 10) * msg_intensity).round, blue: ((color[:b] / 10) * msg_intensity).round, white: ((color[:w] / 10) * msg_intensity).round ) end MatrixMalos::DriverConfig.new( image: MatrixMalos::EverloopImage.new(led: image) ) end end |
Instance Method Details
#loop_animation ⇒ Object
Loop animation until main code thread finishes
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/matrix_creator/everloop/pulse.rb', line 40 def loop_animation loop do @everloop_comm.send_configuration(@everloop_msgs[@intensity]) @intensity += @intensity_next_value # Pulse intensity behavior if @intensity == 11 @intensity = 10 @intensity_next_value = -1 elsif @intensity == -1 @intensity = 0 @intensity_next_value = 1 end sleep(ANIMATION_SPEED) break if @code_thread[:finished] end end |