smoothiepy 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smoothiepy
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: A library for various easing functions.
5
5
  License: MIT
6
6
  Author: Strimnik
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "smoothiepy"
3
- version = "0.0.1"
3
+ version = "0.0.2"
4
4
  description = "A library for various easing functions."
5
5
  authors = ["Strimnik"]
6
6
  license = "MIT"
@@ -0,0 +1,231 @@
1
+ import math
2
+
3
+ class EasingFunction:
4
+ def out(self, t, weight=1):
5
+ raise NotImplementedError
6
+
7
+ def in_(self, t, weight=1):
8
+ raise NotImplementedError
9
+
10
+ def in_out(self, t, weight=1):
11
+ raise NotImplementedError
12
+
13
+ def out_in(self, t, weight=1):
14
+ raise NotImplementedError
15
+
16
+ class Exponential(EasingFunction):
17
+ def in_(self, t, weight=1):
18
+ return weight * (0 if t == 0 else 2 ** (10 * (t - 1)))
19
+
20
+ def out(self, t, weight=1):
21
+ return weight * (1 if t == 1 else 1 - 2 ** (-10 * t))
22
+
23
+ def in_out(self, t, weight=1):
24
+ if t == 0 or t == 1:
25
+ return weight * t
26
+ t *= 2
27
+ if t < 1:
28
+ return weight * 0.5 * 2 ** (10 * (t - 1))
29
+ return weight * 0.5 * (2 - 2 ** (-10 * (t - 1)))
30
+
31
+ def out_in(self, t, weight=1):
32
+ if t < 0.5:
33
+ return weight * 0.5 * self.out(t * 2)
34
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
35
+
36
+ class Quad(EasingFunction):
37
+ def in_(self, t, weight=1):
38
+ return weight * (t * t)
39
+
40
+ def out(self, t, weight=1):
41
+ return weight * (1 - (1 - t) * (1 - t))
42
+
43
+ def in_out(self, t, weight=1):
44
+ return weight * ((t / 0.5) ** 2 if t < 0.5 else 1 - ((1 - t) * (1 - t)) * 0.5)
45
+
46
+ def out_in(self, t, weight=1):
47
+ return weight * (0.5 * (t / 0.5) ** 2 if t < 0.5 else 0.5 * (1 - ((1 - t) * (1 - t)) * 0.5))
48
+
49
+ class Back(EasingFunction):
50
+ def in_(self, t, weight=1):
51
+ c1 = 1.70158
52
+ c2 = c1 * 1.525
53
+ return weight * (t ** 2 * ((c2 + 1) * t - c2))
54
+
55
+ def out(self, t, weight=1):
56
+ c1 = 1.70158
57
+ c2 = c1 * 1.525
58
+ t -= 1
59
+ return weight * ((t ** 2) * ((c2 + 1) * t + c2) + 1)
60
+
61
+ def in_out(self, t, weight=1):
62
+ c1 = 1.70158
63
+ c2 = c1 * 1.525
64
+ t *= 2
65
+ if t < 1:
66
+ return weight * 0.5 * (t ** 2 * ((c2 + 1) * t - c2))
67
+ t -= 2
68
+ return weight * 0.5 * ((t ** 2 * ((c2 + 1) * t + c2)) + 2)
69
+
70
+ def out_in(self, t, weight=1):
71
+ if t < 0.5:
72
+ return weight * 0.5 * self.out(t * 2)
73
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
74
+
75
+ class Bounce(EasingFunction):
76
+ def out(self, t, weight=1):
77
+ n1 = 7.5625
78
+ d1 = 2.75
79
+ if t < 1 / d1:
80
+ return weight * n1 * t * t
81
+ elif t < 2 / d1:
82
+ t -= 1.5 / d1
83
+ return weight * n1 * (t * t + 0.75)
84
+ elif t < 2.5 / d1:
85
+ t -= 2.25 / d1
86
+ return weight * n1 * (t * t + 0.9375)
87
+ else:
88
+ t -= 2.625 / d1
89
+ return weight * n1 * (t * t + 0.984375)
90
+
91
+ def in_(self, t, weight=1):
92
+ return weight * (1 - self.out(1 - t))
93
+
94
+ def in_out(self, t, weight=1):
95
+ return weight * (0.5 * self.in_(t * 2) if t < 0.5 else 0.5 * self.out(t * 2 - 1) + 0.5)
96
+
97
+ def out_in(self, t, weight=1):
98
+ return weight * (0.5 * self.out(t * 2) if t < 0.5 else 0.5 * self.in_(t * 2 - 1) + 0.5)
99
+
100
+ class Elastic(EasingFunction):
101
+ def in_(self, t, weight=1):
102
+ if t == 0 or t == 1:
103
+ return weight * t
104
+ p = 0.3
105
+ s = p / 4
106
+ return weight * -(2 ** (10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p)
107
+
108
+ def out(self, t, weight=1):
109
+ if t == 0 or t == 1:
110
+ return weight * t
111
+ p = 0.3
112
+ s = p / 4
113
+ return weight * ((2 ** (-10 * t)) * math.sin((t - s) * (2 * math.pi) / p) + 1)
114
+
115
+ def in_out(self, t, weight=1):
116
+ if t == 0 or t == 1:
117
+ return weight * t
118
+ t *= 2
119
+ p = 0.45
120
+ s = p / 4
121
+ if t < 1:
122
+ return weight * -0.5 * (2 ** (10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p)
123
+ return weight * ((2 ** (-10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p) * 0.5 + 1)
124
+
125
+ def out_in(self, t, weight=1):
126
+ if t < 0.5:
127
+ return weight * 0.5 * self.out(t * 2)
128
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
129
+
130
+ class Sine(EasingFunction):
131
+ def in_(self, t, weight=1):
132
+ return weight * (1 - math.cos((t * math.pi) / 2))
133
+
134
+ def out(self, t, weight=1):
135
+ return weight * math.sin((t * math.pi) / 2)
136
+
137
+ def in_out(self, t, weight=1):
138
+ return weight * 0.5 * (1 - math.cos(math.pi * t))
139
+
140
+ def out_in(self, t, weight=1):
141
+ if t < 0.5:
142
+ return weight * 0.5 * self.out(t * 2)
143
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
144
+
145
+ class Circ(EasingFunction):
146
+ def in_(self, t, weight=1):
147
+ return weight * (1 - math.sqrt(1 - (t ** 2)))
148
+
149
+ def out(self, t, weight=1):
150
+ t -= 1
151
+ return weight * math.sqrt(1 - (t ** 2))
152
+
153
+ def in_out(self, t, weight=1):
154
+ t *= 2
155
+ if t < 1:
156
+ return weight * 0.5 * (1 - math.sqrt(1 - (t ** 2)))
157
+ t -= 2
158
+ return weight * 0.5 * (math.sqrt(1 - (t ** 2)) + 1)
159
+
160
+ def out_in(self, t, weight=1):
161
+ if t < 0.5:
162
+ return weight * 0.5 * self.out(t * 2)
163
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
164
+
165
+ class Cubic(EasingFunction):
166
+ def in_(self, t, weight=1):
167
+ return weight * (t ** 3)
168
+
169
+ def out(self, t, weight=1):
170
+ t -= 1
171
+ return weight * ((t ** 3) + 1)
172
+
173
+ def in_out(self, t, weight=1):
174
+ t *= 2
175
+ if t < 1:
176
+ return weight * 0.5 * (t ** 3)
177
+ t -= 2
178
+ return weight * 0.5 * ((t ** 3) + 2)
179
+
180
+ def out_in(self, t, weight=1):
181
+ if t < 0.5:
182
+ return weight * 0.5 * self.out(t * 2)
183
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
184
+
185
+ class Quart(EasingFunction):
186
+ def in_(self, t, weight=1):
187
+ return weight * (t ** 4)
188
+
189
+ def out(self, t, weight=1):
190
+ t -= 1
191
+ return weight * ((t ** 4) + 1)
192
+
193
+ def in_out(self, t, weight=1):
194
+ t *= 2
195
+ if t < 1:
196
+ return weight * 0.5 * (t ** 4)
197
+ t -= 2
198
+ return weight * 0.5 * ((t ** 4) + 2)
199
+
200
+ def out_in(self, t, weight=1):
201
+ if t < 0.5:
202
+ return weight * 0.5 * self.out(t * 2)
203
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
204
+
205
+ class Quint(EasingFunction):
206
+ def in_(self, t, weight=1):
207
+ return weight * (t ** 5)
208
+
209
+ def out(self, t, weight=1):
210
+ t -= 1
211
+ return weight * ((t ** 5) + 1)
212
+
213
+ def in_out(self, t, weight=1):
214
+ t *= 2
215
+ if t < 1:
216
+ return weight * 0.5 * (t ** 5)
217
+ t -= 2
218
+ return weight * 0.5 * ((t ** 5) + 2)
219
+
220
+ def out_in(self, t, weight=1):
221
+ if t < 0.5:
222
+ return weight * 0.5 * self.out(t * 2)
223
+ return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
224
+
225
+
226
+ def mix_easing(t, *easing_funcs_and_weights):
227
+ total_weight = sum(weight for weight, _ in easing_funcs_and_weights)
228
+ result = 0
229
+ for weight, easing_func in easing_funcs_and_weights:
230
+ result += (weight / total_weight) * easing_func(t)
231
+ return result
@@ -1,238 +0,0 @@
1
- import math
2
-
3
- class EasingFunction:
4
- def out(self, t):
5
- raise NotImplementedError
6
-
7
- def in_(self, t):
8
- raise NotImplementedError
9
-
10
- def in_out(self, t):
11
- raise NotImplementedError
12
-
13
- def out_in(self, t):
14
- raise NotImplementedError
15
-
16
- class Exponential(EasingFunction):
17
- def in_(self, t):
18
- return 0 if t == 0 else 2 ** (10 * (t - 1))
19
-
20
- def out(self, t):
21
- return 1 if t == 1 else 1 - 2 ** (-10 * t)
22
-
23
- def in_out(self, t):
24
- if t == 0 or t == 1:
25
- return t
26
- t *= 2
27
- if t < 1:
28
- return 0.5 * 2 ** (10 * (t - 1))
29
- return 0.5 * (2 - 2 ** (-10 * (t - 1)))
30
-
31
- def out_in(self, t):
32
- if t < 0.5:
33
- return 0.5 * self.out(t * 2)
34
- return 0.5 * self.in_(t * 2 - 1) + 0.5
35
-
36
- class Quad(EasingFunction):
37
- def in_(self, t):
38
- return t * t
39
-
40
- def out(self, t):
41
- return 1 - (1 - t) * (1 - t)
42
-
43
- def in_out(self, t):
44
- return (t / 0.5) ** 2 if t < 0.5 else 1 - ((1 - t) * (1 - t)) * 0.5
45
-
46
- def out_in(self, t):
47
- return 0.5 * (t / 0.5) ** 2 if t < 0.5 else 0.5 * (1 - ((1 - t) * (1 - t)) * 0.5)
48
-
49
- class Back(EasingFunction):
50
- def in_(self, t):
51
- c1 = 1.70158
52
- c2 = c1 * 1.525
53
- return (t ** 2) * ((c2 + 1) * t - c2)
54
-
55
- def out(self, t):
56
- c1 = 1.70158
57
- c2 = c1 * 1.525
58
- t -= 1
59
- return (t ** 2) * ((c2 + 1) * t + c2) + 1
60
-
61
- def in_out(self, t):
62
- c1 = 1.70158
63
- c2 = c1 * 1.525
64
- t *= 2
65
- if t < 1:
66
- return 0.5 * (t ** 2) * ((c2 + 1) * t - c2)
67
- t -= 2
68
- return 0.5 * ((t ** 2) * ((c2 + 1) * t + c2) + 2)
69
-
70
- def out_in(self, t):
71
- if t < 0.5:
72
- return 0.5 * self.out(t * 2)
73
- return 0.5 * self.in_(t * 2 - 1) + 0.5
74
-
75
- class Bounce(EasingFunction):
76
- def out(self, t):
77
- n1 = 7.5625
78
- d1 = 2.75
79
- if t < 1 / d1:
80
- return n1 * t * t
81
- elif t < 2 / d1:
82
- t -= 1.5 / d1
83
- return n1 * (t * t + 0.75)
84
- elif t < 2.5 / d1:
85
- t -= 2.25 / d1
86
- return n1 * (t * t + 0.9375)
87
- else:
88
- t -= 2.625 / d1
89
- return n1 * (t * t + 0.984375)
90
-
91
- def in_(self, t):
92
- return 1 - self.out(1 - t)
93
-
94
- def in_out(self, t):
95
- return 0.5 * self.in_(t * 2) if t < 0.5 else 0.5 * self.out(t * 2 - 1) + 0.5
96
-
97
- def out_in(self, t):
98
- return 0.5 * self.out(t * 2) if t < 0.5 else 0.5 * self.in_(t * 2 - 1) + 0.5
99
-
100
- class Elastic(EasingFunction):
101
- def in_(self, t):
102
- if t == 0 or t == 1:
103
- return t
104
- p = 0.3
105
- s = p / 4
106
- return -(2 ** (10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p)
107
-
108
- def out(self, t):
109
- if t == 0 or t == 1:
110
- return t
111
- p = 0.3
112
- s = p / 4
113
- return (2 ** (-10 * t)) * math.sin((t - s) * (2 * math.pi) / p) + 1
114
-
115
- def in_out(self, t):
116
- if t == 0 or t == 1:
117
- return t
118
- t *= 2
119
- p = 0.45
120
- s = p / 4
121
- if t < 1:
122
- return -0.5 * (2 ** (10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p)
123
- return (2 ** (-10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p) * 0.5 + 1
124
-
125
- def out_in(self, t):
126
- if t < 0.5:
127
- return 0.5 * self.out(t * 2)
128
- return 0.5 * self.in_(t * 2 - 1) + 0.5
129
-
130
- class Sine(EasingFunction):
131
- def in_(self, t):
132
- return 1 - math.cos((t * math.pi) / 2)
133
-
134
- def out(self, t):
135
- return math.sin((t * math.pi) / 2)
136
-
137
- def in_out(self, t):
138
- return 0.5 * (1 - math.cos(math.pi * t))
139
-
140
- def out_in(self, t):
141
- if t < 0.5:
142
- return 0.5 * self.out(t * 2)
143
- return 0.5 * self.in_(t * 2 - 1) + 0.5
144
-
145
- class Circ(EasingFunction):
146
- def in_(self, t):
147
- return 1 - math.sqrt(1 - (t ** 2))
148
-
149
- def out(self, t):
150
- t -= 1
151
- return math.sqrt(1 - (t ** 2))
152
-
153
- def in_out(self, t):
154
- t *= 2
155
- if t < 1:
156
- return 0.5 * (1 - math.sqrt(1 - (t ** 2)))
157
- t -= 2
158
- return 0.5 * (math.sqrt(1 - (t ** 2)) + 1)
159
-
160
- def out_in(self, t):
161
- if t < 0.5:
162
- return 0.5 * self.out(t * 2)
163
- return 0.5 * self.in_(t * 2 - 1) + 0.5
164
-
165
- class Cubic(EasingFunction):
166
- def in_(self, t):
167
- return t ** 3
168
-
169
- def out(self, t):
170
- t -= 1
171
- return (t ** 3) + 1
172
-
173
- def in_out(self, t):
174
- t *= 2
175
- if t < 1:
176
- return 0.5 * (t ** 3)
177
- t -= 2
178
- return 0.5 * ((t ** 3) + 2)
179
-
180
- def out_in(self, t):
181
- if t < 0.5:
182
- return 0.5 * self.out(t * 2)
183
- return 0.5 * self.in_(t * 2 - 1) + 0.5
184
-
185
- class Quart(EasingFunction):
186
- def in_(self, t):
187
- return t ** 4
188
-
189
- def out(self, t):
190
- t -= 1
191
- return (t ** 4) + 1
192
-
193
- def in_out(self, t):
194
- t *= 2
195
- if t < 1:
196
- return 0.5 * (t ** 4)
197
- t -= 2
198
- return 0.5 * ((t ** 4) + 2)
199
-
200
- def out_in(self, t):
201
- if t < 0.5:
202
- return 0.5 * self.out(t * 2)
203
- return 0.5 * self.in_(t * 2 - 1) + 0.5
204
-
205
- class Quint(EasingFunction):
206
- def in_(self, t):
207
- return t ** 5
208
-
209
- def out(self, t):
210
- t -= 1
211
- return (t ** 5) + 1
212
-
213
- def in_out(self, t):
214
- t *= 2
215
- if t < 1:
216
- return 0.5 * (t ** 5)
217
- t -= 2
218
- return 0.5 * ((t ** 5) + 2)
219
-
220
- def out_in(self, t):
221
- if t < 0.5:
222
- return 0.5 * self.out(t * 2)
223
- return 0.5 * self.in_(t * 2 - 1) + 0.5
224
-
225
- def get_easing_class(easing_type):
226
- easing_classes = {
227
- 'Exponential': Exponential,
228
- 'Quad': Quad,
229
- 'Back': Back,
230
- 'Bounce': Bounce,
231
- 'Elastic': Elastic,
232
- 'Sine': Sine,
233
- 'Circ': Circ,
234
- 'Cubic': Cubic,
235
- 'Quart': Quart,
236
- 'Quint': Quint,
237
- }
238
- return easing_classes.get(easing_type, lambda: EasingFunction())
File without changes