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

p5js-to-lottie

v0.0.3

Published

Save p5js sketch as a Lottie file

Downloads

7

Readme

p5js-to-lottie

Save p5js sketch as a Lottie file

Convert your favorite creative coding library to your favorite animation format.

Motivation:

  • Currently, p5js only supports generates a gif from a sketch.
  • GIFs are large, Lotties are small.
  • Lotties are normally created with dedicated animation tools, but I'm a dev, I like to code my animation.
  • ...

Getting started.

Import the lib bundle after importing p5.js bundle

<head>
...
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
    
    <script src="https://unpkg.com/[email protected]/dist/bundle.js"></script>
    <!-- OR -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bundle.js"></script>

...
</head>

Import the sketch and work on it like you normally do

# index.html

<script src="sketch.js"></script>
# sketch.js

let circX = 200;
let circY = 200;
let diam = 50;
let speedX = 5;
let speedY = 7;
function initVar() {
  circX = 200;
  circY = 200;
  diam = 50;
  speedX = 5;
  speedY = 7;
}
function setup() {
  createCanvas(400, 400);
  noStroke();
  initVar();
}

function draw() {
  clear();

  // draw the circle on the screen
  fill(245, 10, 20);
  ellipse(circX, circY, diam);

  // increment the x and y with their respective speeds
  circX = circX + speedX;
  circY = circY + speedY;

  // if the circle goes off the left or right sides of the screen, turn it around
  if (circX + diam / 2 > width || circX - diam / 2 <= 0) {
    speedX = speedX * -1;
  }

  // if the circle goes off the top or bottom sides of the screen, turn it around
  if (circY + diam / 2 > width || circY - diam / 2 <= 0) {
    speedY = speedY * -1;
  }
}

Add a button to save and download the Lottie file

# index.html

<button onclick="startRecord()">Record</button>
# sketch.js

function startRecord() {
  initVar();
  window.saveLottie(5, (animation) => {
    const player = document.querySelector("lottie-player");
    player.load(JSON.stringify(animation));
  });
}

Examples.

For examples, check the example/ folder.

TODO

The first checkpoint is to support frequently used 2D primitives, 2D transformations and color settings

2D primitives

  • [X] ellipse()
  • [ ] circle()
  • [ ] line()
  • [ ] point()
  • [X] rect()
  • [ ] square()
  • [ ] triangle()

2D transformation & utilities

  • [ ] rotate()
  • [ ] scale()
  • [ ] translate()

Color settings

  • [ ] background()
  • [ ] fill()
  • [ ] noFill()
  • [ ] noStroke()
  • [ ] stroke()

Run tests

The tests are written using playwright

For each test, a gif file and a lottie file will be export and then their respective frames will be compared

npm test