let playBool = true;
let crema = [];
let tmpD = 300;
let bool1 = true;
function setup() {
createCanvas(windowWidth, windowHeight);
crema.push(new Bubble(random(-50, 50), random(-50, 50)));
noStroke();
}
function draw() {
background(255);
translate(width / 2, height / 2);
if (!playBool) {
frameCount--;
}
t =
TWO_PI *
sin(frameCount / 500) *
sin(frameCount / 500) *
cos(frameCount / 500);
if (crema.length < 1000) {
pos = createVector(
random(-width / 1.2, width / 1.2),
random(-height / 1.2, height / 1.2)
);
b = inC(pos.x, pos.y);
if (bool1) {
crema.push(new Bubble(pos.x, pos.y));
}
}
for (let i = 0; i < crema.length; i++) {
push();
rotate(t + (t * 30) / crema[i].d);
crema[i].display();
pop();
}
}
class Bubble {
constructor(x, y) {
this.x = x;
this.y = y;
this.d = tmpD / 2;
this.b = random(6, 10);
this.r = random(1, 4);
}
display() {
for (let i = 0; i < 30; i++) {
fill(255 - i * this.r, 255 - i * this.r * 2, 255 - i * this.b);
circle(this.x, this.y, this.d - (this.d / 30) * i);
}
}
}
function inC(x, y) {
tmpD = random(200, 500);
bool1 = true;
for (let i = 0; i < crema.length; i++) {
if (abs(dist(x, y, crema[i].x, crema[i].y)) < crema[i].d / 2) {
bool1 = false;
} else if (bool1) {
d = 2 * (abs(dist(x, y, crema[i].x, crema[i].y)) - crema[i].d / 2);
tmpD = min(d, tmpD);
}
}
}
function mousePressed() {
playBool = !playBool;
}
function keyPressed() {
if (keyCode === 32) {
frameCount = 0;
} else {
crema = [];
setup();
draw();
}
}