ValueTracker#

Qualified name: manim.mobject.value\_tracker.ValueTracker

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

Bases: 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.

This value changes continuously when animated using the animate syntax.

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))

        tracker = ValueTracker(0)
        pointer.add_updater(
            lambda m: m.next_to(
                        number_line.n2p(tracker.get_value()),
                        UP
                    )
        )
        self.add(number_line, pointer,label)
        tracker += 1.5
        self.wait(1)
        tracker -= 4
        self.wait(0.5)
        self.play(tracker.animate.set_value(5)),
        self.wait(0.5)
        self.play(tracker.animate.set_value(3))
        self.play(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):
        tracker = ValueTracker(0)
        label = Dot(radius=3).add_updater(lambda x : x.set_x(tracker.get_value()))
        self.add(label)
        self.add(tracker)
        tracker.add_updater(lambda mobject, dt: mobject.increment_value(dt))
        self.wait(2)

Methods

get_value

Get the current value of this 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 any method of self.

animation_overrides

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 this ValueTracker.

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 interpolate>)[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) –