mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 12:32:36 +08:00
New implementation of smooth
This commit is contained in:
@ -1,28 +1,25 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from manimlib.utils.bezier import bezier
|
from manimlib.utils.bezier import bezier
|
||||||
from manimlib.utils.simple_functions import sigmoid
|
|
||||||
from manimlib.utils.simple_functions import clip
|
|
||||||
|
|
||||||
|
|
||||||
def linear(t):
|
def linear(t):
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
def smooth(t, inflection=10.0):
|
def smooth(t):
|
||||||
error = sigmoid(-inflection / 2)
|
# Zero first and second derivatives at t=0 and t=1.
|
||||||
return clip(
|
# Equivalent to bezier([0, 0, 0, 1, 1, 1])
|
||||||
(sigmoid(inflection * (t - 0.5)) - error) / (1 - 2 * error),
|
s = 1 - t
|
||||||
0, 1,
|
return (t**3) * (10 * s * s + 5 * s * t + t * t)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def rush_into(t, inflection=10.0):
|
def rush_into(t):
|
||||||
return 2 * smooth(t / 2.0, inflection)
|
return 2 * smooth(0.5 * t)
|
||||||
|
|
||||||
|
|
||||||
def rush_from(t, inflection=10.0):
|
def rush_from(t):
|
||||||
return 2 * smooth(t / 2.0 + 0.5, inflection) - 1
|
return 2 * smooth(0.5 * (t + 1)) - 1
|
||||||
|
|
||||||
|
|
||||||
def slow_into(t):
|
def slow_into(t):
|
||||||
@ -36,9 +33,9 @@ def double_smooth(t):
|
|||||||
return 0.5 * (1 + smooth(2 * t - 1))
|
return 0.5 * (1 + smooth(2 * t - 1))
|
||||||
|
|
||||||
|
|
||||||
def there_and_back(t, inflection=10.0):
|
def there_and_back(t):
|
||||||
new_t = 2 * t if t < 0.5 else 2 * (1 - t)
|
new_t = 2 * t if t < 0.5 else 2 * (1 - t)
|
||||||
return smooth(new_t, inflection)
|
return smooth(new_t)
|
||||||
|
|
||||||
|
|
||||||
def there_and_back_with_pause(t, pause_ratio=1. / 3):
|
def there_and_back_with_pause(t, pause_ratio=1. / 3):
|
||||||
@ -69,8 +66,7 @@ def squish_rate_func(func, a=0.4, b=0.6):
|
|||||||
def result(t):
|
def result(t):
|
||||||
if a == b:
|
if a == b:
|
||||||
return a
|
return a
|
||||||
|
elif t < a:
|
||||||
if t < a:
|
|
||||||
return func(0)
|
return func(0)
|
||||||
elif t > b:
|
elif t > b:
|
||||||
return func(1)
|
return func(1)
|
||||||
|
Reference in New Issue
Block a user