manim
manim copied to clipboard
always_redraw rendering only once
Describe the bug
Testing the UpdatersExample
I notice that the Brace
do not rescale following the square as in the example video.
Reading the always_redraw
code I could notice that a brand new mobject
are created inside the updater callback and passed down to mob.become
. But the become
method clean the "old mob" updaters and copy the updaters from the "new mob" with has no updater. So, in the end, the redraw updater are deregistered.
Looking at the git log I think the bug was introduced at 0e45b41fea5f22d136f62f4af2e0d892e61a12ce when the match_updaters
was added to the become
method.
Code: https://3b1b.github.io/manim/getting_started/example_scenes.html#updatersexample
Wrong display or Error traceback:
https://user-images.githubusercontent.com/5621021/170176501-fc19b110-47fa-4184-8082-b9231dfc70b1.mp4
Additional context
Manim version: master branch at 07a8274cb17db54ce2deb2de28055186e914371c
Hello! The code seems to work fine with this modification:
from manimlib import *
class UpdatersExample(Scene):
def construct(self):
#Create square
square = Square()
square.set_fill(BLUE_E, 1)
#Create label to attach to side of square
text, number = label = VGroup(
Text("Width = "),
DecimalNumber(
0,
show_ellipsis=True,
num_decimal_places=2,
include_sign=True
)
)
brace = always_redraw(Brace, square, UP) #constantly redraw braces to match data
always(label.next_to, brace, UP) #label is next to the brace
always(brace.next_to, square, UP)
f_always(number.set_value, square.get_width)
f_always(brace.set_width, square.get_width)
label.arrange(RIGHT)
self.add(square, brace, label)
#now change the width of the square
self.play(
square.animate.scale(2),
rate_func=there_and_back,
run_time=2
)
self.wait()
self.play(
square.animate.set_width(5, stretch=True),
run_time=3
)
self.wait()
self.play(
square.animate.set_width(2, stretch=True),
run_time=3
)
self.wait()
#Update the label as the width of the square changes
now = self.time
w0 = square.get_width()
square.add_updater(
lambda m: m.set_width(w0 * math.cos(self.time - now))
)
self.wait(4 * PI)
Hi, you can just downgrade your manim to 1.5.0 to solve this problem.
pip install manimgl==1.5.0
This should be fixed now.