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 = 14;
const iterations = 3;
function walkAndSplit(t, s, angleSpread, divisions) {
t.pendown();
t.fd(s);
var newTs = [];
var heading = t.h();
heading = heading - (angleSpread / 2);
var angleChange = angleSpread / divisions;
for (i = 0; i <= divisions; i++) {
var nt = t.clone();
nt.seth(heading)
newTs.push(nt)
heading += angleChange;
}
return newTs;
}
function step(t) {
return walkAndSplit(t, stepSize, radialSpread, subdivisions)
}
// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
turtle.goto(0,stepSize);
turtle.seth(-90);
turtle.pendown();
var turtles = [turtle];
// The walk function will be called until it returns false.
function walk(i) {
turtles = turtles.flatMap(step);
return i < iterations;
}