xxxxxxxxxx
//Harmonic Blooms
//Variables
let dir = 1;
let startAngle = 0;
let c;
let mic;
let sides = 5;
let sound;
function preload() {
sound = loadSound('Rone - Bye Bye Macadam (Official Video).mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
sound.play();
//set random color
c = color(random(255), random(255), random(255));
//start monitor input
mic = new p5.AudioIn();
mic.start();
}
function draw() {
background(0);
translate(width / 2, height / 2);
for (let i = 25; i >= 0; i--) {
//set the size of the polygon
let s = ((i+1) * height / 20)-frameCount%(31*height/20);
//if size reaches 0, become the biggest
if(s < 0)
s += 21*height/15;
//color
let tempc = lerpColor(color(255), c, s / (21*height/15));
noFill();
stroke(tempc);
strokeWeight(4);
//rotate
rotate(startAngle + PI * 0.1);
beginShape();
for (let j = 0; j <= sides; j++) {
let angle = map(j, 0, sides, 0, TWO_PI);
let x = s * cos(angle);
let y = s * sin(angle);
vertex(x, y);
}
endShape(CLOSE);
}
//rotate according to the sound
let temp = map(mic.getLevel(), 0, 1, 0, 2);
startAngle += (dir * radians(temp));
}
//user-interactive key features
function keyTyped() {
if (key == ' ') {//change the color
c = color(random(255), random(255), random(255));
}
if (key == 'd') {//change the rotate direction
dir *= -1;
}
if (key == 'p') {//change the number of sides for the polygon
switch(sides) {
case 2:
sides = 5;//Rose
break;
case 5:
sides = 12; //Ranunculus
break;
case 12:
sides = 2; //Dandelion
break;
}
}
}