Public
Edited
Jan 26, 2024
Insert cell
Insert cell
p5((s) => {
let points = [];
let step = 6;
let mic;

s.setup = function () {
s.createCanvas(width, 500);
mic = new pSound.AudioIn();
mic.start();

for (let i = 0; i < 50; i++) {
points.push(s.createVector(s.random(s.width), s.random(s.height)));
}

s.noFill();
s.noStroke();
s.frameRate(30);
};

s.draw = function () {
let micLevel = mic.getLevel(); // between 0 and 1
let micMapped = s.map(micLevel, 0, 1, 0, 2);

s.background(0);
// Move the points smoothly across the screen
for (let i = 0; i < points.length; i++) {
points[i].x += s.cos(s.frameCount * micMapped + i);
points[i].y += s.sin(s.frameCount * micMapped + i);
}

drawVoronoi();
};

function drawVoronoi() {
for (let x = 0; x < s.width; x += step) {
for (let y = 0; y < s.height; y += step) {
let minDist = s.dist(0, 0, s.width, s.height);
let j = -1;
for (let i = 0; i < points.length; i++) {
let d = s.dist(x, y, points[i].x, points[i].y);
if (d < minDist) {
minDist = d;
j = i;
}
}
let c = minDist * 2;
s.fill(c);
s.rect(x, y, step, step);
}
}
}
})
Insert cell
pSound = require("p5").then(async (p5) => {
await require("p5@0.9.0/lib/addons/p5.sound.min.js");
return p5;
})
Insert cell
import {p5} from "@thometnanni/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