Published
Edited
Mar 21, 2020
Fork of L-Systems
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
poseDemo = {
// (0, 0)
const S = Pose();

// S -----> S1 (5, 0)
let S1 = move(5, S);
S1 = turn(degToRad(90), S1);

// S -----> S1
// |
// S2 (5, 2)
const S2 = move(2, S1);

// Should return a Pose with position [5, 2] and direction <0, 1>
const [x, y] = S2.position;
const [a, b] = S2.direction;
return `Final pose: Position [${x}, ${y}] and Direction <${a}, ${b}>.`;
}
Insert cell
// Converts a string of commands into an array of positions.
convert = input => {
const tokens = input.split("");

let current = Pose();
let stack = [];
let paths = [];

tokens.forEach(token => {
switch (token) {
case "F":
let newPath = [current.position];
current = move(magnitude, current);
newPath.push(current.position);
paths.push(newPath);
break;
case "+":
current = turn(-degToRad(angle), current);
break;
case "-":
current = turn(degToRad(angle), current);
break;
case "[":
stack.push(current);
break;
case "]":
current = stack.pop();
break;
}
});

return paths;
}
Insert cell
convert(axiom)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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