A ball tree
Log in to post a comment.
// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);
const stepSize = 30;
const radialSpread = 360;
const subdivisions = 13;
const iterations = 3;
function walkAndSplit(tState) {
console.log(tState.step);
// t, s, angleSpread, divisions
tState.turtle.pendown();
tState.turtle.fd(tState.step);
var newTs = [];
var heading = tState.turtle.h();
heading = heading - (tState.angleSpread / 2);
const angleChange = tState.angleSpread / tState.divisions;
for (i = 0; i <= tState.divisions; i++) {
var nt = tState.turtle.clone();
nt.seth(heading)
newTs.push({turtle: nt, step: tState.step, angleSpread: tState.angleSpread *2, divisions: tState.divisions + 1});
heading += angleChange;
}
return newTs;
}
// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
turtle.goto(0,stepSize);
turtle.seth(-90);
turtle.pendown();
var turtles = [{turtle: turtle, step: stepSize, angleSpread: radialSpread, divisions: subdivisions}];
// The walk function will be called until it returns false.
function walk(i) {
turtles = turtles.flatMap(walkAndSplit);
console.log(turtles);
return i < iterations;
}