mouse to change the position of one point, hit any key (which one is the any key) to pick a new set of random points.
A fork of Voronoi Fractal Tree by Dan Anderson
xxxxxxxxxx
ArrayList<PVector> points;
float clock;
int numPoints = 20;
PVector p;
void setup() {
size(800, 800);
clock = 0;
colorMode(HSB, 255);
points = new ArrayList<PVector>();
while (points.size() < numPoints) {
float t = (6*PI*points.size())/(numPoints) + clock;
float x = (t/3)*cos(t);
float y = (t/3)*sin(t);
x = map(x, -3*PI, 3*PI, 0, width);
y = map(y, -3*PI, 3*PI, height, 0);
p = new PVector(x, y);
points.add(p);
}
}
void draw() {
p = new PVector(mouseX, mouseY);
points.add(p);
loadPixels();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int closest = 0;
float min_distance = width*height;
for (int i = 0; i < points.size(); i++) {
p = points.get(i);
float d = dist(x, y, p.x, p.y);
if (d < min_distance) {
min_distance = d;
closest = i;
}
}
float h = map(closest, 0, points.size(), 0, 255);
color c = color(h, 255, 255);
pixels[x + y*width] = c;
}
}
updatePixels();
for (int i = 0; i < points.size(); i++) {
p = points.get(i);
fill(0);
noStroke();
ellipse(p.x, p.y, 4, 4);
float t = (6*PI*i)/(numPoints) + clock;
t %= 3*TWO_PI;
float x = (t/3)*cos(t);
float y = (t/3)*sin(t);
x = map(x, -3*PI, 3*PI, 0, width);
y = map(y, -3*PI, 3*PI, height, 0);
p.x = x;
p.y = y;
points.set(i, p);
}
points.remove(points.size()-1);
if (clock < 3*TWO_PI) {
//saveFrame("./data/s#########.png");
}
clock += TWO_PI/200;
}
void keyPressed() {
setup();
}