xxxxxxxxxx
110
// let currentColor;
let song;
let mic;
let smoothSizeOfCircle = 0;
const size = 1;
const moveScale = 800;
const space = 30;
function setup() {
currentColor = color(239,68,14);
song = loadSound('assets/tame_impala_a.mp3');
createCanvas(windowWidth, windowHeight);
mic = new p5.AudioIn();
mic.start();
}
function mousePressed() {
if (song.isPlaying()) {
// .isPlaying() returns a boolean
song.stop();
//background(255, 0, 0);
} else {
song.play();
//background(0, 255, 0);
}
}
function draw() {
background(0, 0, 0);
// read mic-input intensity
let intensity = mic.getLevel();
let sizeOfCircle = map(intensity,0,1,50, 2000);
// let sizeOfRect = map(intensity,0,5,10, 9000000);
// smoothen the change in intensity
smoothSizeOfCircle += (sizeOfCircle - smoothSizeOfCircle) * 0.1;
let n =14;
let w = width/n;
let h =height/n;
strokeWeight(2)
// push()
// let time = millis()/2000
// let ini = (time*500)%space
// for(let x = ini; x < width; x+=space){
// for(let y = ini; y < height; y+=space){
// let angle = noise((x-mouseX) / moveScale, (y-mouseY) / moveScale, time/5) * TWO_PI * 10;
// let xx = cos(angle) * size;
// let yy = sin(angle) * size;
// //stroke(lerpColors(angle%TWO_PI/TWO_PI, colors));
// line(x-xx, y-yy, x+xx, y+yy);
// }
// }
//circle 1
push();
translate(w/2,h/2);
for(let i=0; i<n; i++) {
for(let a=0; a<n; a++){
push()
translate(i*w,a*h)
fill(5, 87, 240);
ellipse(0,0, sin((frameCount + (i*a))*0.1) * smoothSizeOfCircle);
pop();
}
}
pop();
// circle 2
push();
translate(w/2,h/2);
for(let i=0; i<n; i++) {
for(let a=0; a<n; a++){
push()
translate(i*w,a*h)
fill(255, 166, 180);
square(0,0, sin((frameCount+(i*a))*0.1)*smoothSizeOfCircle)
pop();
}
}
pop();
// circle 3
// push();
// translate(w/2,h/2);
// for(let i=0; i<n; i++) {
// for(let a=0; a<n; a++){
// push()
// translate(i*w,a*h)
// fill(209, 242, 0);
// ellipse(0,0, sin((frameCount+(i*a))*0.001)*smoothSizeOfCircle)
// pop();
// }
// }
// pop();
push();
fill(255, 60, 19);
translate(20,20);
text("Intensity: " + nfs(intensity,0,10),0,0);
pop();
}