DecimalNumber with ValueTracker and updaters don't work #3600
-
I have the following code:
The code produces the following video: I expected the numbers (0.00) to change based on my list of targets, but it stays still for several seconds, why? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I think your problem is in your use of
The emphasis is on is populated with a copy of it which means that your original If you use the class NeuronFormula(Scene):
@staticmethod
def make_formula_group(first_term, second_term, third_term):
return VGroup(first_term, second_term, third_term).arrange(RIGHT, buff=0.1).move_to([0, 0, 0])
def construct(self):
formula = NeuronFormula.make_formula_group(MathTex("w"), MathTex("x+"), MathTex("b"))
formula.target = NeuronFormula.make_formula_group(MathTex("?"), MathTex("x+"), MathTex("?"))
self.add(formula)
self.wait(1)
self.play(MoveToTarget(formula), run_time=0.5)
self.wait(1)
a = ValueTracker(0)
b = ValueTracker(0)
a_targets = [3, -3] * 3
b_targets = [3, -3] * 3
a_display = DecimalNumber(a.get_value())
b_display = DecimalNumber(b.get_value())
self.play(
ReplacementTransform(
formula,
NeuronFormula.make_formula_group(a_display, MathTex("x+"), b_display)
)
)
a_display.add_updater(
lambda mob: mob.set_value(a.get_value())
)
b_display.add_updater(
lambda mob: mob.set_value(b.get_value())
)
a_value_animations = Succession(*[ApplyMethod(a.set_value, target) for target in a_targets], lag_ratio=1)
b_value_animations = Succession(*[ApplyMethod(b.set_value, target) for target in b_targets], lag_ratio=1)
self.play(a_value_animations, b_value_animations) NeuronFormula.mp4 |
Beta Was this translation helpful? Give feedback.
-
it is the |
Beta Was this translation helpful? Give feedback.
I think your problem is in your use of
MoveToTarget
which I have never seen or used before. From the description of this animation class:The emphasis is on is populated with a copy of it which means that your original
a_display
which gets the updater is never actually added to the scene, but only a copy of the object from the …