Every step turtles walk a fixed amount forward and turn their head based off of the a*sin(x) + b*cos(y) of their position
Log in to post a comment.
// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);
// Global code will be evaluated once.
const turtles = [];
let seed = 1000; // min=1 max=1000000 step=1
const bits = 20;
const samples = 150000;
const mod = 1<<bits;
const num_turtles = 29; // min = 1 max = 100 step = 1
const steps = 10000; // min = 10 max = 10000 step = 1
const forward_step_size = 0.08; // min = 0.01 max = .15 step = 0.01
const spawn_range = 61; // min = 0 max = 100 step = 1
const sin_modifier = 2.5; // min = 0 max = 10 step = 0.1
const cos_modifier = 6.6; // min = 0 max = 10 step = 0.1
for(let i = 0; i < num_turtles; i++) {
let turtle = new Turtle();
turtle.penup();
turtle.setheading(random() * 360);
let radius = random() * spawn_range;
let theta = random() * Math.PI * 2;
turtle.setx(radius * Math.cos(theta));
turtle.sety(radius * Math.sin(theta));
turtle.pendown();
turtles.push(turtle);
}
// The walk function will be called until it returns false.
function walk(i) {
for(let j in turtles) {
turtles[j].right(sin_modifier * Math.sin(turtles[j].x()) + cos_modifier * Math.cos(turtles[j].y()));
turtles[j].forward(forward_step_size);
}
return i < steps;
}
////////////////////////////////////////////////////////////////
// Pseudorandom number generator. Created by Reinder Nijhoff 2024
// https://turtletoy.net/turtle/a2274fd1fe
////////////////////////////////////////////////////////////////
function random() { // returns a number [0, 1[
let r = 1103515245 * (((seed+=12345) >> 1) ^ seed);
r = 1103515245 * (r ^ (r >> 3));
r = r ^ (r >> 16);
return (r % mod) / mod;
}