-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDEMO_IterableFunction.pde
More file actions
201 lines (180 loc) · 5.12 KB
/
Copy pathDEMO_IterableFunction.pde
File metadata and controls
201 lines (180 loc) · 5.12 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
class IterableFunctionDemo extends Demo{
final ComplexBinaryFunction[] FUNCTIONS= {new MandelbrotIterable(),
new CubelbrotIterable(),
new BurningShipIterable(),
new MobiusIterable(),
new TrigIterable(),
new HyperbolicIterable(),
new ExponentialIterable()};
ComplexBinaryFunction activeFunction = FUNCTIONS[0];
final float shapeStrokeWeight = 0.4;
FourFunctionSurface plot;//currently selected shape
boolean drawLines = true;
boolean drawFaces = true;
IterableFunctionDemo(PApplet _parent){
super(_parent);
}
void demoSetup(){
hint(ENABLE_STROKE_PERSPECTIVE);
hint(ENABLE_DEPTH_SORT);
initialiseRotors();
initialiseCamera();
menu = createFunctionListMenu(this,FUNCTIONS,18);
updateProjString();
menuAction(0);
}
void demoDraw(){
background(0);
rigLights();
drawSetting();
applyUserRotation();
showShape();
drawHUD();
if(recording){saveFrame("frames/FourDimensions#######.png");}
}
void demoKeyPressed(char key){
if (key == TAB){
showMenu = !showMenu;
} else if (key==' ') { //Iterate Function
iterateFunction();
} else if (key=='o') { //Orthographic Projection
projection = (projection+1)%4;
updateProjString();
} else if (key=='O') { //Orthographic Projection
projection = (projection-1 + 4)%4;
updateProjString();
} else if (key=='p') { //Perspective Projection
projection = -1;
updateProjString();
} else if (key=='-') { //Lower 4D focal length
focalLength = max(focalLength/1.418,0);
updateProjString();
} else if (key=='=') { //Raise 4D focal length
focalLength *= 1.418;
updateProjString();
} else if (key=='v') { //toggle recording
recording = !recording;
} else if (key=='x') { //toggle guides
showGuides = !showGuides;
} else if (key=='#'){ //rotate camera or shape
camRotate=!camRotate;
} else if (key=='[') { //draw shape lines
drawLines = !drawLines;
} else if (key==']') { //draw shape faces
drawFaces = !drawFaces;
} else if (key=='q') { // Rotation keys
XY = -1;
} else if (key=='w') {
YZ = 1;
} else if (key=='e') {
XY = 1;
} else if (key=='a') {
XZ = -1;
} else if (key=='s') {
YZ = -1;
} else if (key=='d') {
XZ = 1;
} else if (key=='r') {
ZW = -1;
} else if (key=='t') {
YW = 1;
} else if (key=='y') {
ZW = 1;
} else if (key=='f') {
XW = -1;
} else if (key=='g') {
YW = -1;
} else if (key=='h') {
XW = 1;
}
}
void demoKeyReleased(char key){
if (key=='q') { //necessary to cancel rotations and have multiple rotations at once possible
XY = 0;
} else if (key=='w') {
YZ = 0;
} else if (key=='e') {
XY = 0;
} else if (key=='a') {
XZ = 0;
} else if (key=='s') {
YZ = 0;
} else if (key=='d') {
XZ = 0;
} else if (key=='r') {
ZW = 0;
} else if (key=='t') {
YW = 0;
} else if (key=='y') {
ZW = 0;
} else if (key=='f') {
XW = 0;
} else if (key=='g') {
YW = 0;
} else if (key=='h') {
XW = 0;
}
}
void applyUserRotation(){
//applies rotation from 4D camera movements to the shape
if (XY == -1) {
plot.applyMatrix(negrotorXY, camRotate);
}
if (XY == 1) {
plot.applyMatrix(rotorXY, camRotate);
}
if (XZ == -1) {
plot.applyMatrix(negrotorXZ, camRotate);
}
if (XZ == 1) {
plot.applyMatrix(rotorXZ, camRotate);
}
if (YZ == -1) {
plot.applyMatrix(negrotorYZ, camRotate);
}
if (YZ == 1) {
plot.applyMatrix(rotorYZ, camRotate);
}
if (XW == -1) {
plot.applyMatrix(negrotorXW, camRotate);
}
if (XW == 1) {
plot.applyMatrix(rotorXW, camRotate);
}
if (YW == -1) {
plot.applyMatrix(negrotorYW, camRotate);
}
if (YW == 1) {
plot.applyMatrix(rotorYW, camRotate);
}
if (ZW == -1) {
plot.applyMatrix(negrotorZW, camRotate);
}
if (ZW == 1) {
plot.applyMatrix(rotorZW, camRotate);
}
}
void showShape() {
//draws the displayed shape to the 3D world.
strokeWeight(shapeStrokeWeight);
if (projection==-1) {
plot.shape.persp(focalLength, drawLines, drawFaces);
} else {
plot.shape.ortho(projection, drawLines, drawFaces);
}
}
void iterateFunction(){
plot.iterateFunction(activeFunction);
plot.generateSheet(true);
}
void menuAction(int i){
//changes the currently selected shape
final double[] xBounds = {-2d,2d};
final double[] yBounds = {-2d,2d};
activeFunction = FUNCTIONS[i];
hudLine1 = FUNCTIONS[i].name();
plot = new FourFunctionSurface(new FourVector(0,0,0,10),xBounds,311,yBounds,311);
plot.applyFunction(activeFunction);
iterateFunction();
}
}