Animatronic
A library to animate numeric values with ease on NodeJS, Bun and Deno.
What is is for?
This library is for animating numeric values, it can be used to animate anything that can be represented by a number, like the volume of a sound, the position of a servo motor, the brightness of a led, etc or even some DMX channels values over time.
It is aim to be a simple and easy to use library, with a small footprint and no dependencies. The usage might be limited for big animations but it is perfect for small projects and to be used in embedded systems.
It's currently powering an Escape Room IoT device in production and it's working great.
While this is working in browser context, it is not the main focus of this library, and there are better alternatives for that. The main reason is that we are using setTimeout
and setInterval
to animate the values, and this is not the best approach for the browser, where we should use requestAnimationFrame
instead.
Usage
This library exports one single function and various Easing animations.
JSDocumentation is well defined and pretty self explanatory, but here is a quick example, for more advanced usage, please check the documentation folder.:
Animating a PWM (Pulse Wave Modulation) value to dim a light bulb over time
import { createAnimationController, Easing, type SegmentsConfig } from "animatronic";
const simplePulseSegments: SegmentsConfig = [
{ initialValue: 0, duration: 5000, toValue: 255 },
{ duration: 5000, toValue: 0, easing: Easing.inOutBack },
];
const controller = createAnimationController({
fps: 20,
loop: true,
segments: simplePulseSegments,
});
state.lightMode.onChange((lightMode) => {
controller.stop();
switch (lightMode) {
case "on":
setPWMTo(255);
break;
case "animating":
controller.start(setPWMTo);
break;
default:
setPWMTo(0);
break;
}
});