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

@epok.tech/bezier-gen

v1.1.2

Published

Béziers from Node code generator - for any `mix`-able type/dimension, any number of control points, GLSL or similar.

Downloads

8

Readme

bezier-gen

Béziers from Node code generator - for any mix-able type/dimension, any number of control points, GLSL or similar.

Made with GLSL in mind, but similar languages may be generated if a suitable mix function and behaviour is also provided.

Installation

Install from npm using:

npm install @epok.tech/bezier-gen

or:

yarn add @epok.tech/bezier-gen

Usage

Bézier Functions

This module produces a series of GLSL bézier functions, for each of the given numbers of orders O, and overloaded for each of the given types T, named name, with the signature:

T name(T cp0, T cp1, ..., T cp<O-1>, float t);

The bézier functions may be called as follows (using functions in the pre-generated *.glsl files for example):

// 2D 3rd-order bézier function from `bezier-gen/1d.glsl`
float interpolated = bezier(0.0, 1.0, 2.0, 0.5); // 1.0

// 2D 3rd-order bézier function from `bezier-gen/2d.glsl`
vec2 interpolated = bezier(vec2(0.0), vec2(1.0), vec2(2.0), 0.5); // vec2(1.0)

The implementations make use of a per-element mix function - this assumes GLSL's mix, but the name of a different externally-defined function may be passed as the final argument to the generator.

Generating

You can use the pre-generated *.glsl files, or generate your own bézier functions (for GLSL or similar) using the generator files:

Using bin for command-line:

# These are equivalent:

# Long form:
bezier-gen/bin --orders 3 4 5 --types float vec2 vec3 vec4 --name bezier --file ./bezier.glsl

# Short form:
bezier-gen/bin -o 3 4 5 -t float vec2 vec3 vec4 -n bezier -f ./bezier.glsl

# Defaults (outputs to console if no `file` is given):
bezier-gen/bin

Using index.js for Node or JavaScript:

import { makeBezier, makeBeziers } from 'bezier-gen';

makeBezier(3, 'vec2', 'myBezier') ===
`// Code generated by \`bezier-gen\` - start:

vec2 myBezier(vec2 cp0, vec2 cp1, vec2 cp2, float t) {
    vec2 p0 = mix(cp0, cp1, t);
    vec2 p1 = mix(cp1, cp2, t);

    return mix(p0, p1, t);
}

#pragma glslify: export(myBezier);

// Code generated by \`bezier-gen\` - end.
`

makeBeziers([3, 4], ['float', 'vec2'], 'moreBezier') ===
`// Code generated by \`bezier-gen\` - start:

float moreBezier(float cp0, float cp1, float cp2, float t) {
    float p0 = mix(cp0, cp1, t);
    float p1 = mix(cp1, cp2, t);

    return mix(p0, p1, t);
}

float moreBezier(float cp0, float cp1, float cp2, float cp3, float t) {
    float p0 = mix(cp0, cp1, t);
    float p1 = mix(cp1, cp2, t);
    float p2 = mix(cp2, cp3, t);

    p0 = mix(p0, p1, t);
    p1 = mix(p1, p2, t);

    return mix(p0, p1, t);
}


vec2 moreBezier(vec2 cp0, vec2 cp1, vec2 cp2, float t) {
    vec2 p0 = mix(cp0, cp1, t);
    vec2 p1 = mix(cp1, cp2, t);

    return mix(p0, p1, t);
}

vec2 moreBezier(vec2 cp0, vec2 cp1, vec2 cp2, vec2 cp3, float t) {
    vec2 p0 = mix(cp0, cp1, t);
    vec2 p1 = mix(cp1, cp2, t);
    vec2 p2 = mix(cp2, cp3, t);

    p0 = mix(p0, p1, t);
    p1 = mix(p1, p2, t);

    return mix(p0, p1, t);
}

#pragma glslify: export(moreBezier);

// Code generated by \`bezier-gen\` - end.
`

The options for the top-level generators are:

  • orders (JS), or --orders/-o (CLI): Array of orders (number of control points) of each bézier curve function.
  • types (JS), or --types/-t (CLI): The data type (dimension) of each bézier curve function; may be any mix-able type (for GLSL: float, vec2, vec3, vec4).
  • name (JS), or --name/-n (CLI): The name to use for the (overloaded) bézier curve function/s.
  • mix (JS), or --mix/-m (CLI): The name of the per-element (linear) interpolation function; may be the name for any externally-defined function with the same behaviour and arguments as the GLSL mix.
  • pre (JS), or --pre (CLI): Any prefix text to include.
  • suf (JS), or --suf (CLI): Any suffix text to include; by default, does glslify export.
  • file (JS), or --file/-f (CLI): The output file path for the generated code.

See Also