kopia lustrzana https://github.com/villares/sketch-a-day
voronoi for rosettacode.org
rodzic
62f08e3e49
commit
8a2b517bf1
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 4.8 KiB |
|
@ -0,0 +1,24 @@
|
|||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
generate_voronoi_diagram(width, height, 25)
|
||||
saveFrame("VoronoiDiagram.png")
|
||||
|
||||
def generate_voronoi_diagram(w, h, num_cells):
|
||||
nx, ny, nr, ng, nb = [], [], [], [], []
|
||||
for i in range(num_cells):
|
||||
nx.append(int(random(w)))
|
||||
ny.append(int(random(h)))
|
||||
nr.append(int(random(256)))
|
||||
ng.append(int(random(256)))
|
||||
nb.append(int(random(256)))
|
||||
for y in range(h):
|
||||
for x in range(w):
|
||||
dmin = dist(0, 0, w - 1, h - 1)
|
||||
j = -1
|
||||
for i in range(num_cells):
|
||||
d = dist(0, 0, nx[i] - x, ny[i] - y)
|
||||
if d < dmin:
|
||||
dmin = d
|
||||
j = i
|
||||
set(x, y, color(nr[j], ng[j], nb[j]))
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 5.5 KiB |
|
@ -0,0 +1,35 @@
|
|||
|
||||
void setup() {
|
||||
size(500, 500);
|
||||
generateVoronoiDiagram(width, height, 25);
|
||||
saveFrame("VoronoiDiagram.png");
|
||||
}
|
||||
|
||||
void generateVoronoiDiagram(int w, int h, int num_cells) {
|
||||
int nx[] = new int[num_cells];
|
||||
int ny[] = new int[num_cells];
|
||||
int nr[] = new int[num_cells];
|
||||
int ng[] = new int[num_cells];
|
||||
int nb[] = new int[num_cells];
|
||||
for (int n=0; n < num_cells; n++) {
|
||||
nx[n]=int(random(w));
|
||||
ny[n]=int(random(h));
|
||||
nr[n]=int(random(256));
|
||||
ng[n]=int(random(256));
|
||||
nb[n]=int(random(256));
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
float dmin = dist(0, 0, w - 1, h - 1);
|
||||
int j = -1;
|
||||
for (int i=0; i < num_cells; i++) {
|
||||
float d = dist(0, 0, nx[i] - x, ny[i] - y);
|
||||
if (d < dmin) {
|
||||
dmin = d;
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
set(x, y, color(nr[j], ng[j], nb[j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,12 @@ Here are listed some of the tools I have been using:
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_10_20voronoi](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_10_20voronoi) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_10_19a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_10_19a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
Ładowanie…
Reference in New Issue