Public
Edited
Mar 18, 2022
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
sketch = function (s) {
// set global vars here

const tau = 2 * Math.PI;
const colour1 = "yellow";
const colour2 = "#6317c5";

s.setup = function () {
s.createCanvas(container.width, container.height);

s.background(colour1);
s.fill(colour1);
s.stroke(colour2);
s.strokeWeight(5);

for (let i = 0; i < 10; ++i) {
for (let j = 0; j < 10; ++j) {
if (Math.random() < 0.5) {
s.arc(i * 50, j * 50, 75, 75, 0, 0.25 * tau);
s.arc((i + 1) * 50, (j + 1) * 50, 75, 75, 0.5 * tau, 0.75 * tau);
s.arc(i * 50, j * 50, 50, 50, 0, 0.25 * tau);
s.arc((i + 1) * 50, (j + 1) * 50, 50, 50, 0.5 * tau, 0.75 * tau);
s.arc(i * 50, j * 50, 25, 25, 0, 0.25 * tau);
s.arc((i + 1) * 50, (j + 1) * 50, 25, 25, 0.5 * tau, 0.75 * tau);
} else {
s.arc((i + 1) * 50, j * 50, 75, 75, 0.25 * tau, 0.5 * tau);
s.arc(i * 50, (j + 1) * 50, 75, 75, 0.75 * tau, tau);
s.arc((i + 1) * 50, j * 50, 50, 50, 0.25 * tau, 0.5 * tau);
s.arc(i * 50, (j + 1) * 50, 50, 50, 0.75 * tau, tau);
s.arc((i + 1) * 50, j * 50, 25, 25, 0.25 * tau, 0.5 * tau);
s.arc(i * 50, (j + 1) * 50, 25, 25, 0.75 * tau, tau);
}
}
}
};

s.draw = function () {
// drawing code here
};
}
Insert cell
Insert cell
container = ({ width: 500, height: 500, id: "p5-container" })
Insert cell
myP5 = {
// Resets div container
display.innerHTML = "";
// Reinstantiate the p5 with the sketch
return new p5(sketch, display);
}
Insert cell
p5 = require("p5")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more