manim.mobject.value_tracker.ValueTracker

class ValueTracker(value=0, **kwargs)[source]

Bases: manim.mobject.mobject.Mobject

A mobject that can be used for tracking (real-valued) parameters. Useful for animating parameter changes.

Not meant to be displayed. Instead the position encodes some number, often one which another animation or continual_animation uses for its update function, and by treating it as a mobject it can still be animated and manipulated just like anything else.

Examples

Example: ValueTrackerExample

from manim import *

class ValueTrackerExample(Scene):
    def construct(self):
        number_line = NumberLine()
        pointer = Vector(DOWN)
        label = MathTex("x").add_updater(lambda m: m.next_to(pointer, UP))

        pointer_tracker = ValueTracker(0)
        pointer.add_updater(
            lambda m: m.next_to(
                        number_line.n2p(pointer_tracker.get_value()),
                        UP
                    )
        )
        self.add(number_line, pointer,label)
        pointer_tracker += 1.5
        self.wait(1)
        pointer_tracker -= 4
        self.wait(0.5)
        self.play(pointer_tracker.animate.set_value(5)),
        self.wait(0.5)
        self.play(pointer_tracker.animate.set_value(3))
        self.play(pointer_tracker.animate.increment_value(-2))
        self.wait(0.5)

Note

You can also link ValueTrackers to updaters. In this case, you have to make sure that the ValueTracker is added to the scene by add

Example: ValueTrackerExample

from manim import *

class ValueTrackerExample(Scene):
    def construct(self):
        pointer_tracker = ValueTracker(0)
        label = Dot(radius=3).add_updater(lambda x : x.set_x(pointer_tracker.get_value()))
        self.add(label)
        self.add(pointer_tracker)
        pointer_tracker.add_updater(lambda mobject, dt: mobject.increment_value(dt))
        self.wait(2)

Methods

get_value

Get the current value of the ValueTracker.

increment_value

Increments (adds) a scalar value to the ValueTracker

interpolate

Turns self into an interpolation between mobject1 and mobject2.

set_value

Sets a new scalar value to the ValueTracker

Attributes

animate

Used to animate the application of a method.

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

get_value()[source]

Get the current value of the ValueTracker. This value changes continuously when animate for the ValueTracker is called.

Return type

float

increment_value(d_value)[source]

Increments (adds) a scalar value to the ValueTracker

Parameters

d_value (float) –

interpolate(mobject1, mobject2, alpha, path_func=<function straight_path>)[source]

Turns self into an interpolation between mobject1 and mobject2.

set_value(value)[source]

Sets a new scalar value to the ValueTracker

Parameters

value (float) –