Skip to content

Commit 9a35756

Browse files
JasonGrace2282pre-commit-ci[bot]MrDiver
authored
Explain .Transform vs .ReplacementTransform in quickstart examples (#3500)
* Explained ReplacementTransform vs Transform * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added section explaining Transform vs ReplacementTransform * Added a->b->c example * Clarified explanation * Fixed Typo * Fixed missing colon * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tristan Schulz <[email protected]>
1 parent 64a0e9d commit 9a35756

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

docs/source/tutorials/quickstart.rst

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,9 @@ and animating those method calls with ``.animate``.
268268
269269
self.play(Create(square)) # show the square on screen
270270
self.play(square.animate.rotate(PI / 4)) # rotate the square
271+
self.play(Transform(square, circle)) # transform the square into a circle
271272
self.play(
272-
ReplacementTransform(square, circle)
273-
) # transform the square into a circle
274-
self.play(
275-
circle.animate.set_fill(PINK, opacity=0.5)
273+
square.animate.set_fill(PINK, opacity=0.5)
276274
) # color the circle on screen
277275
278276
2. Render ``AnimatedSquareToCircle`` by running the following command in the command line:
@@ -293,8 +291,8 @@ The following animation will render:
293291

294292
self.play(Create(square)) # show the square on screen
295293
self.play(square.animate.rotate(PI / 4)) # rotate the square
296-
self.play(ReplacementTransform(square, circle)) # transform the square into a circle
297-
self.play(circle.animate.set_fill(PINK, opacity=0.5)) # color the circle on screen
294+
self.play(Transform(square, circle)) # transform the square into a circle
295+
self.play(square.animate.set_fill(PINK, opacity=0.5)) # color the circle on screen
298296

299297
The first ``self.play`` creates the square. The second animates rotating it 45 degrees.
300298
The third transforms the square into a circle, and the last colors the circle pink.
@@ -348,6 +346,55 @@ If you find that your own usage of ``.animate`` is causing similar unwanted beha
348346
using conventional animation methods like the right square, which uses ``Rotate``.
349347

350348

349+
``Transform`` vs ``ReplacementTransform``
350+
*****************************************
351+
The difference between ``Transform`` and ``ReplacementTransform`` is that ``Transform(mob1, mob2)`` transforms the points
352+
(as well as other attributes like color) of ``mob1`` into the points/attributes of ``mob2``.
353+
354+
``ReplacementTransform(mob1, mob2)`` on the other hand literally replaces ``mob1`` on the scene with ``mob2``.
355+
356+
The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal preference. They can be used to accomplish the same effect, as shown below.
357+
358+
.. code-block:: python
359+
360+
class TwoTransforms(Scene):
361+
def transform(self):
362+
a = Circle()
363+
b = Square()
364+
c = Triangle()
365+
self.play(Transform(a, b))
366+
self.play(Transform(a, c))
367+
self.play(FadeOut(a))
368+
369+
def replacement_transform(self):
370+
a = Circle()
371+
b = Square()
372+
c = Triangle()
373+
self.play(ReplacementTransform(a, b))
374+
self.play(ReplacementTransform(b, c))
375+
self.play(FadeOut(c))
376+
377+
def construct(self):
378+
self.transform()
379+
self.wait(0.5) # wait for 0.5 seconds
380+
self.replacement_transform()
381+
382+
383+
However, in some cases it is more beneficial to use ``Transform``, like when you are transforming several mobjects one after the other.
384+
The code below avoids having to keep a reference to the last mobject that was transformed.
385+
386+
.. manim:: TransformCycle
387+
388+
class TransformCycle(Scene):
389+
def construct(self):
390+
a = Circle()
391+
t1 = Square()
392+
t2 = Triangle()
393+
self.add(a)
394+
self.wait()
395+
for t in [t1,t2]:
396+
self.play(Transform(a,t))
397+
351398
************
352399
You're done!
353400
************

0 commit comments

Comments
 (0)