xxxxxxxxxx
95
var mic;
function setup() {
mic = new p5.AudioIn();
mic.start();
createCanvas(990,600);
//colorMode(HSB);
background(0);
//frameRate(30);
}
function draw() {
var vol = mic.getLevel();
console.log(vol);
//fade effect
//push();
fill(10,10);
rect(0, 0, width, height);
// pop();
fill(random(0,255),random(0,255),random(0,255),random(80,100));
strokeWeight(random(0,2)); stroke(0,0,30);
push();
//noStroke();
translate(width/2,height/2);
// petals(.5,300,90);
petals(.24,vol * 800,vol*5000);
//petals(.75,300,90);
//petals(10,300,90);
pop();
smiley(140,0,0)
push();
translate(width/2-25, height/2);
rotate(frameCount / -100.0);
star(0, 0, 15, 7, 5);
pop();
push();
translate(width/2+25, height/2);
rotate(frameCount /10.0);
star(0, 0, 15, 7, 5);
pop();
}
function smiley(color,x, y) {
push();
fill(187,color,350);
translate(width/2,height/2);
//background(10);
push();
ellipse(x, y, 100, 100);
pop();
arc((x - 25), y, 20, 10, 22.5, PI + QUARTER_PI);
arc(x, (y +15), 10, 10, 50, PI + QUARTER_PI);
pop();
}
function petals(speed,long,wide){
//translate(width/2,height/2);
rotate(frameCount /speed);
ellipse(0,0,long,wide);
};
function star(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}