Código Java (voronoi.java):
package voronoi;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Random;
public class Voronoi extends javax.swing.JFrame {
BufferedImage imagen;
int px[], py[], color[], zonas = 21, size = 350;
public Voronoi() {
super("Diagrama de Voronoi");
setBounds(0, 0, size, size);
setDefaultCloseOperation(EXIT_ON_CLOSE);
imagen = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
px = new int[zonas];
py = new int[zonas];
color = new int[zonas];
Random rand = new Random();
for (int i = 0; i < zonas; i++) {
px[i] = rand.nextInt(size);
py[i] = rand.nextInt(size);
color[i] = rand.nextInt(16777215);
}
int n;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
n = 0;
for (int i = 0; i < zonas; i++) {
if (distance(px[i], x, py[i], y) < distance(px[n], x, py[n], y)) {
n = i;
}
}
imagen.setRGB(x, y, color[n]);
}
}
}
@Override
public void paint(Graphics g) {
g.drawImage(imagen, 0, 0, this);
}
double distance(int x1, int x2, int y1, int y2) {
double d;
d = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
return d;
}
public static void main(String[] args) {
new Voronoi().setVisible(true);
}
}
Resultado: