xxxxxxxxxx
115
// a color variable
var c, d;
var x;
//for width and height
var w;
var h;
var mic;
//to make a for loop with varialbe
var length;
// for lerping the length;
var plength;
//to map the level of the mic to a useable level
var levelMap;
//for lerping the level
var plevelMap;
function setup() {
createCanvas(windowWidth, windowHeight);
w = windowWidth;
h = windowHeight;
//mic stuff
mic = new p5.AudioIn();
//starts the mic
mic.start();
//connects the mic to the computer output
// mic.connect();
//starts p5 amplitude...
amplitude = new p5.Amplitude();
// so we can take the level of the mic...
amplitude.setInput(mic);
//to start out for loop length
length = 300;
//hate radians always
angleMode(DEGREES);
//starting an oscillator to tie to amplitude level
osc = new p5.Oscillator();
osc.setType('sin');
//this will be set to a variable of level later
osc.freq(240);
// sets volume from 0.0 to 1.0
osc.amp(0.3);
osc.start();
}
function draw() {
// takes the length of the for loop and changes it based on
// the level of the mic as mapped by levelMap
//constrained to not go negative
length = 4 * constrain(levelMap, 30, 300);
//lerping to smooth things
lengthLerp = lerp(plength, length, 0.1);
//moving things around
translate(w / 2, h/10);
push();
colorMode(HSB);
// background(109, 147, 115, 80);
background(200, 50, 20, 10);
// print(c);
pop();
// fill(255);
textSize(18);
text("make noise & mouseX around", w/10, h/10);
//gets the level of the mic into a variable
level = amplitude.getLevel();
//mapping mic level from amplitude to a usable value
mouseXMap = map(mouseX, 0, w, 0, 100);
levelMap = map(level, 0, 1, -1, mouseXMap);
//lerping above
levelLerp = lerp(plevelMap, levelMap, 0.5);
//for mapping mic level to the oscillator freuency
freqMap = map(level, 0, 1, 100, 500);
//run a for loop to make the circles
// of a length that varies depending on how loud the mic is
for (var i = 0; i < length; i++) {
//have the circles be at random-ish colors
c = color(random(100), 100, random(150));
// d = color(random(10), 100, random(200));
fill(c);
// stroke(d);
// strokeWeight(levelLerp*10);
//have the circles make a circular shape and twist up
//depending on the level of the mic
// also spread apart depending on the length
ellipse((w / 2 * sin(i * 10 * levelMap) + (10 / i))*0.5,
((h / 10 * sin(i * 11 * levelLerp) + (i * 10)))*0.5, w / 20);
//control the oscillator frequency
//via the mic and i or the length value
osc.freq(freqMap + mouseXMap);
//for lerping
plevelMap = levelMap;
plength = length;
}
// print(levelMap);
}