Decreasing bounds per generation.
Log in to post a comment.
Canvas.setpenopacity(-0.1); const size = 100; let turtles = []; let j, nt; Turtle.prototype.withinBounds = function() { return this.x() > this.bounds[0] && this.x() < this.bounds[1] && this.y() > this.bounds[2] && this.y() < this.bounds[3]; } Turtle.prototype.setBounds = function(...args) { this.bounds = [...args]; } const spawnTurtle = (x = 0, y = size/2) => { const turtle = new Turtle(); turtle.penup(); turtle.goto(x, y); turtle.seth(270); turtle.energy = 30; turtle.step = 10; turtle.root = true; turtle.angle = 30; turtle.bs = 0.97; turtle.setBounds(-size, size, -size, size); turtle.pendown(); turtles.push(turtle); } spawnTurtle(); function walk(i) { turtles.map(turtle => { turtle.forward(turtle.energy/100+turtle.step*0.125); if (i%23==0) { for (j = 0; j < 2; j++) { nt = turtle.clone(); nt.energy = turtle.energy*0.9; nt.step = 2.5; nt.bs = turtle.bs * 0.97; nt.angle = i%2==0 ? turtle.angle/4 : turtle.angle*2; j%2==0 ? nt.left(nt.angle) : nt.right(nt.angle); nt.setBounds(turtle.bounds[0]*nt.bs, turtle.bounds[1]*nt.bs, turtle.bounds[2]*nt.bs, turtle.bounds[3]*nt.bs); turtles.push(nt); } } turtle.energy *= 0.994; }); turtles = turtles.filter(turtle => turtle.energy > 0.75 && turtle.withinBounds()); return i < 305 && turtles.length > 0; }