mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Added always_shift and always_rotate
This commit is contained in:
parent
62c4967f21
commit
a73cbb8014
1 changed files with 20 additions and 0 deletions
|
@ -1,5 +1,13 @@
|
||||||
|
import inspect
|
||||||
|
from manimlib.constants import DEGREES
|
||||||
|
from manimlib.constants import RIGHT
|
||||||
|
from manimlib.mobject.mobject import Mobject
|
||||||
|
|
||||||
|
|
||||||
def always(method, *args, **kwargs):
|
def always(method, *args, **kwargs):
|
||||||
|
assert(inspect.ismethod(method))
|
||||||
mobject = method.__self__
|
mobject = method.__self__
|
||||||
|
assert(isinstance(mobject, Mobject))
|
||||||
func = method.__func__
|
func = method.__func__
|
||||||
mobject.add_updater(lambda m: func(m, *args, **kwargs))
|
mobject.add_updater(lambda m: func(m, *args, **kwargs))
|
||||||
|
|
||||||
|
@ -8,3 +16,15 @@ def always_redraw(func):
|
||||||
mob = func()
|
mob = func()
|
||||||
mob.add_updater(lambda m: mob.become(func()))
|
mob.add_updater(lambda m: mob.become(func()))
|
||||||
return mob
|
return mob
|
||||||
|
|
||||||
|
|
||||||
|
def always_shift(mobject, direction=RIGHT, rate=0.1):
|
||||||
|
mobject.add_updater(
|
||||||
|
lambda m, dt: m.shift(dt * rate * direction)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def always_rotate(mobject, rate=20 * DEGREES, **kwargs):
|
||||||
|
mobject.add_updater(
|
||||||
|
lambda m, dt: m.rotate(dt * rate, **kwargs)
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue