-
Notifications
You must be signed in to change notification settings - Fork 233
/
transition.ts
48 lines (43 loc) · 1.22 KB
/
transition.ts
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
export
class Transition {
time_start: number;
duration: any;
cancelled: boolean;
called_on_done: boolean;
on_done: any;
animation_exponent: number;
on_animation: any;
constructor(on_animation, on_done, duration, animation_exponent= 1) {
this.on_done = on_done;
this.on_animation = on_animation;
this.animation_exponent = animation_exponent;
this.duration = duration;
// this.objects = []
this.time_start = (new Date()).getTime();
this.cancelled = false;
this.called_on_done = false;
}
// set(obj) {
// this.objects.push(obj);
// }
is_done() {
const dt = (new Date()).getTime() - this.time_start;
return (dt >= this.duration) || this.cancelled;
}
cancel() {
this.cancelled = true;
}
update() {
if (this.cancelled) {
return;
}
const dt = ((new Date()).getTime() - this.time_start) / this.duration;
let u = Math.min(1, dt);
u = Math.pow(u, this.animation_exponent);
this.on_animation(u);
if (dt >= 1 && !this.called_on_done) {
this.called_on_done = true;
this.on_done();
}
}
}