xxxxxxxxxx
// Title: Worley Noise pixelated
// Author: Juan Carlos Ponce Campuzano
// https://jcponce.github.io
//
// Inspired by Daniel Shiffman
// Coding in the Cabana:
// https://thecodingtrain.com/CodingInTheCabana/004-worley-noise.html
p = [];
setup = (_) => {
createCanvas((w = 450), w);
noStroke();
for (i = 0; i < 30; i++) {
p[i] = createVector(random(w), random(w), random(w));
}
};
dists = [];
draw = (_) => {
s = round(w / 60);
for (x = 0; x <= w + s; x += s) {
for (y = 0; y <= w + s; y += s) {
for (i = 0; i < p.length; i++) {
v = p[i];
z = (w / 2) * (sin((0.5 * millis()) / 1000) + 1);
d = dist(x, y, z, v.x, v.y, v.z);
dists[i] = d;
p[i].x = p[i].x + random(-1,1) * 0.001;
p[i].y = p[i].y + random(-1,1) * 0.001;
}
o = sort(dists);
r = map(o[0], 0, 150, 10, 255);
g = map(o[1], 0, 250, 225, 10);
b = map(o[2], 0, 500, 220, 255);
fill(r, g, b);
u = createVector(x, y);
push();
translate(u.x, u.y);
rect(0, 0, s, s);
pop();
}
}
//noLoop();
};