Methods as animations
Once we have understood how the transformations work, we can enter other functionalities based on them. Everything that we will see next is derived from the transformations.
MoveToTarget
This is quite a useful animation. Basically it is about creating a temporary copy of a Mobject called target, then making modifications to that copy (target) to end with a transformation from the original Mobject to the target.
We could do this manually, in the following example we will see MoveToTarget on the left side and on the right side we will see its analog manually.
def construct(self):
source_left = Dot()
source_right = source_left.copy()
VGroup(source_left,source_right).arrange(RIGHT,buff=3)
# Left side - MoveToTarget ----------------
source_left.generate_target()
# Manupulate the .target attr
source_left.target.set_style(
fill_color=TEAL,
stroke_width=10,
stroke_color=ORANGE
)
source_left.target.scale(7)
source_left.target.to_edge(UP)
# Right side - Manually ----------------
source_right_target = source_right.copy()
source_right_target.set_style(
fill_color=TEAL,
stroke_width=10,
stroke_color=ORANGE
)
source_right_target.scale(7)
source_right_target.to_edge(UP)
# Animations
self.add(source_left,source_right)
self.play(
MoveToTarget(source_left),
Transform(source_right,source_right_target),
run_time=3
)
self.wait()