p5.js
Orbit Loom
A spirograph loom. One line, woven by two invisible gears into a rosette that breathes and never quite repeats. Drag the sliders to change the gears — click the canvas for a new weave.
Licence: CC BY-NC-SA 4.0: remix with credit, non-commercial, share alike
View the code
// Orbit Loom — a spirograph harmonograph in p5.js
// One line weaves an endless rosette; the geometry slowly breathes, so the
// pattern never repeats. Palette: charcoal #0D0D12, bone #e9e5da, signal orange #ffb454
// Click the canvas for a new weave · Press S to save a frame
// Live sliders: Teeth (gear ratio) · Reach (pen offset) · Trails (fade) · Spin (morph speed)
const BONE = [233, 229, 218];
const ORANGE = [255, 180, 84];
const BG = [13, 13, 18];
let t = 0;
let seedPhase = 0;
let prevMain = null, prevEcho = null;
let sTeeth, sReach, sTrails, sSpin, uiBox;
function setup() {
createCanvas(windowWidth, windowHeight);
background(...BG);
buildControls();
}
function buildControls() {
uiBox = createDiv();
uiBox.style('position', 'absolute');
uiBox.style('left', '14px');
uiBox.style('background', 'rgba(13,13,18,0.55)');
uiBox.style('padding', '10px 12px');
uiBox.style('border-radius', '10px');
uiBox.style('font-family', "'JetBrains Mono', monospace");
uiBox.style('color', '#e9e5da');
uiBox.style('z-index', '5');
const row = (label, slider) => {
const r = createDiv();
r.parent(uiBox);
r.style('display', 'flex');
r.style('align-items', 'center');
r.style('gap', '10px');
r.style('margin', '3px 0');
const lab = createSpan(label);
lab.parent(r);
lab.style('font-size', '11px');
lab.style('width', '52px');
lab.style('letter-spacing', '0.05em');
slider.parent(r);
slider.style('width', '130px');
};
sTeeth = createSlider(40, 200, 105, 1); row('Teeth', sTeeth);
sReach = createSlider(60, 320, 190, 1); row('Reach', sReach);
sTrails = createSlider(3, 50, 7, 1); row('Trails', sTrails);
sSpin = createSlider(0, 3, 1, 0.1); row('Spin', sSpin);
placeControls();
}
function placeControls() {
if (uiBox) uiBox.position(14, height - 138);
}
function loomPoint(tt, dd, s) {
const R = min(width, height) * 0.34;
const r = sTeeth.value();
const k = (R - r) / r;
const x = (R - r) * cos(tt) + dd * cos(k * tt + seedPhase);
const y = (R - r) * sin(tt) - dd * sin(k * tt + seedPhase);
return [width / 2 + x * s, height / 2 + y * s];
}
function draw() {
noStroke();
fill(BG[0], BG[1], BG[2], sTrails.value());
rect(0, 0, width, height);
const breathe = sin(frameCount * 0.004 * sSpin.value()) * 36;
const dd = sReach.value() + breathe;
seedPhase += 0.0006 * sSpin.value();
const steps = 240;
for (let i = 0; i < steps; i++) {
t += 0.02;
const m = 0.5 + 0.5 * sin(t * 0.05);
const cr = lerp(BONE[0], ORANGE[0], m);
const cg = lerp(BONE[1], ORANGE[1], m);
const cb = lerp(BONE[2], ORANGE[2], m);
const pm = loomPoint(t, dd, 1);
if (prevMain) {
stroke(cr, cg, cb, 46); strokeWeight(3.2);
line(prevMain[0], prevMain[1], pm[0], pm[1]);
stroke(cr, cg, cb, 190); strokeWeight(1.2);
line(prevMain[0], prevMain[1], pm[0], pm[1]);
}
prevMain = pm;
const pe = loomPoint(t + PI, dd, 0.62);
if (prevEcho) {
stroke(cr, cg, cb, 70); strokeWeight(1);
line(prevEcho[0], prevEcho[1], pe[0], pe[1]);
}
prevEcho = pe;
}
}
function mousePressed(e) {
if (e && e.target && e.target.tagName !== 'CANVAS') return;
seedPhase = random(TWO_PI);
prevMain = null; prevEcho = null;
}
function keyPressed() {
if (key === 's' || key === 'S') saveCanvas('orbit-loom', 'png');
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
background(...BG);
prevMain = null; prevEcho = null;
placeControls();
}