Class: SparkleMotion::Nodes::Transforms::Range

Inherits:
SparkleMotion::Nodes::Transform show all
Defined in:
lib/sparkle_motion/nodes/transforms/range.rb

Overview

Transform values from 0..1 into a new range.

TODO: Allow change to range to apply over time?

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(mid_point:, delta:, source:, mask: nil, logger:) ⇒ Range

Returns a new instance of Range.



8
9
10
11
12
# File 'lib/sparkle_motion/nodes/transforms/range.rb', line 8

def initialize(mid_point:, delta:, source:, mask: nil, logger:)
  super(source: source, mask: mask)
  @logger = logger
  set_range(mid_point, delta)
end

Instance Method Details

#set_range(mid_point, delta) ⇒ Object



20
21
22
23
# File 'lib/sparkle_motion/nodes/transforms/range.rb', line 20

def set_range(mid_point, delta)
  @min = clamp("min", mid_point, delta, (mid_point - delta).round)
  @max = clamp("max", mid_point, delta, (mid_point + delta).round)
end

#update(t) ⇒ Object



14
15
16
17
18
# File 'lib/sparkle_motion/nodes/transforms/range.rb', line 14

def update(t)
  super(t) do |x|
    (@source[x] * (@max - @min)) + @min
  end
end