-
Notifications
You must be signed in to change notification settings - Fork 0
/
Land.pde
53 lines (44 loc) · 1.36 KB
/
Land.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import megamu.mesh.*;
int land_nPoints = 255;
class Land {
Land() {
generatePoints();
voronoiPolygons = new ArrayList<PVector[]>();
updateVoronoi();
//relaxPoints();
//relaxPoints(); // implies updateVoronoi();
}
void generatePoints() {
points = randomPoints(land_nPoints, 640, 480);
//PVector[] points = {new PVector(200, 200), new PVector(220, 200), new PVector(230, 200), new PVector(225, 225), new PVector(230, 230)};
//this.points = points;
}
void updateVoronoi() {
voronoi = new Voronoi(GeomUtils.toFloatArray(points));
for (MPolygon polygon : voronoi.getRegions()) {
//voronoiPolygons.add(GeomUtils.rectClipPolygon(GeomUtils.toVectorArray(polygon),
//0, 0, width, height));
}
}
void drawUnderlay(PGraphics g) {
for (PVector[] polygon : voronoiPolygons) {
g.stroke(0);
g.strokeWeight(1);
fill(255);
GeomUtils.drawPolygon(g, polygon);
g.strokeWeight(2);
g.stroke(0x9B, 0x14, 0x14);
PVector centroid = GeomUtils.centroid(polygon);
GeomUtils.drawPoint(g, centroid);
g.stroke(0xCE, 0x4B, 0x4B);
g.strokeWeight(3);
//g.point(centroid.x, centroid.y);
}
g.stroke(0);
g.strokeWeight(4);
GeomUtils.drawPoints(g, points);
}
PVector[] points;
Voronoi voronoi;
ArrayList<PVector[]> voronoiPolygons;
}