walking ripples
Explanation and play here: https://www.fractalkitty.com/walking-ripples/
let circles = [];
let w, h, n, c1, c2;
let type = 0;
function setup() {
circles = [];
rand1 = int(random(5, 10));
background(255);
n = int(random(50, 200));
for (let i = 0; i <= n; i++) {
if (type === 0) {
h = windowHeight * 0.98;
w = h / 2;
cnv = createCanvas(w, h);
sd = random(w / 15, w / 4);
let f = (((i * h) / 2.5) * 2) / n / 1000;
circles[i] = {
x: (w / 12) * cos(f) * sin(f * 2),
y: -height / 2.5 + (((i * h) / 2.5) * 2) / n,
r: abs(randomGaussian(10, sd))
};
} else if (type === 1) {
h = windowHeight * 0.98;
w = h / 2;
cnv = createCanvas(w, h);
sd = random(w / 30, w / 6);
circles[i] = {
x:
(w / 12) *
cos(
(-height / 2.5 + (((i * h) / 2.5) * 2) / n) /
random([50, 100, 400, 1000])
),
y: -height / 2.5 + (((i * h) / 2.5) * 2) / n,
r: abs(randomGaussian(10, sd))
};
} else if (type === 2) {
h = windowHeight * 0.98;
w = h / 2;
cnv = createCanvas(w, h);
sd = random(w / 30, w / 6);
circles[i] = {
x: random(-w / 2.5, w / 2.5),
y: random(-h / 2.5, h / 2.5),
r: abs(randomGaussian(10, sd))
};
} else if (type === 4) {
w = min(windowHeight, windowWidth) * 0.98;
h = w;
cnv = createCanvas(w, h);
circles[i] = {
x: (w / 3) * cos((i * 6 * PI) / n),
y: (w / 3) * sin((i * 6 * PI) / n),
r: random(10, w / 3)
};
} else if (type === 5) {
w = min(windowHeight, windowWidth) * 0.98;
h = w;
cnv = createCanvas(w, h);
circles[i] = {
x: i * (w / 100) * cos((i * 6 * PI) / n),
y: i * (w / 100) * sin((i * 6 * PI) / n),
r: random(10, w / 8 + i * 4)
};
} else if (type === 6) {
w = min(windowHeight, windowWidth) * 0.98;
h = w;
cnv = createCanvas(w, h);
circles[i] = {
x: i * (w / 80) * cos((i * rand1 * PI) / n),
y: i * (w / 80) * sin((i * rand1 * PI) / n),
r: (i * i) / 2 + random(5, w / 10)
};
} else {
h = windowHeight * 0.98;
w = h / 2;
cnv = createCanvas(w, h);
sd = random(w / 15, w / 3);
circles[i] = {
x: 0,
y: -height / 2.5 + (((i * h) / 2.5) * 2) / n,
r: abs(randomGaussian(10, sd))
};
}
}
noFill();
c1 = color(255, 255, 255);
c2 = color(200, 255, 255);
}
function draw() {
translate(w / 2, h / 2);
for (let i = 0; i < 10000; i++) {
let x = random(-w / 2, w / 2);
let y = random(-h / 2, h / 2);
cCount = 0;
for (let j = 0; j < circles.length; j++) {
if (dist(circles[j].x, circles[j].y, x, y) < circles[j].r / 2) {
cCount++;
}
}
if (cCount % 2 === 1) {
stroke(
100 + 50 * sin(random(0, 2 * PI)) + 25 * cos(y / h),
200 + 50 * sin(random(0, 2 * PI)) + 25 * cos(y / (h / 3)),
220 + 50 * sin(random(0, 2 * PI)) + 25 * cos(y / h / 2)
);
point(x, y);
}
if (cCount % 2 === 0) {
stroke(
255 + 50 * sin(random(0, 2 * PI)),
255 + 50 * sin(random(0, 2 * PI)),
255 + 50 * sin(random(0, 2 * PI))
);
point(x, y);
}
}
}
function mousePressed() {}
function keyPressed() {
if (keyCode === 32) {
setup();
draw();
} else if (keyCode === 83) {
save(cnv, "drip_lines" + str(n), "jpg");
}
if (keyCode === 38) {
if (type < 7) {
type++;
setup();
draw();
} else {
type = 0;
setup();
draw();
}
}
if (keyCode === 40) {
if (type > 0) {
type--;
setup();
draw();
} else {
type = 7;
setup();
draw();
}
}
}