xxxxxxxxxx
137
let song;
let fft;
let amp;
let col = 0;
let particles = [];
let r;
function preload() {
song = loadSound("16 Pineapples - It's my love for u.mp3");
}
function setup() {
createCanvas(600, 900);
fft = new p5.FFT();
angleMode(DEGREES);
}
function draw() {
background(col);
stroke(255);
noFill();
rotate(60);
strokeWeight(3);
translate(0, 0);
fft.analyze();
amp = fft.getEnergy(20, 200);
var wave = fft.waveform();
beginShape();
for (let i = 0; i <= 180; i++) {
let index = floor(map(i, 0, 180, 0, wave.length - 1));
var r = map(wave[index], -1, 1, 15, 350);
let x = r * -sin(i);
let y = r * cos(i);
//stroke(255,255,255,10);
vertex(x, y);
}
endShape();
beginShape();
for (let i = 0; i <= 180; i++) {
let index = floor(map(i, 0, 180, 0, wave.length - 1));
let r = map(wave[index], -1, 1, 15, 350);
let x = r * -sin(i);
let y = r * cos(i);
vertex(x, y);
}
endShape();
beginShape();
for (let i = 0; i <= 180; i++) {
let index = floor(map(i, 0, 180, 0, wave.length - 1));
let r = map(wave[index], -1, 1, 15, 350);
let x = r * sin(i);
let y = r * cos(i);
//stroke(255,255,255,10);
vertex(x, y);
}
endShape();
// beginShape();
// for (let i = 0; i <= 180; i++) {
// let index = floor(map(i, 0, 180, 0, wave.length - 1));
// let r = map(wave[index], -1, 1, 15, 350);
// let x = r * sin(i);
// let y = r * cos(i);
// //stroke(255,255,255,50);
// vertex(x, y);
// }
// endShape();
let p = new Particle();
particles.push(p);
for (let i = 0; i < particles.length; i++) {
particles[i].update(amp > 900);
particles[i].show();
}
for (let i = 0; i < 20; i++) {
rotate(60);
beginShape();
noFill();
stroke(x2 * 60, y2, z2 + 9);
strokeWeight(1);
for (var j2 = 0; j2 < 360; j2 += 10) {
var rad2 = i * 8;
var x2 = rad2 * tan(j2);
var y2 = rad2 * -cos(j2);
var z2 = sin(frameCount * 5 + i * 5) * 60;
vertex(x2, y2, z2);
}
endShape(CLOSE);
}
}
function mouseClicked() {
if (song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
class Particle {
constructor() {
this.pos = p5.Vector.random2D().mult(190);
this.vel = createVector(0, 0);
this.acc = this.pos.copy().mult(random(0.0001, 0.00001));
this.w = random(3, 5);
}
update(cond) {
this.vel.add(this.acc);
this.pos.add(this.vel);
if (cond) {
this.pos.add(this.vel);
this.pos.add(this.vel);
this.pos.add(this.vel);
}
}
show() {
noStroke();
fill(0,0,255);
ellipse(this.pos.x, this.pos.y, this.w);
}
}