xxxxxxxxxx
450
// colours
let colorBG, colorMain, colorLS, colorGDP, colorSS, colorHLE, colorFLC, colorGEN, colorPC;
let sound, fft;
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
// colorRelated
colorBG = color('rgb(235, 205, 75)');
colorMain = color('rgb(255,255,255)');
colorLS = color('rgb(250, 160, 65)');
colorGDP = color('rgb(110, 240, 155)');
colorSS = color('rgb(85, 165, 240)');
colorHLE = color('rgb(235, 120, 220)');
colorFLC = color('rgb(155, 60, 235)');
colorGEN = color('rgb(235, 105, 75)');
colorPC = color('rgb(210, 60, 65)');
// soundRelated
canvas.mousePressed(userStartAudio);
sound = new p5.AudioIn();
sound.start();
fft = new p5.FFT();
sound.connect(fft);
}
function draw() {
background(colorBG);
// audio
if(!checkAudio()) {
return;
}
fft.analyze();
let bass = fft.getEnergy("bass");
let lowMid = fft.getEnergy("lowMid");
let mid = fft.getEnergy("mid");
let highMid = fft.getEnergy("highMid");
let treble = fft.getEnergy("treble");
translate(windowWidth/2, windowHeight/2);
shapeOne(bass, mid, treble);
shapeTwo(bass, mid, treble);
shapeThree(bass, mid, treble);
shapeFour(bass, mid, treble);
shapeFive(bass, mid, treble);
shapeSix(bass, mid, treble);
shapeSeven(bass, mid, treble);
shapeEight(bass, mid, treble);
shapeNine(bass, mid, treble);
shapeTen(bass, mid, treble);
shapeEleven(bass, mid, treble);
shapeTwelve(bass, mid, treble);
shapeThirteen(bass, mid, treble);
shapeFourteen(bass, mid, treble);
}
function shapeOne(e, f, g) {
push();
let circle = 1;
let zoff = 2;
let noiseMax = e*30;
let s0 = 0.5;
let s1 = 0.5;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorLS);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), 0, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeTwo(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = f*30;
let s0 = 0.6;
let s1 = 0.6;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorGDP);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -5, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeThree(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = g*30;
let s0 = 0.7;
let s1 = 0.7;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorSS);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -10, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeFour(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = e*50;
let s0 = 0.8;
let s1 = 0.8;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorHLE);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -15, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeFive(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = f*50;
let s0 = 0.9;
let s1 = 0.9;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorFLC);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -20, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeSix(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = g*50;
let s0 = 1;
let s1 = 1;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorGEN);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -25, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeSeven(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = e*70;
let s0 = 1.1;
let s1 = 1.1;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorPC);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -30, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeEight(e, f, g) {
push();
let circle = 1;
let zoff = 2;
let noiseMax = f*70;
let s0 = 1.2;
let s1 = 1.2;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorLS);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -35, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeNine(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = g*70;
let s0 = 1.3;
let s1 = 1.3;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorGDP);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -40, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeTen(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = e*90;
let s0 = 1.4;
let s1 = 1.4;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorSS);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -45, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeEleven(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = f*90;
let s0 = 1.5;
let s1 = 1.5;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorHLE);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -50, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeTwelve(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = g*90;
let s0 = 1.6;
let s1 = 1.6;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorFLC);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -55, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeThirteen(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = e*120;
let s0 = 1.7;
let s1 = 1.7;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorGEN);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -60, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function shapeFourteen(e, f, g) {
push();
let circle = 10;
let zoff = 2;
let noiseMax = f*120;
let s0 = 1.8;
let s1 = 1.8;
rotate(frameCount * 55);
strokeWeight(5);
stroke(colorPC);
noFill();
for (let j = 0; j < 1; j++) {
beginShape();
for (let a = 0; a < TWO_PI; a+=radians(0.75)) {
let xoff = map(cos(a + circle), -5, 5, 0, noiseMax);
let yoff = map(sin(a + circle), -5, 5, 0, noiseMax);
let r = map(sin(xoff, yoff, zoff), -65, 50, 200, width/5);
let x = r * cos(a) * ((s0 + j * s1));
let y = r * sin(a) * ((s0 + j * s1));
curveVertex(x, y);
}
endShape(CLOSE);
}
pop();
}
function checkAudio() {
if (getAudioContext().state !== 'running') {
background(40);
fill(colorLS);
textAlign(CENTER);
text('Play your happy song, enable your microphone and click here for some good vibrations.', windowWidth/2, windowHeight/2);
return false;
}
return true;
}