Skip to content

Commit

Permalink
drift easing
Browse files Browse the repository at this point in the history
  • Loading branch information
hibit-at committed Feb 2, 2023
1 parent 8c42506 commit 220a6f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
43 changes: 40 additions & 3 deletions EaseUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
'InOutBack',
'InBounce',
'OutBounce',
'InOutBounce'
'InOutBounce',
'Drift',
]


Expand Down Expand Up @@ -200,13 +201,46 @@ def InOutBounce(t):
return (1 - OutBounce(1 - 2 * t)) / 2 if t < 0.5 else (1 + OutBounce(2 * t - 1)) / 2


def Drift(t, x=6, y=6):
x /= 10
y /= 10
if x == 1 and y == 1:
return t
if x > y:
hy = 0
hx = (x-y)/(1-y)
else:
hx = 0
hy = (y-x)/(1-x)
if t >= x:
return (1-t)/(1-x)*y + (t-x)/(1-x)
else:
ng = 0
ok = 1
while abs(ng-ok) > 1e-10:
mid = ng + ok
mid /= 2
criteria = 3*(1-mid)*mid*mid*hx + mid*mid*mid*x
if criteria >= t:
ok = mid
else:
ng = mid
return 3*(1-ok)*ok*ok*hy + ok*ok*ok*y


def interpolate(start, end, rate):
return start*(1-rate) + end*rate


def ease(self, dur, text, line):
def ease(self, dur, text : str, line):
u_text = text.upper()
flag = 0
dx = 6
dy = 6
if len(u_text.split('_')) > 2:
dx = float(u_text.split('_')[1])
dy = float(u_text.split('_')[2])
print(dx, dy)
if u_text != 'EASE':
if u_text[:4] == 'EASE':
u_text = u_text[4:]
Expand Down Expand Up @@ -259,7 +293,10 @@ def ease(self, dur, text, line):
new_line = Line(spans[i])
new_line.visibleDict = deepcopy(line.visibleDict)
t = sum(spans[:(i+1)])/init_dur
rate = easefunc(t)
if easefunc != Drift:
rate = easefunc(t)
else:
rate = Drift(t,dx,dy)
new_line.start = deepcopy(self.lastTransform)
endPos = Pos(
interpolate(ixp, lxp, rate),
Expand Down
1 change: 0 additions & 1 deletion Scriptmapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from cgi import print_arguments
import sys
from ScriptMapperClass import ScriptMapper

Expand Down

0 comments on commit 220a6f4

Please sign in to comment.