Git Product home page Git Product logo

animatronic's Introduction

Animatronic

Logo Aurora

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

// For the sake of simplicity we have assume we have function `setPWMTo` that sets the PWM of a device between 0 and 255.

import { createAnimationController, Easing, type SegmentsConfig } from "animatronic";

// Generate segments that take a full trip from 0 to 255 and back to 0 in 10 seconds.
const simplePulseSegments: SegmentsConfig = [
  { initialValue: 0, duration: 5000, toValue: 255 },
  { duration: 5000, toValue: 0, easing: Easing.inOutBack }, // With some easing
];

// Create an animation controller
const controller = createAnimationController({
  fps: 20, // 20 times per seconds, generate a new value.
  loop: true, // Loop the animation
  segments: simplePulseSegments, // The animation to be used (the default one unless overridden on start).
});

state.lightMode.onChange((lightMode) => {
  // Cancel eventual previous animation
  controller.stop();

  switch (lightMode) {
    case "on":
      setPWMTo(255);
      break;
    case "animating":
      controller.start(setPWMTo);
      break;
    default:
      setPWMTo(0);
      break;
  }
});

animatronic's People

Contributors

screamz avatar

Stargazers

Aaron Zomback avatar lait_frais avatar  avatar Muhammed Ibrahim avatar

Watchers

 avatar

Forkers

trobyss

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.