A node that ramps up a value from a start to an end value using an easing function. Output values are values over time or values within an array.
Typical use cases are smoothing command value changes to avoid large steps.
Fig. 1: Node appearance
~/.node-red
npm install node-red-contrib-easing
Fig. 2: Node properties
The transition from the start to the end value follows a functional behaviour. These transiton profiles are divided into three categories depending on the easing function name:
The behaviour of these three categories is shown by the means of the sinoidal functions in Figure 3.
Fig. 3: Easing function categories (In, Out, InOut)
Several easing funtions are selectable in the node configuration. These are:
The profiles of these functions are shown below. See chapter Transition profiles of the easing functions for details.
Depending on the type of the msg.payload
the easing
node behaves differently ramping with the selected easing function:
msg.payload
, the easing
node ramps from 0.0 to 1.0.msg.payload
is a number, the easing
node ramps from its last value to this number given.msg.payload
contains a JSON object in the format: { "from" : 1, "to" : 10, "duration": 200, "interval" :10 }, it will ramp between these two values (<from>, <to>) within the given <duration> (in milliseconds), outputing a value every <interval> ms.msg.payload
contains a JSON object in the format: { "from" : 1, "to" : 10, "size": 10 }, it will ramp between these two values (<from>, <to>), giving an array of <size> values.The output can be configured via the Output property within the node configuration to be
msg
objects are sent, each containing one single value within the msg.payload
.msg
is sent, containing an array with all transition profile values within the msg.payload
.This option generates a msg
sequence.
The duration of this sequence is set by the Duration property within the node configuration. The time interval between two msg
sent is set by the Interval property within the node configuration.
The scaling of both values relates to milliseconds (ms).
The number of sent msg
objects equals to (<Duration> / <Interval>) + 1: The first msg
object is sent immediately containing the start value (e.g. 0.0), the last msg
object is sent after <Duration> ms containing the end value (e.g. 1.0).
The 'step height' of every msg.payload
value depends on the selected easing function. As an example, for the linear case it equals to :
(<end value> -- <start value>) · <Interval> / <Duration>.
Fig. 4: Values over time (<duration>, <interval> in ms)
This option generates one single msg
object. It contains an array [0 .. <Size>] with a selectable number of entries. This number of entries is set by the Size property within the node configuration, i.e. the array contains (<Size> + 1) entries.
Fig. 5: Configuration As Array
Check Node-REDs info panel to see more information on how to use the easing node.
Remark: Example flows are present in the examples subdirectory. In Node-RED they can be imported via the import function and then selecting Examples in the vertical tab menue.
The example flow shows the three options of input data via the injecting nodes (option values over time).
Fig. 6: Easing example
The following graphs show the normalized transition profiles the user can select.
Fig. 7: Polynomial profiles
Fig. 8: Sinoide and exponential profiles
Fig. 9: Bouncing profiles