mobject_update_utils#
Utility functions for continuous animation of mobjects.
Functions
- always_redraw(func)[source]#
Redraw the mobject constructed by a function every frame.
This function returns a mobject with an attached updater that continuously regenerates the mobject according to the specified function.
- Parameters:
func (Callable[[], Mobject]) – A function without (required) input arguments that returns a mobject.
- Return type:
Examples
Example: TangentAnimation ¶
from manim import * 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)
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)
- always_rotate(mobject, rate=0.3490658503988659, **kwargs)[source]#
A mobject which is continuously rotated at a certain rate.
- Parameters:
mobject (Mobject) – The mobject to be rotated.
rate (float) – The angle which the mobject is rotated by over one second.
kwags – Further arguments to be passed to
Mobject.rotate()
.
- Return type:
Examples
Example: SpinningTriangle ¶
from manim import * class SpinningTriangle(Scene): def construct(self): tri = Triangle().set_fill(opacity=1).set_z_index(2) sq = Square().to_edge(LEFT) # will keep spinning while there is an animation going on always_rotate(tri, rate=2*PI, about_point=ORIGIN) self.add(tri, sq) self.play(sq.animate.to_edge(RIGHT), rate_func=linear, run_time=1)
class SpinningTriangle(Scene): def construct(self): tri = Triangle().set_fill(opacity=1).set_z_index(2) sq = Square().to_edge(LEFT) # will keep spinning while there is an animation going on always_rotate(tri, rate=2*PI, about_point=ORIGIN) self.add(tri, sq) self.play(sq.animate.to_edge(RIGHT), rate_func=linear, run_time=1)
- always_shift(mobject, direction=array([1., 0., 0.]), rate=0.1)[source]#
A mobject which is continuously shifted along some direction at a certain rate.
- Parameters:
mobject (Mobject) – The mobject to shift.
direction (ndarray[float64]) – The direction to shift. The vector is normalized, the specified magnitude is not relevant.
rate (float) – Length in Manim units which the mobject travels in one second along the specified direction.
- Return type:
Examples
Example: ShiftingSquare ¶
from manim import * class ShiftingSquare(Scene): def construct(self): sq = Square().set_fill(opacity=1) tri = Triangle() VGroup(sq, tri).arrange(LEFT) # construct a square which is continuously # shifted to the right always_shift(sq, RIGHT, rate=5) self.add(sq) self.play(tri.animate.set_fill(opacity=1))
class ShiftingSquare(Scene): def construct(self): sq = Square().set_fill(opacity=1) tri = Triangle() VGroup(sq, tri).arrange(LEFT) # construct a square which is continuously # shifted to the right always_shift(sq, RIGHT, rate=5) self.add(sq) self.play(tri.animate.set_fill(opacity=1))
- f_always(method, *arg_generators, **kwargs)[source]#
More functional version of always, where instead of taking in args, it takes in functions which output the relevant arguments.
- turn_animation_into_updater(animation, cycle=False, **kwargs)[source]#
Add an updater to the animation’s mobject which applies the interpolation and update functions of the animation
If cycle is True, this repeats over and over. Otherwise, the updater will be popped upon completion
Examples
Example: WelcomeToManim ¶
from manim import * class WelcomeToManim(Scene): def construct(self): words = Text("Welcome to") banner = ManimBanner().scale(0.5) VGroup(words, banner).arrange(DOWN) turn_animation_into_updater(Write(words, run_time=0.9)) self.add(words) self.wait(0.5) self.play(banner.expand(), run_time=0.5)
class WelcomeToManim(Scene): def construct(self): words = Text("Welcome to") banner = ManimBanner().scale(0.5) VGroup(words, banner).arrange(DOWN) turn_animation_into_updater(Write(words, run_time=0.9)) self.add(words) self.wait(0.5) self.play(banner.expand(), run_time=0.5)