Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion manim/animation/updaters/mobject_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,32 @@ def updater(mob):


def always_redraw(func):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we are at it, we could probably also add a type hint for func, it should be something like Callable[[], Mobject] (with Callable from collections.abc) I guess.

"""Redraw a mobject every frame.

.. manim:: TangentAnimation

class TangentAnimation(Scene):
def construct(self):
ax = Axes()
sine = ax.plot(np.sin, color=RED)
alpha = ValueTracker(0)
point = always_redraw(
lambda: Dot(
sine.point_from_proportion(alpha.get_value()),
color=BLUE)
)
tangent = always_redraw(
lambda: TangentLine(
sine,
alpha=alpha.get_value(),
color=YELLOW,
length=4)
)
self.play(Create(ax), Create(sine), Create(point), Create(tangent))
self.play(alpha.animate.set_value(1), rate_func=linear, run_time=10)
"""
mob = func()
mob.add_updater(lambda m: mob.become(func()))
mob.add_updater(lambda _: mob.become(func()))
return mob


Expand Down