Created
November 3, 2015 14:30
-
-
Save claytical/07f877dac8d786df0df5 to your computer and use it in GitHub Desktop.
p5js using mic input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mic; | |
| var micOn; | |
| function setup() { | |
| // uncomment this line to make the canvas the full size of the window | |
| createCanvas(windowWidth, windowHeight); | |
| // the volume is a number between 0 and 1 | |
| mic = new p5.AudioIn(); | |
| micOn = false; | |
| } | |
| function draw() { | |
| // draw stuff here | |
| background(255); | |
| if (micOn) { | |
| var micLevel = mic.getLevel(); | |
| var circleSize = map(micLevel, 0, 1, 0, width); | |
| fill(0); | |
| ellipse(width/2, height/2, circleSize, circleSize); | |
| } | |
| } | |
| function mousePressed() { | |
| micOn = !micOn; | |
| if (micOn) { | |
| mic.start(); | |
| } | |
| else { | |
| mic.stop(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment