let color1, color2;
let n, d;
let discs;
let t = 0;
let random1, random2;
function setup() {
cnv = createCanvas((m = min(600, min(windowWidth, windowHeight))), m);
n = int(random(3, 7));
random1 = int(random(3, 10));
random2 = random(-1, 1);
discs = [];
let d = (height - 200) / n;
for (let i = 0; i < n; i++) {
discs[i] = {
x: width / 2,
y: 40 + d * i,
d: random(0, 40) + (i * d) / 4 + d * sin(((random1 * PI) / n) * i)
};
}
color1 = color(random(140, 205), random(160, 245), random(200, 255), 170);
color2 = color(random(0, 55), random(0, 55), random(0, 55), 170);
noStroke();
}
function draw() {
t += 0.005;
for (let i = 0; i < 5000; i++) {
let x = random(0, width);
let y = random(0, height);
cnt = 0;
for (let j = 0; j < discs.length; j++) {
let delta = dist(x, y, discs[j].x, discs[j].y);
if (delta <= discs[j].d / 2) {
cnt = cnt + 1;
}
noStroke();
}
if (cnt % 2 === 1) {
fill(color1);
} else {
fill(color2);
}
circle(width / 5 + x, y, random(1, random1 / 4));
circle(width - width / 5 - x, height - y, random(1, random1 / 4));
if (
(x < 10 && x > 5) ||
(x < width - 5 && x > width - 10) ||
(y < 10 && y > 5) ||
(y < width - 5 && y > width - 10)
) {
push();
fill(color1);
circle(x, y, random(1, 5));
pop();
}
}
for (let i = 0; i < n; i++) {
discs[i].x =
width / 2 +
(width / 10) *
Math.sin((i * t) / random1) *
Math.cos((i * t) / (random1 * 1.5));
}
}
function mousePressed() {
setup();
draw();
}
function keyPressed() {
if (keyCode === 83) {
save(cnv, "two", "jpg");
}
}