Tall grass

Slightly turning turtles at random.

Log in to post a comment.

Canvas.setpenopacity(0.25);

const participants = 4096;
const turniness = 2;
const seed = Math.random()*999;

let a, b;
let turtles = [...Array(participants)].map(() => new Turtle());
turtles.map((turtle, idx) => {
    turtle.penup();
    turtle.goto(120-idx*240/participants, 180);
    turtle.seth(270+5*Math.sin(seed+0.6*idx+Math.sin(seed+0.5*idx)));
    turtle.pendown();
    turtle.speed = 0.5+Math.random();
    turtle.height = Math.random() > 0.5 ? 20+30*Math.random() : 50+20*Math.random();
    turtle.head = Math.random() > 0.1 ? 0 : 10+30*Math.random();
    turtle.headWidth = Math.random() > 0.5 ? 1+3*Math.random() : Math.random();
    turtle.headAngle = Math.random() > 0.5 ? 15+15*Math.random() : 0;
})

function walk(i) {
    turtles.map(turtle => {
        turtle.right(turniness*(-0.5+Math.random()));
        turtle.speed *= (1-Math.random()*0.01);
        turtle.forward(turtle.speed);
        if (turtle.head > 0 && turtle.y() < (20 - turtle.height + turtle.head)) {
            a = turtle.clone();
            b = turtle.clone();
            a.left(45+Math.random()*15);
            a.forward(turtle.headWidth);
            b.right(45+Math.random()*15);
            b.forward(turtle.headWidth);
            turtle.left(turtle.headAngle*(1-2*(i%2)));
        }
    });
    turtles = turtles.filter(turtle => turtle.speed > 0.2 && turtle.y() > -100);
    return turtles.length > 0;
}