smoothiepy 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
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.
- smoothiepy/easing_functions.py +114 -121
- {smoothiepy-0.0.1.dist-info → smoothiepy-0.0.2.dist-info}/METADATA +1 -1
- smoothiepy-0.0.2.dist-info/RECORD +6 -0
- smoothiepy-0.0.1.dist-info/RECORD +0 -6
- {smoothiepy-0.0.1.dist-info → smoothiepy-0.0.2.dist-info}/LICENSE +0 -0
- {smoothiepy-0.0.1.dist-info → smoothiepy-0.0.2.dist-info}/WHEEL +0 -0
smoothiepy/easing_functions.py
CHANGED
@@ -1,238 +1,231 @@
|
|
1
1
|
import math
|
2
2
|
|
3
3
|
class EasingFunction:
|
4
|
-
def out(self, t):
|
4
|
+
def out(self, t, weight=1):
|
5
5
|
raise NotImplementedError
|
6
6
|
|
7
|
-
def in_(self, t):
|
7
|
+
def in_(self, t, weight=1):
|
8
8
|
raise NotImplementedError
|
9
9
|
|
10
|
-
def in_out(self, t):
|
10
|
+
def in_out(self, t, weight=1):
|
11
11
|
raise NotImplementedError
|
12
12
|
|
13
|
-
def out_in(self, t):
|
13
|
+
def out_in(self, t, weight=1):
|
14
14
|
raise NotImplementedError
|
15
15
|
|
16
16
|
class Exponential(EasingFunction):
|
17
|
-
def in_(self, t):
|
18
|
-
return 0 if t == 0 else 2 ** (10 * (t - 1))
|
17
|
+
def in_(self, t, weight=1):
|
18
|
+
return weight * (0 if t == 0 else 2 ** (10 * (t - 1)))
|
19
19
|
|
20
|
-
def out(self, t):
|
21
|
-
return 1 if t == 1 else 1 - 2 ** (-10 * t)
|
20
|
+
def out(self, t, weight=1):
|
21
|
+
return weight * (1 if t == 1 else 1 - 2 ** (-10 * t))
|
22
22
|
|
23
|
-
def in_out(self, t):
|
23
|
+
def in_out(self, t, weight=1):
|
24
24
|
if t == 0 or t == 1:
|
25
|
-
return t
|
25
|
+
return weight * t
|
26
26
|
t *= 2
|
27
27
|
if t < 1:
|
28
|
-
return 0.5 * 2 ** (10 * (t - 1))
|
29
|
-
return 0.5 * (2 - 2 ** (-10 * (t - 1)))
|
28
|
+
return weight * 0.5 * 2 ** (10 * (t - 1))
|
29
|
+
return weight * 0.5 * (2 - 2 ** (-10 * (t - 1)))
|
30
30
|
|
31
|
-
def out_in(self, t):
|
31
|
+
def out_in(self, t, weight=1):
|
32
32
|
if t < 0.5:
|
33
|
-
return 0.5 * self.out(t * 2)
|
34
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
33
|
+
return weight * 0.5 * self.out(t * 2)
|
34
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
35
35
|
|
36
36
|
class Quad(EasingFunction):
|
37
|
-
def in_(self, t):
|
38
|
-
return t * t
|
37
|
+
def in_(self, t, weight=1):
|
38
|
+
return weight * (t * t)
|
39
39
|
|
40
|
-
def out(self, t):
|
41
|
-
return 1 - (1 - t) * (1 - t)
|
40
|
+
def out(self, t, weight=1):
|
41
|
+
return weight * (1 - (1 - t) * (1 - t))
|
42
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
|
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
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)
|
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
48
|
|
49
49
|
class Back(EasingFunction):
|
50
|
-
def in_(self, t):
|
50
|
+
def in_(self, t, weight=1):
|
51
51
|
c1 = 1.70158
|
52
52
|
c2 = c1 * 1.525
|
53
|
-
return (t ** 2
|
53
|
+
return weight * (t ** 2 * ((c2 + 1) * t - c2))
|
54
54
|
|
55
|
-
def out(self, t):
|
55
|
+
def out(self, t, weight=1):
|
56
56
|
c1 = 1.70158
|
57
57
|
c2 = c1 * 1.525
|
58
58
|
t -= 1
|
59
|
-
return (t ** 2) * ((c2 + 1) * t + c2) + 1
|
59
|
+
return weight * ((t ** 2) * ((c2 + 1) * t + c2) + 1)
|
60
60
|
|
61
|
-
def in_out(self, t):
|
61
|
+
def in_out(self, t, weight=1):
|
62
62
|
c1 = 1.70158
|
63
63
|
c2 = c1 * 1.525
|
64
64
|
t *= 2
|
65
65
|
if t < 1:
|
66
|
-
return 0.5 * (t ** 2
|
66
|
+
return weight * 0.5 * (t ** 2 * ((c2 + 1) * t - c2))
|
67
67
|
t -= 2
|
68
|
-
return 0.5 * ((t ** 2
|
68
|
+
return weight * 0.5 * ((t ** 2 * ((c2 + 1) * t + c2)) + 2)
|
69
69
|
|
70
|
-
def out_in(self, t):
|
70
|
+
def out_in(self, t, weight=1):
|
71
71
|
if t < 0.5:
|
72
|
-
return 0.5 * self.out(t * 2)
|
73
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
72
|
+
return weight * 0.5 * self.out(t * 2)
|
73
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
74
74
|
|
75
75
|
class Bounce(EasingFunction):
|
76
|
-
def out(self, t):
|
76
|
+
def out(self, t, weight=1):
|
77
77
|
n1 = 7.5625
|
78
78
|
d1 = 2.75
|
79
79
|
if t < 1 / d1:
|
80
|
-
return n1 * t * t
|
80
|
+
return weight * n1 * t * t
|
81
81
|
elif t < 2 / d1:
|
82
82
|
t -= 1.5 / d1
|
83
|
-
return n1 * (t * t + 0.75)
|
83
|
+
return weight * n1 * (t * t + 0.75)
|
84
84
|
elif t < 2.5 / d1:
|
85
85
|
t -= 2.25 / d1
|
86
|
-
return n1 * (t * t + 0.9375)
|
86
|
+
return weight * n1 * (t * t + 0.9375)
|
87
87
|
else:
|
88
88
|
t -= 2.625 / d1
|
89
|
-
return n1 * (t * t + 0.984375)
|
89
|
+
return weight * n1 * (t * t + 0.984375)
|
90
90
|
|
91
|
-
def in_(self, t):
|
92
|
-
return 1 - self.out(1 - t)
|
91
|
+
def in_(self, t, weight=1):
|
92
|
+
return weight * (1 - self.out(1 - t))
|
93
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
|
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
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
|
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
99
|
|
100
100
|
class Elastic(EasingFunction):
|
101
|
-
def in_(self, t):
|
101
|
+
def in_(self, t, weight=1):
|
102
102
|
if t == 0 or t == 1:
|
103
|
-
return t
|
103
|
+
return weight * t
|
104
104
|
p = 0.3
|
105
105
|
s = p / 4
|
106
|
-
return -(2 ** (10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p)
|
106
|
+
return weight * -(2 ** (10 * (t - 1))) * math.sin((t - s) * (2 * math.pi) / p)
|
107
107
|
|
108
|
-
def out(self, t):
|
108
|
+
def out(self, t, weight=1):
|
109
109
|
if t == 0 or t == 1:
|
110
|
-
return t
|
110
|
+
return weight * t
|
111
111
|
p = 0.3
|
112
112
|
s = p / 4
|
113
|
-
return (2 ** (-10 * t)) * math.sin((t - s) * (2 * math.pi) / p) + 1
|
113
|
+
return weight * ((2 ** (-10 * t)) * math.sin((t - s) * (2 * math.pi) / p) + 1)
|
114
114
|
|
115
|
-
def in_out(self, t):
|
115
|
+
def in_out(self, t, weight=1):
|
116
116
|
if t == 0 or t == 1:
|
117
|
-
return t
|
117
|
+
return weight * t
|
118
118
|
t *= 2
|
119
119
|
p = 0.45
|
120
120
|
s = p / 4
|
121
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
|
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
124
|
|
125
|
-
def out_in(self, t):
|
125
|
+
def out_in(self, t, weight=1):
|
126
126
|
if t < 0.5:
|
127
|
-
return 0.5 * self.out(t * 2)
|
128
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
127
|
+
return weight * 0.5 * self.out(t * 2)
|
128
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
129
129
|
|
130
130
|
class Sine(EasingFunction):
|
131
|
-
def in_(self, t):
|
132
|
-
return 1 - math.cos((t * math.pi) / 2)
|
131
|
+
def in_(self, t, weight=1):
|
132
|
+
return weight * (1 - math.cos((t * math.pi) / 2))
|
133
133
|
|
134
|
-
def out(self, t):
|
135
|
-
return math.sin((t * math.pi) / 2)
|
134
|
+
def out(self, t, weight=1):
|
135
|
+
return weight * math.sin((t * math.pi) / 2)
|
136
136
|
|
137
|
-
def in_out(self, t):
|
138
|
-
return 0.5 * (1 - math.cos(math.pi * t))
|
137
|
+
def in_out(self, t, weight=1):
|
138
|
+
return weight * 0.5 * (1 - math.cos(math.pi * t))
|
139
139
|
|
140
|
-
def out_in(self, t):
|
140
|
+
def out_in(self, t, weight=1):
|
141
141
|
if t < 0.5:
|
142
|
-
return 0.5 * self.out(t * 2)
|
143
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
142
|
+
return weight * 0.5 * self.out(t * 2)
|
143
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
144
144
|
|
145
145
|
class Circ(EasingFunction):
|
146
|
-
def in_(self, t):
|
147
|
-
return 1 - math.sqrt(1 - (t ** 2))
|
146
|
+
def in_(self, t, weight=1):
|
147
|
+
return weight * (1 - math.sqrt(1 - (t ** 2)))
|
148
148
|
|
149
|
-
def out(self, t):
|
149
|
+
def out(self, t, weight=1):
|
150
150
|
t -= 1
|
151
|
-
return math.sqrt(1 - (t ** 2))
|
151
|
+
return weight * math.sqrt(1 - (t ** 2))
|
152
152
|
|
153
|
-
def in_out(self, t):
|
153
|
+
def in_out(self, t, weight=1):
|
154
154
|
t *= 2
|
155
155
|
if t < 1:
|
156
|
-
return 0.5 * (1 - math.sqrt(1 - (t ** 2)))
|
156
|
+
return weight * 0.5 * (1 - math.sqrt(1 - (t ** 2)))
|
157
157
|
t -= 2
|
158
|
-
return 0.5 * (math.sqrt(1 - (t ** 2)) + 1)
|
158
|
+
return weight * 0.5 * (math.sqrt(1 - (t ** 2)) + 1)
|
159
159
|
|
160
|
-
def out_in(self, t):
|
160
|
+
def out_in(self, t, weight=1):
|
161
161
|
if t < 0.5:
|
162
|
-
return 0.5 * self.out(t * 2)
|
163
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
162
|
+
return weight * 0.5 * self.out(t * 2)
|
163
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
164
164
|
|
165
165
|
class Cubic(EasingFunction):
|
166
|
-
def in_(self, t):
|
167
|
-
return t ** 3
|
166
|
+
def in_(self, t, weight=1):
|
167
|
+
return weight * (t ** 3)
|
168
168
|
|
169
|
-
def out(self, t):
|
169
|
+
def out(self, t, weight=1):
|
170
170
|
t -= 1
|
171
|
-
return (t ** 3) + 1
|
171
|
+
return weight * ((t ** 3) + 1)
|
172
172
|
|
173
|
-
def in_out(self, t):
|
173
|
+
def in_out(self, t, weight=1):
|
174
174
|
t *= 2
|
175
175
|
if t < 1:
|
176
|
-
return 0.5 * (t ** 3)
|
176
|
+
return weight * 0.5 * (t ** 3)
|
177
177
|
t -= 2
|
178
|
-
return 0.5 * ((t ** 3) + 2)
|
178
|
+
return weight * 0.5 * ((t ** 3) + 2)
|
179
179
|
|
180
|
-
def out_in(self, t):
|
180
|
+
def out_in(self, t, weight=1):
|
181
181
|
if t < 0.5:
|
182
|
-
return 0.5 * self.out(t * 2)
|
183
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
182
|
+
return weight * 0.5 * self.out(t * 2)
|
183
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
184
184
|
|
185
185
|
class Quart(EasingFunction):
|
186
|
-
def in_(self, t):
|
187
|
-
return t ** 4
|
186
|
+
def in_(self, t, weight=1):
|
187
|
+
return weight * (t ** 4)
|
188
188
|
|
189
|
-
def out(self, t):
|
189
|
+
def out(self, t, weight=1):
|
190
190
|
t -= 1
|
191
|
-
return (t ** 4) + 1
|
191
|
+
return weight * ((t ** 4) + 1)
|
192
192
|
|
193
|
-
def in_out(self, t):
|
193
|
+
def in_out(self, t, weight=1):
|
194
194
|
t *= 2
|
195
195
|
if t < 1:
|
196
|
-
return 0.5 * (t ** 4)
|
196
|
+
return weight * 0.5 * (t ** 4)
|
197
197
|
t -= 2
|
198
|
-
return 0.5 * ((t ** 4) + 2)
|
198
|
+
return weight * 0.5 * ((t ** 4) + 2)
|
199
199
|
|
200
|
-
def out_in(self, t):
|
200
|
+
def out_in(self, t, weight=1):
|
201
201
|
if t < 0.5:
|
202
|
-
return 0.5 * self.out(t * 2)
|
203
|
-
return 0.5 * self.in_(t * 2 - 1) + 0.5
|
202
|
+
return weight * 0.5 * self.out(t * 2)
|
203
|
+
return weight * (0.5 * self.in_(t * 2 - 1) + 0.5)
|
204
204
|
|
205
205
|
class Quint(EasingFunction):
|
206
|
-
def in_(self, t):
|
207
|
-
return t ** 5
|
206
|
+
def in_(self, t, weight=1):
|
207
|
+
return weight * (t ** 5)
|
208
208
|
|
209
|
-
def out(self, t):
|
209
|
+
def out(self, t, weight=1):
|
210
210
|
t -= 1
|
211
|
-
return (t ** 5) + 1
|
211
|
+
return weight * ((t ** 5) + 1)
|
212
212
|
|
213
|
-
def in_out(self, t):
|
213
|
+
def in_out(self, t, weight=1):
|
214
214
|
t *= 2
|
215
215
|
if t < 1:
|
216
|
-
return 0.5 * (t ** 5)
|
216
|
+
return weight * 0.5 * (t ** 5)
|
217
217
|
t -= 2
|
218
|
-
return 0.5 * ((t ** 5) + 2)
|
218
|
+
return weight * 0.5 * ((t ** 5) + 2)
|
219
219
|
|
220
|
-
def out_in(self, t):
|
220
|
+
def out_in(self, t, weight=1):
|
221
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
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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())
|
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
|
@@ -0,0 +1,6 @@
|
|
1
|
+
smoothiepy/__init__.py,sha256=t5OxxXYztyxrMV_xWan3GqQTtOQbzZHlUYrxa8rcAeg,48
|
2
|
+
smoothiepy/easing_functions.py,sha256=Y-IOjw9XNSSExkmiB9hIZWuKmMzedPtgJqlHHWclDLY,6992
|
3
|
+
smoothiepy-0.0.2.dist-info/LICENSE,sha256=g_THpn4YFNVZxdi4DZy1h-Jwpd-2EaKYVomsGeoWkMY,1084
|
4
|
+
smoothiepy-0.0.2.dist-info/METADATA,sha256=jOOx8BXRivBni0_Rd93N7f0HahPPHGVEHa9uUzkEdpU,608
|
5
|
+
smoothiepy-0.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
6
|
+
smoothiepy-0.0.2.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
smoothiepy/__init__.py,sha256=t5OxxXYztyxrMV_xWan3GqQTtOQbzZHlUYrxa8rcAeg,48
|
2
|
-
smoothiepy/easing_functions.py,sha256=cYhM9kVIYu0n8KkmkS9LeSSNWDv0u71p3msPbvs2iwA,6059
|
3
|
-
smoothiepy-0.0.1.dist-info/LICENSE,sha256=g_THpn4YFNVZxdi4DZy1h-Jwpd-2EaKYVomsGeoWkMY,1084
|
4
|
-
smoothiepy-0.0.1.dist-info/METADATA,sha256=5JCpHo0BfOu_juYghDcG9s1_ASzQ5GJiJ02uf7WkCTQ,608
|
5
|
-
smoothiepy-0.0.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
6
|
-
smoothiepy-0.0.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|