Class: SparkleMotion::Nodes::Transform

Inherits:
SparkleMotion::Node show all
Defined in:
lib/sparkle_motion/nodes/transform.rb

Overview

A sub-class of ‘Node` for any node that operates as a transform, rather than as a root node.

Sub-classes should override ‘update(t)` and call it like so:

“‘ruby def update(t)

super(t) do |x|
  # calculate value for light `x` from `@source[x]` here.
end

end “‘

Constant Summary

Constants inherited from SparkleMotion::Node

SparkleMotion::Node::DEBUG_SCALE, SparkleMotion::Node::FRAME_PERIOD

Instance Attribute Summary

Attributes inherited from SparkleMotion::Node

#debug, #history, #lights

Instance Method Summary collapse

Methods inherited from SparkleMotion::Node

#[], #[]=, #snapshot_to!

Constructor Details

#initialize(source:, mask: nil) ⇒ Transform

Returns a new instance of Transform.



15
16
17
18
19
# File 'lib/sparkle_motion/nodes/transform.rb', line 15

def initialize(source:, mask: nil)
  super(lights: source.lights)
  @source = source
  @mask   = mask
end

Instance Method Details

#update(t) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sparkle_motion/nodes/transform.rb', line 21

def update(t)
  @source.update(t)
  if block_given?
    (0..(@lights - 1)).each do |x|
      # Apply to all lights if no mask, and apply to specific lights if mask.
      apply_transform = !@mask || @mask[x]
      @state[x]       = apply_transform ? yield(x) : @source[x]
    end
  end
  super(t)
end