xxxxxxxxxx
let sound;
let peaks;
let index = 0;
let amplitude;
let radius;
function preload() {
sound = loadSound("mixkit.mp3");
}
function setup() {
cnv = createCanvas(700, 700);
background(100);
//cnv.mouseClicked(togglePlay);
sound.amp(0.3);
sound.loop();
amplitude = new p5.Amplitude();
peaks = sound.getPeaks();
print(sound.duration());
}
function draw() {
background(0);
radius = width/2-50;
translate(width/2, height/2);
rotate (millis (3)/ 1000);
circle (50, 50, 50 );
// Peak circle
fill(100, 20, 100);
stroke(255);
beginShape();
for (i=0; i<peaks.length; i++) {
peak = map(peaks[i], 0, 1, 1, 50);
step = map(i, 0, peaks.length, 0, 2*PI);
x = (peak+radius) * cos(step);
y = (peak+radius) * sin(step);
vertex(x, y);
//radius -= 1;
}
{
translate(CENTER);
// mapping of sin over time (-1 ... +1) to -200 ... 200
// speed is defined by /1000
let s = map(sin(millis()/300), -1, 1, -100, 100);
noFill();
stroke(255);
translate(s, 0);
//ellipse(0, 0, 200, 200);
//ellipse(0, 0, 50, 50);
ellipse(0, 0, s, s);
translate(s, -s, 0);
ellipse(0, 0, s, s);
translate(s, -s, 0);
ellipse(0, 0, -s,-s);
translate(-s, 0); //umgedreht
ellipse(0, 0, -s, -s);
translate(-s, s, 0);
ellipse(0, 0, -s, -s);
//translate(-s, s, 0)
ellipse(0, 0, s, s);
}
endShape();
// Sound position
sound_angle = map(sound.currentTime(), 0, sound.duration(), 0, 2*PI);
sx = (peak+radius) * cos(sound_angle);
sy = (peak+radius) * sin(sound_angle);
ellipse(sx, sy, 10, 10);
}