-
Notifications
You must be signed in to change notification settings - Fork 13
/
partitionSmooth.pde
53 lines (41 loc) · 1.33 KB
/
partitionSmooth.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 processing.javafx.*;
import micycle.pgs.*;
import java.util.List;
PShape polygon;
List<PShape> subPartitions;
void setup() {
size(800, 800, FX2D);
smooth();
textAlign(LEFT, TOP);
List<PVector> randomPoints = PGS_PointSet.poisson(30, 30, width - 30, height - 30, 40);
polygon = PGS_Hull.concaveHullBFS(randomPoints, 0.1);
PShape partitions = PGS_Processing.convexPartition(polygon);
subPartitions = new ArrayList<PShape>();
for (PShape p : partitions.getChildren()) {
PShape split = PGS_Processing.split(p, 2);
subPartitions.addAll(PGS_Conversion.getChildren(split));
}
}
void draw() {
background(0, 0, 40);
fill(0, 255, 255);
text(frameRate, 2, 2); // fps
for (PShape p : subPartitions) {
PVector centroid = PGS_ShapePredicates.centroid(p);
if (centroid == null) {
continue;
}
float smooth = map(centroid.x+centroid.y, 0, width+height, 0, 01);
smooth = triangleWave(1, (smooth + frameCount*0.01) % 2);
int fill = color(triangleWave(255, frameCount), 255*centroid.x/width, 255*centroid.y/height);
p = PGS_Transformation.scale(p, 1-smooth*0.4);
p = PGS_Morphology.smooth(p, smooth);
p.setStrokeWeight(1);
p.setStroke(255);
p.setFill(fill);
shape(p);
}
}
static float triangleWave(float max, float time) {
return max - abs(time % (2 * max) - max);
}