I have this simple script, where I would like the ValueTracker (displayed as a number on the right) to evolve at the same speed with the graph. Instead the graph plotting finishes in 5 seconds. Do you know why and how to fix it?
from manim import *
class TrackerExample(Scene):
def sin(self,x):
f = 1 / 50
return np.sin(x * 2 * math.pi * f) / 2 + 0.5
def construct(self):
axes= Axes(x_range=[0, 749, 100],
y_range=[0, 4, 2],
axis_config={"include_numbers": True, "font_size": 24},
x_axis_config={},
x_length=4,
y_length=3
).move_to(LEFT * 2)
self.play(Write(axes, lag_ratio=0.01, run_time=1))
tracker = ValueTracker(0)
sin_graph = axes.plot(lambda x: self.sin(x), color=BLUE)
numbers = DecimalNumber(0).move_to(2*RIGHT)
numbers.add_updater(lambda m: m.set_value(int(tracker.get_value())))
self.add(numbers)
self.play(tracker.animate.set_value(749), Write(sin_graph), run_time=10,
rate_func=linear)
example = TrackerExample()
example.construct()
I am using the community version of manim, 0.16.0.post0
This is due to your choice of Animation: Write
draws, in the first 50% of the animation run time, the stroke of the mobject and then fills it in the remaining 50% of the run time. Replace Write
with Create
, and it will look as expected.
And by the way, if you want to render your scene directly from the script, use the render
method, not construct
:
example = TrackerExample()
example.render()