mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
New implementation of smooth
This commit is contained in:
parent
5ee4b94ec3
commit
ae8e8040d7
1 changed files with 12 additions and 16 deletions
|
@ -1,28 +1,25 @@
|
|||
import numpy as np
|
||||
|
||||
from manimlib.utils.bezier import bezier
|
||||
from manimlib.utils.simple_functions import sigmoid
|
||||
from manimlib.utils.simple_functions import clip
|
||||
|
||||
|
||||
def linear(t):
|
||||
return t
|
||||
|
||||
|
||||
def smooth(t, inflection=10.0):
|
||||
error = sigmoid(-inflection / 2)
|
||||
return clip(
|
||||
(sigmoid(inflection * (t - 0.5)) - error) / (1 - 2 * error),
|
||||
0, 1,
|
||||
)
|
||||
def smooth(t):
|
||||
# Zero first and second derivatives at t=0 and t=1.
|
||||
# Equivalent to bezier([0, 0, 0, 1, 1, 1])
|
||||
s = 1 - t
|
||||
return (t**3) * (10 * s * s + 5 * s * t + t * t)
|
||||
|
||||
|
||||
def rush_into(t, inflection=10.0):
|
||||
return 2 * smooth(t / 2.0, inflection)
|
||||
def rush_into(t):
|
||||
return 2 * smooth(0.5 * t)
|
||||
|
||||
|
||||
def rush_from(t, inflection=10.0):
|
||||
return 2 * smooth(t / 2.0 + 0.5, inflection) - 1
|
||||
def rush_from(t):
|
||||
return 2 * smooth(0.5 * (t + 1)) - 1
|
||||
|
||||
|
||||
def slow_into(t):
|
||||
|
@ -36,9 +33,9 @@ def double_smooth(t):
|
|||
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)
|
||||
return smooth(new_t, inflection)
|
||||
return smooth(new_t)
|
||||
|
||||
|
||||
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):
|
||||
if a == b:
|
||||
return a
|
||||
|
||||
if t < a:
|
||||
elif t < a:
|
||||
return func(0)
|
||||
elif t > b:
|
||||
return func(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue