Ascensions

Using bounds for vignettes.

Log in to post a comment.

Canvas.setpenopacity(-0.1);

const size = 200;
const divs = 5;
const blockSize = size/divs;
const maxItersPerBlock = 145;

let turtles = [];
let block = -1;
let bi = 0;
let x, y, j, nt, bso;

Turtle.prototype.withinBounds = function() {
    return this.x() >= this.bounds[0] && this.y() >= this.bounds[1] && this.x() < this.bounds[2] && this.y() < this.bounds[3];
}

Turtle.prototype.setBounds = function(...args) {
    this.bounds = [...args];
}

const spawnTurtle = (x = 0, y = 0, energy = 20, step = 10, angle = 15, bs = 0.99) => {
    const turtle = new Turtle();
    turtle.penup();
    turtle.goto(x, y);
    turtle.energy = energy;
    turtle.step = step;
    turtle.angle = angle;
    turtle.bs = bs;
    turtle.seth(270);
    turtle.root = true;
    turtle.pendown();
    return turtle;
}

function walk(i) {
    if (turtles.length && bi < maxItersPerBlock) {
        turtles.map(turtle => {
            turtle.forward(turtle.energy/100+turtle.step*0.125);
            if (i%15==0) {
                for (j = 0; j < 2; j++) {
                    nt = turtle.clone();
                    nt.energy = turtle.energy*0.9;
                    nt.step = 2.5;
                    nt.bs = turtle.bs * turtle.bs;
                    nt.angle = i%2==0 ? turtle.angle/4 : turtle.angle*2;
                    j%2==0 ? nt.left(nt.angle) : nt.right(nt.angle);
                    bso = 1-(Math.abs(turtle.bounds[3]-turtle.bounds[1])/blockSize)*nt.bs
                    nt.setBounds(turtle.bounds[0]+bso, turtle.bounds[1]+bso, turtle.bounds[2]-bso, turtle.bounds[3]-bso);
                    turtles.push(nt);
                }
            }
            turtle.energy *= 0.994;
        });
        turtles = turtles.filter(turtle => turtle.energy > 0.75 && turtle.withinBounds());
        bi++;
    }
    else {
        block++;
        x = block%divs;
        y = Math.floor(block/divs);
        bi = 0;
        nt = spawnTurtle(-100+x*blockSize+blockSize/2, -100+y*blockSize+blockSize, 25+x+y, 5+x*y, 30+x*30+y*22.5);
        nt.setBounds(-100+x*blockSize, -100+y*blockSize, -100+(x+1)*blockSize, -100+(y+1)*blockSize);
        turtles = [nt];  
    }
    return y < divs;
}