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

bezier-paths

v1.0.1

Published

A library to easily generate and traverse bezier paths. And different parts of the path can have different speeds!

Downloads

4

Readme

Bezier Paths

A library to easily generate and traverse bezier paths. And different parts of the path can have different speeds!

Interactive demo

Check it out here!

Installation

npm i bezier-paths

Usage

You can include the library in browser projects which don't allow require or import by simply adding the file via <script> and accessing the global variable BezierPaths.

First create a bunch of points that will make up your path using either createLinearPoint or createBezierPoint. Then call compilePath which will compile the points into a path that exposes methods getPointAtTime and getPointAtDistance for traversing the path:

var curvedPoints = [];

curvedPoints.push(BezierPaths.createBezierPoint(
	x, y,
	speedTo, speedFrom,
	controlBackX, controlBackY,
	controlFrontX, controlFrontY
));
curvedPoints.push(BezierPaths.createBezierPoint(...));
curvedPoints.push(BezierPaths.createBezierPoint(...));
curvedPoints.push(BezierPaths.createBezierPoint(...));

var path = BezierPaths.compilePath(precision, points);
path.getPointAtTime(time);
// OR
path.getPointAtDistance(distance);

API

createLinearPoint(x, y, speedTo, speedFrom): Point

  • x: Number - X position of the point
  • y: Number - Y position of the point
  • speedTo: Number - Speed of the segment when reaching this point
  • speedFrom: Number - Speed of the segment when leaving this point
  • Creates a new point that is not curved by itself.

createBezierPoint(x, y, speedTo, speedFrom, controlBackX, controlBackY, controlFrontX, controlFrontY): Point

  • x: Number - X position of the point
  • y: Number - Y position of the point
  • speedTo: Number - Speed of the segment when reaching this point
  • speedFrom: Number - Speed of the segment when leaving this point
  • controlBackX: Number - X position of the control point affect the path before this point
  • controlBackY: Number - Y position of the control point affect the path before this point
  • controlFrontX: Number - X position of the control point affect the path after this point
  • controlFrontY: Number - Y position of the control point affect the path after this point
  • Creates a new point that curves the path before and after itself up until the previous/next point.

compilePath(curvesPrecision, points): CompiledPath

  • curvesPrecision: Number - Number of points that will make up each curved segment. For smooth angles a value of at least 50 is recommended. The bigger it is the smoother the curves will be when traversing them.
  • points: Point[] - An array of points that will make up the path.

Point

  • Field x: Number - X position of the point
  • Field y: Number - Y position of the point
  • Field speedTo: Number - Speed of the segment when reaching this point
  • Field speedFrom: Number - Speed of the segment when leaving this point
  • Field controlBackX: Number - X position of the control point affect the path before this point
  • Field controlBackY: Number - Y position of the control point affect the path before this point
  • Field controlFrontX: Number - X position of the control point affect the path after this point
  • Field controlFrontY: Number - Y position of the control point affect the path after this point
  • Field isCurved: Boolean - Is the point curved or not. If not controls have the same position as the point itself.

CompiledPath.getPointAtTime(time)

  • time: Number - Time, in frames
  • Returns the position along the path assuming travel from the start of the path for the amount of frames specified in an argument. If time is larger than path's duration it will wrap around.

CompiledPath.getPointAtDistance(distance)

  • distance: Number - Distance, in pixels
  • Returns the position along the path assuming travel from the start of the path by the number of pixels specified in an argument. If distance is larger than path's length it will wrap around.

CompiledPath.pathLength

  • Field containing the path's length in pixels.

CompiledPath.pathDuration

  • Field containing the path's duration in frames.

CompiledPath.points

  • An array of compiled points making up the path. The points only contain x, y, speedFrom and speedTo.