File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
1
+
2
+ class EasingBase :
3
+ limit = (- 1 , 1 )
4
+
5
+ def __init__ (self , start = 0 , end = 1 , duration = 1 ):
6
+ self .start = start
7
+ self .end = end
8
+ self .duration = duration
9
+
10
+ @classmethod
11
+ def func (cls , t ):
12
+ raise NotImplementedError
13
+
14
+ def ease (self , alpha ):
15
+ """
16
+ Interpolate between start and end given an alpha from 0 to duration
17
+ :param alpha: 0 to duration
18
+ :return: respective value between start and end
19
+ """
20
+ t = self .limit [0 ] * (1 - alpha ) + self .limit [1 ] * alpha
21
+ t /= self .duration
22
+ a = self .func (t )
23
+ return self .end * a + self .start * (1 - a )
24
+
25
+
26
+ """
27
+ Quadratic easing functions
28
+ """
29
+
30
+
31
+ class QuadEaseInOut (EasingBase ):
32
+ limit = (- 1 , 1 )
33
+
34
+ def func (self , t ):
35
+ if t < 0 :
36
+ return (t + 1 ) ** 2 / (self .limit [1 ] - self .limit [0 ])
37
+ return - (t - 1 ) ** 2 / (self .limit [1 ] - self .limit [0 ]) + 1
38
+
39
+
40
+ class QuadEaseIn (QuadEaseInOut ):
41
+ limit = (- 1 , 0 )
42
+
43
+
44
+ class QuadEaseOut (QuadEaseInOut ):
45
+ limit = (0 , 1 )
You can’t perform that action at this time.
0 commit comments