Skip to content
Merged
Changes from 11 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
29 changes: 27 additions & 2 deletions manim/animation/updaters/mobject_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


import inspect
from collections.abc import Callable

import numpy as np

Expand Down Expand Up @@ -55,9 +56,33 @@ def updater(mob):
return mobject


def always_redraw(func):
def always_redraw(func: Callable[[], Mobject]):
"""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.add(ax, sine, point, tangent)
self.play(alpha.animate.set_value(1), rate_func=linear, run_time=2)
"""
mob = func()
mob.add_updater(lambda m: mob.become(func()))
mob.add_updater(lambda _: mob.become(func()))
return mob


Expand Down