-
Notifications
You must be signed in to change notification settings - Fork 0
/
delaun.pde
159 lines (141 loc) · 4.53 KB
/
delaun.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import megamu.mesh.*;
class Delaun extends visual {
int amountOfPoints = 50;
float[][] origPoints = new float[amountOfPoints][2];
float[][] points = new float[amountOfPoints][2];
float wi, he;
Delaunay myDelaunay;
Slider delaunayElements;
float noiseS = 0;
float noiseInc = 0.01;
Delaun(String id, int x, int y, float s, float f) {
super(id, x, y, s, f, true);
this.wi = x;
this.he = y;
for (int i=0; i<amountOfPoints; i++)
{
origPoints[i][0] = random(x); // first point, x
origPoints[i][1] = random(y); // first point, y
}
for (int i=0; i<5; i++)
{
t[i] = 100;
}
}
float[] getCamSettings() {
float[] settings = new float[4];
settings[0] = this.wi/2;
settings[1] = this.he/2;
settings[2] = 0;
settings[3] = 400;
return settings;
}
void show() {
background(0);
morphPoints();
updateDelaunay();
noiseS += noiseInc;
for (int i=0; i<5; i++)
{
t[i]+=0.1;
}
}
void feed(Boolean [] t) {
if (t[0]) {
this.t[0] = 0;
} else if (t[1]) {
this.t[1] = 0;
} else if (t[2]) {
this.t[2] = 0;
} else if (t[3]) {
this.t[3] = 0;
} else if (t[4]) {
this.t[4] = 0;
}
}
//GUI elements
float amp = 20;
float[] t = new float [5];
float A = -0.8;
float B = -10;
boolean randomJigger = false;
boolean radialJigger = !randomJigger;
void morphPoints() {
for (int i=0; i<amountOfPoints; i++)
{
this.points[i][0] = this.origPoints[i][0] + amp*(noise(origPoints[i][0]/amp+noiseS)-0.5);
this.points[i][1] = this.origPoints[i][1] + amp*(noise(origPoints[i][1]/amp+noiseS)-0.5); // first point, y
if (randomJigger) {
if (i<amountOfPoints/5) {
this.points[i][0] += random(-1, 1)*amp*cos(B*t[0])*exp(A*t[0]);
this.points[i][1] += random(-1, 1)*amp*cos(B*t[0])*exp(A*t[0]);
}
if (i>amountOfPoints/5) {
this.points[i][0] += random(-1, 1)*amp*cos(B*t[1])*exp(A*t[1])/3;
this.points[i][1] += random(-1, 1)*amp*cos(B*t[1])*exp(A*t[1])/3;
}
}
if (radialJigger) {
if (i<amountOfPoints/5) {
this.points[i][0] += (this.points[i][0]-this.wi/2)/amp*cos(B*t[0])*exp(A*t[0]);
this.points[i][1] += (this.points[i][1]-this.he/2)/amp*cos(B*t[0])*exp(A*t[0]);
}
if (i>amountOfPoints/5 && i<amountOfPoints*2/5) {
this.points[i][0] += (this.points[i][0]-this.wi/2)/amp*cos(B*t[1])*exp(A*t[1])/2;
this.points[i][1] += (this.points[i][1]-this.he/2)/amp*cos(B*t[1])*exp(A*t[1])/2;
}
if (i>amountOfPoints*2/5 && i<amountOfPoints*3/5) {
this.points[i][0] += (this.points[i][0]-this.wi/2)/amp*cos(B*t[1])*exp(A*t[2])/4;
this.points[i][1] += (this.points[i][1]-this.he/2)/amp*cos(B*t[1])*exp(A*t[2])/4;
}
if (i>amountOfPoints*3/5 && i<amountOfPoints*4/5) {
this.points[i][0] += (this.points[i][0]-this.wi/2)/amp*cos(B*t[1])*exp(A*t[3])/8;
this.points[i][1] += (this.points[i][1]-this.he/2)/amp*cos(B*t[1])*exp(A*t[3])/8;
}
if (i>amountOfPoints*4/5 && i<amountOfPoints) {
this.points[i][0] += (this.points[i][0]-this.wi/2)/amp*cos(B*t[1])*exp(A*t[4])/16;
this.points[i][1] += (this.points[i][1]-this.he/2)/amp*cos(B*t[1])*exp(A*t[4])/16;
}
}
}
}
void updateDelaunay() {
this.myDelaunay = new Delaunay(this.points);
float[][] myEdges = myDelaunay.getEdges();
for (int i=0; i<myEdges.length; i++)
{
float startX = myEdges[i][0];
float startY = myEdges[i][1];
float endX = myEdges[i][2];
float endY = myEdges[i][3];
stroke(map((endY-startY)*(endY-startY)+(endX-startX)*(endX-startX), 0, 4000, 255, 0), 50, 60);
strokeWeight(1);
line( startX, startY, endX, endY );
}
}
void addGui(ControlP5 cp5, int x, int y) {
delaunayElements = cp5.addSlider("elements")
.setPosition(x, y)
.setSize(80, 18)
.setRange(5, 1000)
.setValue(amountOfPoints)
;
}
void removeGui(ControlP5 cp5) {
cp5.remove("elements");
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom(delaunayElements)) {
this.amountOfPoints = int(delaunayElements.getValue());
origPoints = new float[amountOfPoints][2];
points = new float[amountOfPoints][2];
this.wi = x;
this.he = y;
for (int i=0; i<amountOfPoints; i++)
{
origPoints[i][0] = random(wi); // first point, x
origPoints[i][1] = random(he); // first point, y
}
}
}
}