npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

animatronic

v1.2.1

Published

NodeJS, Bun and Deno library to animate numeric values with ease.

Downloads

22

Readme

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;
  }
});