Public
Edited
Apr 18
Insert cell
Insert cell
(await visibility(),
p5((sketch) => {
sketch.setup = function () {
sketch.createCanvas(500, 500);
};
sketch.draw = function () {
sketch.background(255);
drawTriangle(sketch);
if (sketch.keyIsDown(sketch.LEFT_ARROW)) {
vars.angle -= 0.1;
}

if (sketch.keyIsDown(sketch.RIGHT_ARROW)) {
vars.angle += 0.1;
}
vars.pos = vecmath.trans(vars.pos, vars.angle, vars.velocity);
};
}))
Insert cell
function drawTriangle(sketch) {
sketch.push();
sketch.noStroke();
sketch.fill("steelblue");
sketch.translate(...vars.pos);
sketch.rotate(vars.angle);
sketch.triangle(-15, -5, 0, 0, -15, 5);
sketch.pop();
}
Insert cell
vars = ({
angle: 0,
velocity: 0.1,
pos: [100, 100]
})
Insert cell
p5
Insert cell
x = 100
Insert cell
y = 100
Insert cell
import {p5} from "@tmcw/p5"
Insert cell
import { vecmath } from "@harrystevens/vector-math@254"
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