document.getElementById("clickme").onclick = clickAct;
let cnv;
let c = 0;
let t;
let waveA = [];
function setup() {
cnv = createCanvas(windowWidth, 200);
angleMode(DEGREES);
}
function draw() {
t = width / 2 + (width / 2) * sin(frameCount / 20);
noStroke();
fill(200 * sin(frameCount / 3), 0, 200 * cos(frameCount / 2), 100);
for (let i = 0; i < c; i++) {
waveA[i].move();
waveA[i].display();
}
}
function clickAct() {
waveA.push(new waveMe(c));
c = c + 1;
if (c > 50) {
c = 0;
waveA = [];
setup();
}
}
class waveMe {
constructor(n) {
this.x = 0;
this.y = 100;
this.n = n;
}
move() {
this.x = t;
this.y = 100 + 70 * sin(t) * cos(this.n * t) + 10 * sin((this.n * t) / 2);
}
display() {
circle(this.x, this.y, 2);
}
}