Public
Edited
Apr 26, 2023
Insert cell
Insert cell
p5(sketch => {
let mic;
sketch.setup = function() {
// see https://p5js.org/reference/#/p5.AudioIn
mic = new p5Sketch.AudioIn();
mic.start();
};
sketch.draw = function() {
// background(220, 220, 220, 10);
sketch.background(200);
// get current microphone level
let micLevel = mic.getLevel(); // between 0 and 1
// The size of the circle proportional to mic level
// The min and max of micLevel is 0 - 1. Map this to
// the diameter values of 5 to maxDiameter
let diameter = sketch.map(micLevel, 0, 1, 5, 1000);
sketch.circle(sketch.width / 2, sketch.height / 2, diameter);
};
})
Insert cell
p5Sketch = require("p5").then(async (p5) => {
// newer versions of p5 sound don't work with es6 modules
await require("p5@0.9.0/lib/addons/p5.sound.min.js");
return p5;
})
Insert cell
import {p5} from "@tmcw/p5"
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