Published
Edited
Sep 22, 2021
1 fork
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 path = [];
let current = Pose();

tokens.forEach(token => {
switch (token) {
case "F":
current = move(magnitude, current);
path.push(current.position);
break;
case "+":
current = turn(-degToRad(angle), current);
break;
case "-":
current = turn(degToRad(angle), current);
break;
}
});

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