Basic Updaters
Basic theory
Updaters are functions that are applied to a Mobject and that are updated every frame.
Question: How would we make sure that the square is always above the circle without having to manipulate the square?
Basically, we need the square.next_to(circle,UP)
to apply each frame of the animation, for this we can use the Updaters.
If the functions are simple then we can use anonymous functions to make it shorter.
And this updater is going to run until we pause and delete it.
Pause updaters:
Mobject.suspend_updating()
Restore updaters:
Mobject.resume_updating()
Delete all updaters:
Mobject.clear_updaters()
Yes, you can add more updaters, each Mobject has an attribute (a list) where it stores its updaters, so you can add or remove more updaters.
.become
Now imagine that we want the Brace
to change in size depending on the line.
There are some Mobjects that you can change their shape through their methods, but the most general way is to use .become
.
The easiest way to understand .become
is by making the analogy with Transform
, basically .become
is an instant Transform
, and I can demonstrate it with the following code.
def construct(self):
c = Circle().scale(2)
s = Square().scale(2)
c.generate_target()
c.target.become(s) # <-- it's an instant transformation
self.add(c)
self.play(MoveToTarget(c))
self.wait()