-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTime.pde
44 lines (37 loc) · 976 Bytes
/
Time.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
class Time {
// Simulation parameters
float fps, dt, time, time_1, phase;
boolean pause = false; // Whether the simulation is paused or not
boolean reset = false; // Flag to reset the simulation
Time(int fps){
this.fps = fps;
this.dt = 1.0/fps;
frameRate(fps);
}
void update(float period){
if(!pause)
time += 1.0 / fps;
dt = time-time_1;
if(Float.isFinite(period)){
if(period==0)
println("Warning: period==0 must be prevented!");
phase += dt / period; // Increment of phase: dt / T
}
time_1 = time;
if(reset){
reset = false;
phase = 0.0;
time = 0.0;
time_1 = 0.0;
}
}
void event(ControlEvent e){
if(e.getName()=="pause") pause = !pause;
if(e.getName()=="next" || e.getName()=="prev")
if(!pause)
pause = true;
else
time += (e.getName()=="next"? 1.0 : -1.0) / fps;
if(e.getName()=="reset") reset = true;
}
}