-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.sj
54 lines (46 loc) · 1.23 KB
/
animation.sj
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
#animation(
nextFrame(time : 'i32)'bool
)
animation!t #animation (
start : 'i32
startValue : 't
end : 'i32
endValue : 't
setValue : 'heap (:t)void
nextFrame(time : 'i32)'bool {
percent := (time - start) as f32 / (end - start) as f32
if percent < 0.0f {
percent = 0.0f
} else if percent > 1.0f {
percent = 1.0f
}
// interoplate & set value
setValue(startValue.interpolate(endValue, percent))
// If after end return false
percent == 1.0f
}
) { this }
animator(
animations : list!heap #animation()
current := 0
nextFrame(time : 'i32) {
current = time
if animations.count > 0 {
// Iterate and remove all that return false
for i : 0 toReverse animations.count {
a : animations[i]
if a.nextFrame(time) {
animations.removeAt(i)
}
}
}
void
}
) { this }
animator : animator()
i32_interpolate(x : 'i32, y : 'i32, percent : 'f32) {
(x as f32 * (1.0f - percent) + y as f32 * percent) as i32
}
f32_interpolate(x : 'f32, y : 'f32, percent : 'f32) {
x * (1.0f - percent) + y * percent
}