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

rvl-node-animations

v3.1.1

Published

A set of helper methods to create animations for RVL-Node

Downloads

2

Readme

RVL-Node Animations

A set of helper methods to create and render animations for RVL-Node and friends

System Requirements

  • Any modern JavaScript engine (web or Node.js)

Installation

Install using npm:

npm install rvl-node-animations

Usage

Basic usage:

import {
  initRenderer,
  renderPixels,
  createWaveParameters,
  createSolidColorWave,
  createColorCycleWave
} from 'rvl-node-animations';

// Initialize the renderer
initRenderer();

const waveParameters = createWaveParameters(
  // Create a solid-cyan, half-way transparent color
  createSolidColorWave(128, 255, 128),

  // Create a fully opaque, slow color cycle that will show throw the cyan wave
  createColorCycleWave(2, 255)
);

// Render the pixels at 33 frames per second
setInterval(() => {
  const pixels = renderPixels(waveParameters);
  // Display pixels in the browser/an LED strip/etc.
}, 33);

If you intend to create these animations on the same device that will be controlling the LEDs, here is an example integrating rvl-node-animations and rvl-node:

import {
  createWaveParameters,
  createSolidColorWave,
  createColorCycleWave
} from 'rvl-node-animations';
import { RVL } from 'rvl-node';

const rvl = new RVL({
  networkInterface: 'wlan0',
  logLevel: 'debug',
  mode: 'controller'
});

rvl.on('initialized', () => {
  rvl.setWaveParameters(createWaveParameters(
    // Create a solid-cyan, half-way transparent color
    createSolidColorWave(128, 255, 128),

    // Create a fully opaque, slow color cycle that will show throw the cyan wave
    createColorCycleWave(2, 255)
  ));
});

Notes

If you're using TypeScript, you don't need to install separate @types type definitions because this package ships with them. To support sharing of interfaces between this module and rvl-node itself, I created another module called rvl-node-types, which may be of interest to you.

All waves are defined in the HSV color space that has been mapped to 8-bit integers (e.g. the hue is 0-255, not 0-360, and saturation/value are 0-255, not 0-1 or 0-100). Please familiarize yourself with the HSV color space before using this library.

API

Note: API signatures are declared using TypeScript syntax. This provides a concise, formal definition for all signatures in a syntax that is familiar to at least some developers.

createWaveParameters(wave1, wave2, wave3, wave4)

This method creates a fully formed set of wave parameters that can be passed directly to rvl-node#setWaveParameters().

Signature:

function createWaveParameters(
  wave1?: IWave,
  wave2?: IWave,
  wave3?: IWave,
  wave4?: IWave
): IWaveParameters

Arguments:

Returns: an IWaveParameters instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

createEmptyWave()

This method creates an empty wave, aka a fully-transparent wave that allows waves below it in the stack to be fully visible.

Signature:

function createEmptyWave(): IWave

Arguments: none

Returns: an IWave instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

createSolidColorWave(h, s, a)

This method creates a solid color wave that does not change over distance or time.

Signature:

function createSolidColorWave(h: number, s: number, a: number): IWave

Arguments:

Returns: an IWave instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

createColorCycleWave(rate, a)

This method creates a wave that cycles through colors over time.

From a technical perspective, it linearly varies the hue over time while keeping the saturation and value at 100%.

Signature:

function createColorCycleWave(rate: number, a: number): IWave

Arguments:

Returns: an IWave instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

createMovingWave(h, s, rate, spacing)

This method creates a moving wave, with the alpha varying between 0% and 100% over distance, creating a "roving wave" effect.

From a technical perspective, it varies the alpha over distance, and varies the y-value of the start of wave with time.

Signature:

function createMovingWave(h: number, s: number, rate: number, spacing: number): IWave

Arguments:

Returns: an IWave instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

createPulsingWave(h, s, rate)

This method creates a wave that pulses, aka it varies from fully transparent to fully opaque over time.

From a technical perspective, it varies the alpha over time with nothing else that varies.

Signature:

function createPulsingWave(h: number, s: number, rate: number): IWave

Arguments:

Returns: an IWave instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

createRainbowWave(a, rate)

This method creates a wave that looks like a rainbow, and slowly moves.

From a technical perspective it varies the hue over distance, and varies the y-value of the start of wave with time.

Signature:

function createRainbowWave(a: number, rate: number): IWave

Arguments:

Returns: an IWave instance. Details can be found at rvl-node-types, but for all intents and purposes it can be treated as a black box.

initRenderer(waveParameters, numPixels, numWaves)

This method initializes the renderer and starts the animation clock.

Signature:

function initRenderer(waveParameters: IWaveParameters, numPixels: number, numWaves: number = 4): void

Arguments:

Returns: none.

renderPixels()

Renders the pixels for this exact moment in time based on the parameters set in initRenderer.

Signature:

interface IPixel {
  r: number;
  g: number;
  b: number;
}
function renderPixels(): IPixel[]

Arguments: none.

Returns: An array of IPixels representing the color set in 8-bit RGB format.

resetRendererClock()

This method resets the renderer clock to 0.

Signature:

function resetRendererClock(): void

Arguments: none.

Returns: none.

getRendererClock()

Gets the current renderer clock, in milliseconds. This number is not relative to anything, and cannot be used to, e.g., get the wall time.

Signature:

function getRendererClock(): number

Arguments: none.

Returns: The renderer clock as a number.

Background

Note: you do not need to know this information to use this library at all. Some might find it interesting though.

RVL Node uses a rendering engine based on sin waves. RVL Node layers four waves on top of each other to create interesting and aesthetically pleasing LED animations. Think of this like CSS layers. They can include transparency to create a layering effect.

All waves are defined in the HSV color space that has been mapped to 8-bit integers. A hue of 180 degrees is represented by the value 128, a saturation of 25% is represented by the value 64, and so on and so forth.

A wave is defined using the following mathematical formula:

ledChannelValue(t, x) = a * sin(w_t * t + w_x * x + phi) + b

This function takes 5 variables from the user (a, w_x, w_t, phi, b), and 2 from the engine (x, t). This allows someone to create a wave that can vary over time, over the length of the LED strip, can be constant, or any of the above. Each channel (hue, saturation, value, and alpha) have their own wave assigned to them. 4 channels per layer, times 4 layers, means 80 coefficients total!

License

Copyright (c) Bryan Hughes [email protected]

This file is part of Raver Lights Node Animations.

Raver Lights Node Animations is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Raver Lights Node Animations is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Raver Lights Node Animations. If not, see http://www.gnu.org/licenses/.