xxxxxxxxxx
55
// Rapid doodle prototype that lets you set brush size with microphone
// Try drawing and singing!
//
// Prototype 1: https://editor.p5js.org/jonfroehlich/sketches/0ERh-9Lbc
// Basic drawing app
//
// Prototype 2: https://editor.p5js.org/jonfroehlich/sketches/ZZFLDQL0H
// This prototype
//
// Prototype 3: https://editor.p5js.org/jonfroehlich/sketches/MSGdVYUle
// Sets brush color based on x-mouse position
//
// This prototype: https://editor.p5js.org/jonfroehlich/sketches/hFnLaol1u
// Sets brush size based on microphone level
//
// By Jon E. Froehlich
// https://makeabilitylab.cs.washington.edu/
//
let diameter= 50;
let mic;
function setup() {
createCanvas(600, 400);
background(140);
noStroke();
colorMode(HSB);
mic = new p5.AudioIn();
mic.start();
}
function draw() {
// background(220);
let hue = map(mouseX, 0, width, 0, 360);
if(mouseIsPressed == true){
noFill();
stroke(hue, 70, 80, 0.8);
}else{
// fill is taking red, green, blue, opacity
// from 0 to 255 where 255 is max
noStroke();
fill(hue, 70, 80, 0.8);
}
//diameter = dist(mouseX, mouseY, pmouseX, pmouseY);
micLevel = mic.getLevel();
diameter = map(micLevel, 0, 1, 5, 1000);
circle(mouseX, mouseY, diameter);
}
function keyPressed(){
print(key);
if(key == ' '){
background(190);
}
}