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

shapes-julia

v0.1.0

Published

A living Julia set that changes shape with the chord being played: calm chords make round islands, tense chords make sparkly dust. WebGL2, no dependencies.

Readme

shapes-julia

A living Julia set that changes shape with the chord being played. Calm chords make round islands, tense chords make curls, crystal shards and sparkly dust, and every chord pours its color into the shape. Drawn by a WebGL2 fragment shader. No dependencies.

Three shapes: C major is a round yellow island, G7 an orange island with sharp crystal edges, and the cluster C D♭ D E♭ green sparkly dust

It comes from Shapes, a music toy for young children (the julia.html page there is built on this package).

Install

npm install shapes-julia

It's ES modules only, with TypeScript types included. It works with any bundler (Vite, webpack, esbuild, Rollup, Parcel), or straight from a CDN with no build step (see No bundler).

Quick start

A complete page. Give the canvas a size with CSS: the drawing follows that size.

<div style="height: 70vh"><canvas id="julia" style="width: 100%; height: 100%"></canvas></div>
<p id="caption"></p>

<script type="module">
  import { createJulia } from 'shapes-julia';

  const caption = document.getElementById('caption');
  const julia = createJulia(document.getElementById('julia'));

  julia.on('chord', ({ name, feel, color }) => {
    caption.textContent = `${name}: ${feel}`;   // "C major: A smooth, round island"
    caption.style.color = color;
  });

  // Whenever the notes sounding change (MIDI note numbers, 60 = middle C)…
  julia.setNotes([60, 64, 67]);
  // …and whenever a note or chord is struck (strength 0–1, e.g. velocity / 127)
  julia.strike(0.8);
</script>

There are two calls to know:

  • setNotes(notes) says what is sounding. It picks the shape, and the picture glides there. Call it every time a note starts or stops, passing everything still held. An empty list leaves the last shape in place, so the picture doesn't collapse between chords.
  • strike(strength) says when something was played. The shape bounces and a ring of the chord's color flows in and soaks into it. Call it on each note-on (or each chord you trigger).

Try [60, 64, 67] (C major, a round island), [55, 59, 62, 65] (G7, crystal shards) and [60, 61, 62, 63] (a cluster, dust).

Recipes

No bundler

Map the bare name to a CDN with an import map, and the Quick start page works as a static file:

<script type="importmap">
  {
    "imports": {
      "shapes-julia": "https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js",
      "shapes-julia/wheel": "https://cdn.jsdelivr.net/npm/[email protected]/dist/wheel.js",
      "shapes-julia/synth": "https://cdn.jsdelivr.net/npm/[email protected]/dist/synth.js"
    }
  }
</script>

Or import from the URL directly: import { createJulia } from 'https://esm.sh/[email protected]'.

React

Create the view once the canvas exists, and destroy it when the component goes away. Hold it in a ref, so a render never makes a second view.

import { useEffect, useRef, useState } from 'react';
import { createJulia, type JuliaView } from 'shapes-julia';

export function Julia({ notes, strikeKey }: { notes: number[]; strikeKey: number }) {
  const canvas = useRef<HTMLCanvasElement>(null);
  const view = useRef<JuliaView | null>(null);
  const [caption, setCaption] = useState({ text: '', color: '' });

  useEffect(() => {
    const julia = createJulia(canvas.current!);
    julia.on('chord', ({ name, feel, color }) => setCaption({ text: `${name}: ${feel}`, color }));
    view.current = julia;
    return () => { julia.destroy(); view.current = null; };
  }, []);

  useEffect(() => { view.current?.setNotes(notes); }, [notes]);
  useEffect(() => { if (strikeKey) view.current?.strike(0.8); }, [strikeKey]); // bump strikeKey to strike

  return (
    <>
      <canvas ref={canvas} style={{ width: '100%', height: '60vh' }} />
      <p style={{ color: caption.color }}>{caption.text}</p>
    </>
  );
}

React's Strict Mode mounts twice in development. That's fine: destroy() frees everything, and the canvas takes the new view. With server rendering (Next.js and the like), importing the package on the server is safe: nothing touches the DOM until createJulia runs, and effects only run in the browser.

Vue

<script setup lang="ts">
import { onMounted, onBeforeUnmount, ref, watch } from 'vue';
import { createJulia, type JuliaView } from 'shapes-julia';

const props = defineProps<{ notes: number[] }>();
const canvas = ref<HTMLCanvasElement>();
let julia: JuliaView | undefined;

onMounted(() => { julia = createJulia(canvas.value!); julia.setNotes(props.notes); });
watch(() => props.notes, notes => { julia?.setNotes(notes); julia?.strike(0.8); });
onBeforeUnmount(() => julia?.destroy());
</script>

<template><canvas ref="canvas" style="width: 100%; height: 60vh" /></template>

Other frameworks work the same way: create in the mount hook and destroy in the unmount hook.

A MIDI keyboard

The Web MIDI API delivers note numbers that setNotes takes as they are. Keep the set of held keys, send all of it on every change, and strike on each note-on:

import { createJulia } from 'shapes-julia';

const julia = createJulia(document.getElementById('julia'));
const held = new Set();

const access = await navigator.requestMIDIAccess();
for (const input of access.inputs.values()) {
  input.onmidimessage = ({ data: [status, note, velocity] }) => {
    const kind = status & 0xf0;
    if (kind === 0x90 && velocity > 0) {           // note on
      held.add(note);
      julia.setNotes([...held]);
      julia.strike(velocity / 127);
    } else if (kind === 0x80 || kind === 0x90) {   // note off (or note on at velocity 0)
      held.delete(note);
      julia.setNotes([...held]);                   // [] keeps the last shape
    }
  };
}

Web MIDI works in Chrome, Edge, Firefox and Chrome on Android. Safari and iOS don't have it.

When several notes of a chord land a few milliseconds apart, the view merges their strikes into one ring, so playing chords doesn't flood the picture.

With sound

Pair it with shapes-julia/synth, whose timbre follows the same shape, and let the glow follow what's actually heard:

import { createJulia } from 'shapes-julia';
import { startNote, loudness } from 'shapes-julia/synth';

const julia = createJulia(canvas, { loudness });
const releases = new Map();
const held = new Set();

function noteOn(note, velocity) {
  releases.set(note, startNote(note, velocity / 127));
  held.add(note);
  julia.setNotes([...held]);
  julia.strike(velocity / 127);
}
function noteOff(note) {
  releases.get(note)?.();
  releases.delete(note);
  held.delete(note);
  julia.setNotes([...held]);
}

When WebGL2 is missing

createJulia doesn't throw. Check isSupported() and show something else, and do the same if the browser takes the graphics away:

import { createJulia } from 'shapes-julia';

const julia = createJulia(canvas);
const fallback = document.getElementById('no-gl'); // e.g. "This device can't draw the fractal"
fallback.hidden = julia.isSupported();
julia.on('contextlost', () => { fallback.hidden = false; });
julia.on('contextrestored', () => { fallback.hidden = true; });

The chord event still fires without WebGL2, so captions and colors keep working.

API

createJulia(canvas, options?) → JuliaView

Each call makes its own view, so a page can hold several. It does not throw when WebGL2 is missing: check isSupported() and show your own fallback.

| Option | Default | | |---|---|---| | dark | follows prefers-color-scheme | Dark-theme colors. | | reducedMotion | follows prefers-reduced-motion | No wandering, gliding, bounce or rings; changes are immediate. | | background | #edf1ef light / #101518 dark | Behind the shape: '#rrggbb', '#rgb' or [r, g, b] in sRGB 0–1. Anything else throws a TypeError. | | maxPixelRatio | 1.5 | The highest drawing resolution, in device pixels per CSS pixel (the shader is heavy). | | autoResize | true | Follow the canvas's CSS size with a ResizeObserver. Set when created; with false, call resize() yourself. | | loudness | none | () => number, 0–1, read every frame: louder is a brighter, wider glow. Without it the level is what setLoudness() last gave, or each strike fading away. |

Leave dark and reducedMotion out to follow the system, which updates live. Pass them to follow your app's own setting instead.

JuliaView

| Method | | |---|---| | setNotes(notes: number[]) | The notes sounding now, as MIDI numbers (any octave, any order, duplicates fine). The shape glides to the chord's island or dust; an empty list leaves the picture as it is. Emits chord. | | strike(strength = 0.7, notes = last chord) | A strike: the shape bounces and a ring of the chord's color flows in and soaks into the island. Does nothing before any chord. | | setLoudness(value: number \| null) | Push a loudness (0–1); null goes back to following strikes. Ignored when the loudness option is given. | | setOptions(partial) | Change options live. A key given as undefined goes back to its default (e.g. following the system theme again). | | on(event, listener) → () => void | Listen; call the returned function to stop. | | resize() | Re-measure the canvas now. | | isSupported() | false without WebGL2, when the shader can't be built, or while the context is lost. | | destroy() | Stop drawing, remove every listener and observer, and free the WebGL program and buffer. Safe to call twice; later calls to the view do nothing. The canvas can be given to a new createJulia. |

Events

| Event | Payload | |---|---| | chord | A JuliaChord (below), after every setNotes with at least one note. | | contextlost | The browser took the graphics away (common on phones in the background); drawing stops. | | contextrestored | They came back and drawing has resumed. |

A listener that throws doesn't stop the others; its error is rethrown on a microtask so it still shows up in the console.

JuliaChord

| Field | Type | | |---|---|---| | notes | number[] | The notes given to setNotes. | | name | string | 'C major', 'A minor', 'G7'… or the note names when they make no chord ('C D♭ D E♭'). | | mood | Mood \| null | 'major' \| 'minor' \| 'maj7' \| 'dom7' \| 'm7' \| 'm7b5' \| 'dim7', or null when there is no chord. | | feel | string | Words for the shape, written for a child: 'A smooth, round island', 'Sharp crystal shards', 'Sparkly dust!'. | | color | string | The color the chord paints, as CSS rgb(r g b), ready for style.color. | | rgb | [r, g, b] | The same color in sRGB 0–1. | | tension | number | 0 for calm and up; the shape breaks into dust at DUST (0.73). | | dust | boolean | Whether the shape broke into dust. |

Other exports

  • toRGB(color: string | RGB): RGB turns '#rgb', '#rrggbb' or an sRGB 0–1 triple into sRGB 0–1, throwing a TypeError on anything else. It's the parser behind the background option.
  • Types: JuliaView, JuliaOptions, JuliaChord, JuliaEvents, JuliaListener, RGB.

Optional extras

shapes-julia/wheel: drag to play

Touch the picture like a circle of fifths: dragging round plays your way through the keys (12 o'clock is C, clockwise by fifths), with major chords on the outside and their relative minors in the middle.

import { createChordWheel } from 'shapes-julia/wheel';

const wheel = createChordWheel(canvas, {
  onChord: notes => { mySynth.play(notes); julia.setNotes(notes); julia.strike(0.7); },
  onTap: () => julia.strike(0.8),
});
// wheel.destroy() removes its listeners
  • createChordWheel(element, { onChord(notes), onTap?() }) → { destroy() }. onChord gets MIDI numbers around middle C each time the finger crosses into a new key. onTap is a press that wasn't dragged.
  • chordAt(dx, dy, width, height) → { key, notes } is the mapping on its own (dx, dy from the element's middle), for drawing labels or building your own input.

Give the element touch-action: none so a drag isn't taken as a scroll. The wheel uses pointer events only, so offer buttons or keys as well for people who can't drag.

shapes-julia/synth: the matching sound

The synth voice from Shapes, whose timbre follows the same Julia lens: round and mellow for calm chords, buzzing for tense ones, crackling for dust. It is a single shared audio graph per page, and it follows every note it is playing by itself, so there's nothing to tell it about the chord.

| Export | | |---|---| | startNote(midi: number, strength: number) → () => void | Start a held note (strength 0–1, e.g. velocity / 127). Call the returned function to release it. | | playNotes(notes: number[]) | A quick strum that rings out by itself, as when a chord is tapped. | | loudness() → number | How loud the output is right now, 0 to about 1, measured from the sound itself. Pass it as createJulia's loudness option. | | ensureAudio() → AudioContext | The shared context, created (and resumed) on first call. Call it inside a tap or key handler if you want sound ready before the first note. | | unlock(event) | The handler the entry installs on the first pointerup, click or keydown to start audio. You won't usually need it. |

Browsers only start audio after a user gesture. Importing shapes-julia/synth listens once for the first tap, click or key anywhere to unlock it, so this entry has side effects. The others don't. Each voice runs through a filter, shaper and compressor, and the synth plays at most 24 notes at once (the oldest fades).

shapes-julia/math: the shapes without the drawing

The pure functions behind the picture. They have no DOM and no WebGL, so they're safe on a server, in a worker or in tests. For example, to show a chord's color and words without drawing it:

import { juliaTarget, feelOf, nameChord, moodColor, toHex } from 'shapes-julia/math';

const notes = [57, 60, 64];                 // A minor
const { name, mood } = nameChord(notes);    // 'A minor', 'minor'
const target = juliaTarget(notes);          // { theta, reach, spin, dust }
feelOf(target);                             // 'An island with wiggly edges'
if (mood) toHex(moodColor(mood));           // the chord's color as '#rrggbb' (mood is null for no chord)

Chords

| Function | | |---|---| | nameChord(notes) → { name, quality, mood } | The chord's name, 'major' \| 'minor' \| null quality and Mood. | | tension(notes) → number | 0 for one note or silence, rising with roughness and instability; dust from DUST (0.73). | | juliaTarget(notes, last?) → JuliaTarget | Where the chord sits: theta (angle round the Mandelbrot cardioid), reach (1 = on its edge), spin (the picture's turn) and dust. Ambiguous chords (augmented, °7) keep the last target's theta and spin. | | feelOf({ reach, dust, fold? }) → string | The words the chord event uses. | | foldFor(tension) → number | How faceted (crystal-shard) the shape is, 0 to 1. foldNear(fold, reach) fades it out near the edge, so dust stays sparkly. |

Colors (OKLCH as LCh = [L, C, h]; dark lifts them for a dark background)

| Function | | |---|---| | moodColor(mood, dark?) → LCh | The color a chord kind paints: major family yellow and orange, minor family blue and violet. | | noteColor(midi, dark?) → LCh | A single note's color: one hue per note name round the circle of fifths, deep for low notes and pale for high. | | toHex(lch) → string | '#rrggbb' for CSS, losing chroma rather than hue when a color is out of gamut. |

The fractal (points are [x, y] in the complex plane)

| Function | | |---|---| | juliaC(theta, reach) → Point | The Julia parameter c for a place round the cardioid. | | escapes(c, max?) → boolean | Whether c is outside the Mandelbrot set, so its Julia set is dust. | | escapeRadius(c) → number | A radius that holds the whole Julia set. | | attractor(c) → { alpha, rate } | The attracting fixed point inside an island, and how fast points settle on it. | | settleCount(z, c, attractor, max?, fold?) → number \| null | Smooth steps for z to settle (null if it escapes): the depth colors soak in by. | | depthRange(c, grid?, fold?) → [lo, hi] | The island's 10th to 90th percentile settle counts. | | islandReach(tension) → number | How far out an island sits for a tension. | | islandExtent(c, spin?, fold?, …) → [halfWidth, halfHeight] | How far the shape reaches across and up, for framing it. | | findDust(theta, reach, margin?) → { theta, reach } | A nearby place that is dust all the way out. | | DUST, ISLAND_EDGE, CUSP, MINOR_REACH, DUST_BREATH | The constants behind these. |

The shader: vertexSource and fragmentSource (GLSL ES 3.00) and UNIFORMS (every uniform name) are exported so you can read or reuse them. The shape uniforms are res (canvas pixels), c, alpha and useAlpha (1 for an island), lnRate (ln of attractor(c).rate, or −1), depthLo / depthHi (from depthRange), fold, view (half the shorter side, in complex units) and spin. The color uniforms (halo, ring, soak, …) are set by the view's internal ring-and-soak model and aren't a stable API. To draw the picture, use createJulia.

Performance

  • The shader is heavy: every pixel iterates up to 300 steps. The view draws at most 30 frames a second, at up to maxPixelRatio (1.5) device pixels per CSS pixel. Lower it to 1 for big canvases on phones.
  • It only draws while something moves. With reducedMotion it stops completely once the shape settles. Without it, a gentle ambient wander keeps drawing at 30 fps, so destroy views you're not showing.
  • It pauses while the page is hidden and carries on where it was when the page comes back.
  • Each view has its own WebGL context, and browsers allow about 16 per page. Several views are fine; dozens are not.
  • The CPU side is small: about 1 ms per new chord to measure its shape for framing (remembered for repeats), and about 0.3 ms per drawn frame to sample the island's depth range.

How the chord picks the shape

The chord's pitch-class Fourier transform picks a point on the edge of the Mandelbrot set's main cardioid: the fifths component chooses where (so each key has its own place), and the thirds component sets the picture's turn. Tension (roughness plus instability) chooses how far out the point sits. Below the dust line it stays inside, where the Julia set is one connected island (minor chords reach a little further, so relative major and minor differ in form). At the dust line or above, it searches for a nearby point outside, where the set shatters into dust. Tense chords also facet the shape into straight-edged crystal shards.

Outside points are drawn by Inigo Quilez's distance estimate, so filaments stay bold and dust stays visible. Inside points stop once they settle on the island's attracting point, and how long that took is the depth the color soaks in by.

Browser support

WebGL2: Safari 15+, Chrome/Edge 56+, Firefox 51+, Android System WebView on Android 7+. The code targets ES2020. TypeScript users need moduleResolution bundler, node16 or nodenext (or node, through typesVersions).

Changes

See CHANGELOG.md.

Licence

MIT. See LICENSE.