Published
Edited
Mar 29, 2020
3 forks
Also listed in…
P5.js
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
p5(sketch => {
sketch.setup = function() {
sketch.createCanvas(width, height);
sketch.colorMode(sketch.HSB, 360, 100, 100, 50);
sketch.noFill();
sketch.rect(0, 0, width, height);
};
sketch.draw = function() {
// sketch.noLoop();
sketch.background(255, 2);
// number of vertex dependant on seconds
const thisSecond = new Date().getSeconds() / 2;
const circleResolution = sketch.map(thisSecond, 0, 30, 2, 60); // if 0 seconds --> 2 points
const radius = sketch.map(thisSecond, 0.5, 30, 0.5, height / 2) + Math.random(); // if 0 seconds --> 2 points
const angle = sketch.TWO_PI / circleResolution;
sketch.strokeWeight(thisSecond / 30);
// translate canvas to draw from the middle of it
sketch.translate(width / 2, height / 2);
sketch.beginShape();
for (var i = 0; i <= circleResolution; i++) {
const x = sketch.cos(180 - angle * i) * radius;
const y = sketch.sin(180 - angle * i) * radius;
// sketch.line(0, 0, x, y);
sketch.vertex(x, y);
}
sketch.endShape(sketch.CLOSE);
}
})
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