-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInterpolators.java
More file actions
195 lines (179 loc) · 4.59 KB
/
Interpolators.java
File metadata and controls
195 lines (179 loc) · 4.59 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
import nub.core.Graph;
import nub.core.Node;
import nub.processing.Scene;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PShape;
import processing.event.MouseEvent;
/**
* This example introduces the three different interpolations offered by the Graph.
*/
public class Interpolators extends PApplet {
Scene scene;
Node shape;
boolean recurrent = true;
//Choose P3D or P2D
String renderer = P3D;
public void settings() {
size(1920, 1080, renderer);
}
public void setup() {
//scene = new Scene(this, 150);
scene = new Scene(createGraphics(1920, 1080, P3D), 150);
scene.eye().enableHint(Node.KEYFRAMES);
PShape pshape;
if (scene.is2D()) {
rectMode(CENTER);
pshape = createShape(RECT, 0, 0, 100, 100);
}
else {
pshape = createShape(BOX, 30);
}
pshape.setFill(color(0, 255, 255/*, 125*/));
shape = new Node(pshape);
shape.setAnimationRecurrence(recurrent);
shape.setMinMaxScalingFilter(0.8f, 1.2f);
shape.setHUD(this::hud);
shape.enableHint(Node.AXES);
shape.enableHint(Node.BULLSEYE);
shape.enableHint(Node.KEYFRAMES, Node.AXES | Node.BULLSEYE, 2, color(0, 255, 0), 10);
shape.configHint(Node.BULLSEYE, color(255, 0, 0));
shape.setBullsEyeSize(50);
int count = (int) random(4, 10);
count = 10;
for (int i = 0; i < count; i++) {
//shape.addKeyFrame(scene.randomNode(), i % 2 == 1 ? 1000 : 4000);
/*
Node node = scene.randomNode();
node.enableHint(Node.BULLSEYE);
shape.addKeyFrame(node, i % 2 == 1 ? 1000 : 4000);
// */
// /*
scene.randomize(shape);
shape.addKeyFrame(Node.AXES | Node.SHAPE, i % 2 == 1 ? 1000 : 4000);
// */
}
shape.resetScalingFilter();
shape.animate();
frameRate(1000);
}
public void draw() {
/*
// WARNING: works only for onscreen scenes
background(125);
scene.render();
scene.drawAxes();
stroke(0,255,0);
scene.drawGrid();
scene.beginHUD();
hud(scene.context());
scene.endHUD();
// */
// /*
// Works for both onscreen and offscreen scenes!!!
scene.display(color(125), true, color(0, 255, 0)/*, this::sceneHUD*/);
//scene.display(color(125), true, true, this::customBox);
// */
}
public void customBox() {
PGraphics pg = scene.context();
pg.pushStyle();
// /*
pg.fill(255, 0, 0, 125);
pg.box(30);
// */
// pg.shape(box);
pg.popStyle();
}
public void sceneHUD() {
scene.beginHUD();
hud(scene.context());
scene.endHUD();
}
public void hud(PGraphics pg) {
pg.pushStyle();
pg.rectMode(CENTER);
pg.fill(255, 0, 255, 125);
pg.stroke(0,0,255);
pg.strokeWeight(3);
pg.rect(0, 0, 80, 50);
pg.popStyle();
}
public void mouseMoved() {
scene.updateTag();
}
public void mouseDragged() {
if (mouseButton == LEFT)
scene.spin();
else if (mouseButton == RIGHT)
scene.shift();
else
scene.moveForward((mouseX - pmouseX)/5);
}
public void mouseWheel(MouseEvent event) {
if (scene.is3D())
scene.moveForward(event.getCount() * 20);
else
scene.zoom(event.getCount() * 20);
}
float speed = 1;
public void keyPressed() {
if (key == 'm') {
shape.animate(-1);
}
if (key == 'n') {
recurrent = !recurrent;
shape.setAnimationRecurrence(recurrent);
}
if (key == 'q') {
shape.resetAnimation();
}
if (key == 'y') {
if (shape.isAttached())
shape.detach();
else
shape.attach();
}
if (key == 'x')
shape.removeKeyFrames();
if (key == 'c') {
println(Graph.nodes().size());
shape.removeKeyFrame(1);
println(Graph.nodes().size());
}
if (key == 't') {
shape.setAnimationTime(23250);
}
if (key == 'z') {
println(scene.fov());
println(scene.eye().worldMagnitude());
}
if (key == ' ') {
shape.toggleHint(Node.KEYFRAMES);
scene.eye().toggleHint(Node.KEYFRAMES);
}
if (key == 'r') {
shape.removeKeyFrame(3);
}
if (key == 'p') {
shape.toggleAnimation();
}
if (key == '-' || key == '+') {
shape.animate(speed += key == '+' ? 0.25f : -0.25f);
}
if (key == '1') {
scene.eye().addKeyFrame(Node.CAMERA | Node.BULLSEYE, 1000);
}
if (key == 'a')
scene.eye().toggleAnimation();
if (key == 'b')
scene.eye().removeKeyFrames();
if (key == 's')
scene.fit(1000);
if (key == 'f')
scene.fit();
}
public static void main(String[] args) {
PApplet.main(new String[]{"Interpolators"});
}
}