Touching circles

A method of drawing infinitely many touching circles, based on this tweet twitter.com/matthen2/status/1256824725814120448 by @matthen2 and youtu.be/sg_6nlmz8f4.

Log in to post a comment.

// Touching circles. Created by Reinder Nijhoff 2020 - @reindernijhoff
//
// https://turtletoy.net/turtle/59d0a20f0c
//
// Based on https://twitter.com/matthen2/status/1256824725814120448 by @matthen2
//

const turtle = new Turtle();

const pow = -1; // min=-2, max=0, step=0.01
const xoffset = -.25; // min=-1, max=1, step=0.01
const yoffset = -.65; // min=-1, max=1, step=0.01

const radius =  45;
const grid   =  40;
const steps  = 250;

function trans(p) {
    p[0] += xoffset; p[1] += yoffset;
    let s = Math.pow(p[0]**2 + p[1]**2, pow);
    return [radius * p[1] * s, radius * p[0] * s];
};

function addCircle(x,y) {
    turtle.jump(trans([x+.5,y]));
    for (let i=0; i<=steps; i++) {
        const a = Math.PI * 2 * i / steps;
        turtle.goto(trans([x+.5*Math.cos(a), y+.5*Math.sin(a)]));
    }
}

function walk(i) {
    const x = (i % grid) - (grid/2|0);
    const y = (i/grid|0) - (grid/2|0);
    addCircle(x, y);
    return i < grid * grid - 1;
}