Public
Edited
Jun 11, 2023
1 fork
1 star
Insert cell
Insert cell
koch = new LSystem("F", {
F: "F+F--F+F",
"+": "+",
"-": "-"
})
Insert cell
Insert cell
{
const width = 500;
const height = 250;
const turtle = new Turtle({ width, height, x: 0, y: height });

const d = 2;
const t = 85;
const n = 7;

drawSequence(turtle, koch.iteration(n), d, t);
return turtle.draw();
}
Insert cell
{
const width = 500;
const height = 250;
const turtle = new Turtle({ width, height, x: width / 2, y: height / 2 });

const d = 40;
const t = 120;
const n = 8;
drawSequence(turtle, koch.iteration(n), d, t);
return turtle.draw();
}
Insert cell
Insert cell
function drawSequence(turtle, iteration, dist, angle) {
iteration.split("").forEach((c) => {
switch (c) {
case "F":
turtle.forward(dist);
break;
case "+":
turtle.left(angle);
break;
case "-":
turtle.right(angle);
break;
}
});
}
Insert cell
import {Turtle} from "@pnavarrc/turtle-graphics"
Insert cell
import {LSystem} from "@pnavarrc/l-systems"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more