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

trianglesjs

v1.0.2

Published

A very simple way to create cool triangle patterns on your webpage!

Downloads

9

Readme

triangles-js

A JavaScript module that renders cool animated triangle patterns.

This module creates Delaunay Triangles very fast with a modified version of ironwallaby's implementation. It resizes to fit the canvas that it draws on, so any sized canvas can use triangles-js.

1. Default Pattern

Demo0

This is the default pattern. How boring!!!

<canvas id="canvas0"></canvas>
<script type="text/javascript" src="../src/triangle.js"></script>
<script type="text/javascript">
    Triangle.create(document.getElementById("canvas0"));
</script>

2. Custom Pattern

Demo1

This is a custom pattern. The number of points can be customized! The velocity of the points can be customized! Even the color of each triangle can be customized with a function!

<canvas id="canvas1"></canvas>
<script type="text/javascript" src="../src/triangle.js"></script>
<script type="text/javascript">
    Triangle.create(document.getElementById("canvas1"), {
        numPoints: 75,
        velocity: 0.25,
        fillStyle: function(x, y) {
            return `rgb(${y * 255},${x * 255},${255})`;
        },
    });
</script>

3. Rainbow Pattern

Demo2

This is a rainbow pattern. The fillStyle function is converting HSL color into rgb format for a rainbow effect!

<canvas id="canvas2"></canvas>
<script type="text/javascript" src="../src/triangle.js"></script>
<script type="text/javascript">
    Triangle.create(document.getElementById("canvas2"), {
        numPoints: 600,
        frameRate: 60,
        velocity: 1,
        fillStyle: function(x, y) {
            let h = x,
                s = 0.8,
                l = y * 0.6 + 0.2;
            var r, g, b;

            if (s == 0) {
                r = g = b = l; // achromatic
            } else {
                var hue2rgb = function hue2rgb(p, q, t) {
                    if (t < 0) t += 1;
                    if (t > 1) t -= 1;
                    if (t < 1 / 6) return p + (q - p) * 6 * t;
                    if (t < 1 / 2) return q;
                    if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
                    return p;
                }

                var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
                var p = 2 * l - q;
                r = hue2rgb(p, q, h + 1 / 3);
                g = hue2rgb(p, q, h);
                b = hue2rgb(p, q, h - 1 / 3);
            }

            return `rgb(${r*255},${g*255},${b*255})`;
        },
    });
</script>

4. Complex Functions Pattern

Demo3

This is a striped pattern created with a cosine function in the horizontal direction. You can use any function you want to create any pattern that you can think of!

<canvas id="canvas3"></canvas>
<script type="text/javascript" src="../src/triangle.js"></script>
<script type="text/javascript">
    Triangle.create(document.getElementById("canvas3"), {
        numPoints: 150,
        frameRate: 60,
        velocity: 2,
        fillStyle: function(x, y) {
            return `rgb(${(Math.cos(x*4*Math.PI)+1)* 255*0.5},${155 + y * 100},${y * 100})`;
        },
    });
</script>

Documentation

Triangle.create(canvas, options)

Parameter | Description ------------ | ------------- canvas | The canvas element to draw triangles on options.numPoints: Int | (optional) Number of points to use to make triangles options.frameRate: Int | (optional) The framerate to use to render triangles. options.velocity: Float | (optional) The maximum velocity of points options.fillStyle: (x: Float, y: Float) => String | (optional) The function that calculates the color of each triangle. It takes in the X and Y coordinates and returns a string containing the rgb color of the triangle whose centroid is at position (X, Y). The range for x and y is 0 to 1.