xxxxxxxxxx
123
var mic, fft;
var bassToLowMid, lowMid, mid, highMid, highMidToTreble, treble;
var bgColor, ellipseColor, triangleColor, stripeColor, stripeColorTwo, ovalColor, lineColor;
function setup() {
createCanvas(windowWidth, windowHeight);
//set color
bgColor = color(35,10,51);
ellipseColor = color(64,30,84);
triangleColor = color(128,106,187);
stripeColor = color(122,251,250);
stripeColorTwo = color(233,66,238);
//ovalColor = color(221,252,119);
lineColor = color(251,231,252);
mic = new p5.AudioIn();
mic.start();
amp = new p5.Amplitude();
fft = new p5.FFT(0.8, 1024);
fft.setInput(mic);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
background(0);
}
function draw() {
background(bgColor);
var spectrum = fft.analyze();
micLevel = mic.getLevel();
frameRate(15);
noStroke();
bassToLowMid = fft.getEnergy("bass", "lowMid");
lowMid = fft.getEnergy("lowMid");
mid = fft.getEnergy("mid");
highMid = fft.getEnergy("highMid");
highMidToTreble = fft.getEnergy("highMid", "treble");
treble = fft.getEnergy("treble");
//ellipse
if (lowMid > 130) {
fill(ellipseColor);
ellipse(width / 2, height / 2, 400, 400)
}
//ellipse stroke
if (bassToLowMid > 140) {
stroke(stripeColor);
strokeWeight(10);
noFill();
var end = map(10, 0, 60, 0, 360);
arc(width / 2, height / 2, 500, 500, 0, end)
arc(width / 2, height / 2, 450, 450, 0, end)
arc(width / 2, height / 2, 400, 400, 0, end)
noStroke();
}
//oval
/*
if (bassToLowMid > 120 && bassToLowMid < 140) {
fill(ovalColor);
ellipse(width / 2, height / 2, 50, 400);
noStroke();
}*/
//triangle
if (mid > 60) {
stroke(triangleColor);
strokeWeight(3);
noFill();
triangle(width / 3, height / 3, width / 2, 40, 700, 700);
noStroke();
}
//line
if (mid > 35 && mid < 60) {
stroke(lineColor);
strokeWeight(2);
noFill();
line(height / 3, 40, 700, height - 20);
noStroke();
}
//three stripes
if (highMid > 50) {
fill(stripeColor);
rect(width / 4, 370, width / 2, 40);
rect(width / 4, 430, width / 2, 40);
rect(width / 4, 490, width / 2, 40);
}
//stripe
if (highMid < 50 && highMid > 30) {
fill(stripeColorTwo);
rect(width / 4, 430, width / 2, 40);
}
//amplitude ellipse
push();
if (highMidToTreble < 30 && highMidToTreble > 5) {
frameRate(30);
fill(255, 255, 255, 191);
ellipse(width / 2, height / 2, micLevel * 10000, micLevel * 10000);
}
pop();
}
//mousePressed function
function mousePressed() {
bgColor = color(random(255), random(255), random(255));
ellipseColor = color(random(255), random(255), random(255));
triangleColor = color(random(255), random(255), random(255));
stripeColor = color(random(255), random(255), random(255));
stripeColorTwo = color(random(255), random(255), random(255));
ovalColor = color(random(255), random(255), random(255));
lineColor = color(random(255), random(255), random(255));
}