This repository has been archived by the owner on Dec 27, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation_wave.js
74 lines (59 loc) · 2.79 KB
/
animation_wave.js
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
animation.enqueue({
easing: easing,
duration: 2000,
cuePoints: [
0, delay/duration,(delay*2)/duration, (delay*3)/duration, (delay*4)/duration, (delay*5)/duration,
//every led cuepoints is "shifted"
0.5,0.5+ delay/duration,0.5+ (delay*2)/duration,0.5+ (delay*3)/duration,0.5+ (delay*4)/duration,0.5+ (delay*5)/duration,
1
],
keyFrames: [
//led1 normal
[{value: 0}, null, null, null, null, null, //cuepoint 0
{value: 255},null, null, null, null, null, //cuepoint in the middle
{value: 0}], //cuepoint 1
//led2 shifted by delay
[{value:tweenCalc(0.5+ delay/duration ,delay/duration, 1, easing,255, 0 )}, {value: 0}, null, null, null, null, //cuepoint 0
null, {value: 255}, null, null, null, null, //cuepoint in the middle
{value: tweenCalc(0.5+ delay/duration ,delay/duration, 1, easing,255, 0 )}], //cuepoint 1
//led3 shifted by delay*2
[{value:tweenCalc(0.5+ (delay*2)/duration ,(delay*2)/duration, 1, easing,255, 0 )}, null, {value: 0},null, null, null,
null, null, {value: 255}, null, null, null,
{value:tweenCalc(0.5+ (delay*2)/duration ,(delay*2)/duration, 1, easing,255, 0 )}],
//led4 shifted by delay*3
[{value:tweenCalc(0.5+ (delay*3)/duration ,(delay*3)/duration, 1, easing,255, 0 )}, null, null, {value: 0},null, null,
null, null, null, {value: 255},null, null,
{value: tweenCalc(0.5+ (delay*3)/duration ,(delay*3)/duration, 1, easing,255, 0 )}],
//led5 shifted by delay*4
[{value:tweenCalc(0.5+ (delay*4)/duration ,(delay*4)/duration, 1, easing,255, 0 )}, null, null, null, {value: 0}, null,
null, null, null, null, {value: 255}, null,
{value:tweenCalc(0.5+ (delay*4)/duration ,(delay*4)/duration, 1, easing,255, 0 )}],
//led6 shifted by delay*5
[{value:tweenCalc(0.5+ (delay*5)/duration ,(delay*5)/duration, 1, easing,255, 0 )}, null, null, null, null, {value: 0},
null, null, null, null, null , {value: 255},
{value:tweenCalc(0.5+ (delay*5)/duration ,(delay*5)/duration, 1, easing,255, 0 )}],
],
metronomic: false,
loop: true
})
function tweencalc (startCue, endCue, nowCue, easing,left, right ) {
var tween = {
duration: null,
progress: null
};
// Find our progress for the current tween
tween.duration = (endCue - startCue)
tween.progress = (nowCue - startCue) / tween.duration;
// Catch divide by zero
/*if (!Number.isFinite(tween.progress)) {
tween.progress = this.reverse ? 0 : 1;
}*/
// Apply tween easing to tween.progress
// to do: When reverse replace inFoo with outFoo and vice versa. skip inOutFoo
tween.progress = ease[easing](tween.progress);
// Calculate this tween value
var calcValue;
calcValue = (right - left) *
tween.progress + left;
return calcValue;
};