Music House

Harmonic architecture?

Log in to post a comment.

Canvas.setpenopacity(-0.125);

const size = 200;
const step = 0.025;
const iters = 0.8+Math.random()*0.15;
const fstep = 1;
const p = 0.1315+Math.random()*0.00751;
const q = p/4-Math.random()*0.0185;

let turtles = [];
let iter = 0;

Turtle.prototype.withinBounds = function() {
    return Math.abs(this.x()) <= size/2 && Math.abs(this.y());
}

const spawnTurtle = (x = 0, y = 0, angle = 0) => {
    const turtle = new Turtle();
    turtle.penup();
    turtle.goto(x, y);
    turtle.seth(angle);
    turtle.pendown();
    return turtle;
}

function walk(i) {
    round = Math.floor(iter/Math.round(size/step));
    if (turtles.length) {
        turtles.map((turtle, idx) => {
            const x = turtle.x();
            const y = turtle.y();
            turtle.mod = Math.sin(
                p/q*iter+p*q*(Math.sin(q*p*x)+Math.sin(q*q*y))
                /
                p/(p*q*Math.cos(q*p*p*x)+p*Math.sin(q*q*p*y))
            );
            turtle.forward(fstep);
            turtle.right(turtle.mod);
        });
        turtles = turtles.filter(turtle => {
            if (!turtle.withinBounds()) {
                iter++;
                return false;
            }
            return true;
        });
    }
    else {
        turtles.push(spawnTurtle(-size/1.5+(iter*step)%size, -160, 90));
    }
    return iter < iters*(size/step);
}