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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mandala-p5js

v1.0.0

Published

Radial-symmetry mandala and kaleidoscope patterns for p5.js

Readme

mandala-p5js

Draw mandalas, kaleidoscopes and rosette patterns by replicating a single wedge around a centre, on a p5.js canvas. Add mirroring for the extra fold of symmetry real mandalas have.

The drawing helpers take a p5 instance as their first argument, so the package works in instance mode (and global mode too). The transform math (where a point lands in each replicated slice) is pure and decoupled from p5, so it can be used and tested without a canvas.

Installation

npm install mandala-p5js

p5 is a peer dependency (^1.0.0); install it alongside if you haven't already:

npm install p5

Usage (instance mode)

You draw a single wedge; the symmetry is handled for you. Inside wedgeFn the canvas is already translated to the centre and rotated into the current slice.

const p5 = require('p5');
const { drawMandala } = require('mandala-p5js');

new p5((p) => {
    p.setup = () => {
        p.createCanvas(600, 600);
        p.background(10);
        p.stroke(255, 120);
        p.noFill();

        drawMandala(
            p,
            (pp) => {
                // One wedge, drawn outward from the centre. It gets replicated.
                pp.line(0, 0, 0, -240);
                pp.circle(0, -160, 60);
                pp.circle(0, -100, 24);
            },
            { slices: 16, mirror: true },
        );
    };
});

For dot / scatter mandalas, replicate a motif of points directly:

const { drawMotif } = require('mandala-p5js');

// A motif is a list of [x, y] points relative to the centre.
const motif = [
    [40, 0],
    [80, -20],
    [120, 10],
];
drawMotif(p, motif, { slices: 12, mirror: true, dotSize: 5 });

API

drawMandala(p, wedgeFn, opts = {})

Calls wedgeFn(p, sliceIndex) once per slice, with the canvas translated to the centre and rotated into that slice.

  • opts.cx, opts.cy — centre. Defaults to the canvas centre.
  • opts.slices — number of rotational folds. Default 12.
  • opts.mirror — also draw a reflected twin of each wedge. Default false.

drawMotif(p, motif, opts = {})

Replicates a list of [x, y] points (relative to the centre) across all slices and draws them as dots. Same opts as drawMandala, plus dotSize.

Pure helpers (no p5 needed)

  • symmetryPoints(x, y, slices, mirror = false) — every replicated copy of one point. Returns Array<{ x, y }>.
  • replicateMotif(motif, slices, mirror = false) — replicates a whole motif. Returns Array<[x, y]>.
  • rotatePoint(x, y, angle) — rotates a point around the origin.
const { symmetryPoints } = require('mandala-p5js');

symmetryPoints(10, 0, 4);
// => [{x:10,y:0}, {x:0,y:10}, {x:-10,y:0}, {x:0,y:-10}]

License

MIT © Damian Sire