Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Explain ``.Transform`` vs ``.ReplacementTransform`` in quickstart examples (#3500)

Jason Grace9a35756048ad
diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst
index f118a6614..bd681add5 100644
--- a/docs/source/tutorials/quickstart.rst
+++ b/docs/source/tutorials/quickstart.rst
@@ -268,11 +268,9 @@ and animating those method calls with ``.animate``.
self.play(Create(square)) # show the square on screen
self.play(square.animate.rotate(PI / 4)) # rotate the square
+ self.play(Transform(square, circle)) # transform the square into a circle
self.play(
- ReplacementTransform(square, circle)
- ) # transform the square into a circle
- self.play(
- circle.animate.set_fill(PINK, opacity=0.5)
+ square.animate.set_fill(PINK, opacity=0.5)
) # color the circle on screen
2. Render ``AnimatedSquareToCircle`` by running the following command in the command line:
@@ -293,8 +291,8 @@ The following animation will render:
self.play(Create(square)) # show the square on screen
self.play(square.animate.rotate(PI / 4)) # rotate the square
- self.play(ReplacementTransform(square, circle)) # transform the square into a circle
- self.play(circle.animate.set_fill(PINK, opacity=0.5)) # color the circle on screen
+ self.play(Transform(square, circle)) # transform the square into a circle
+ self.play(square.animate.set_fill(PINK, opacity=0.5)) # color the circle on screen
The first ``self.play`` creates the square. The second animates rotating it 45 degrees.
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
using conventional animation methods like the right square, which uses ``Rotate``.
+``Transform`` vs ``ReplacementTransform``
+*****************************************
+The difference between ``Transform`` and ``ReplacementTransform`` is that ``Transform(mob1, mob2)`` transforms the points
+(as well as other attributes like color) of ``mob1`` into the points/attributes of ``mob2``.
+
+``ReplacementTransform(mob1, mob2)`` on the other hand literally replaces ``mob1`` on the scene with ``mob2``.
+
+The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal preference. They can be used to accomplish the same effect, as shown below.
+
+.. code-block:: python
+
+ class TwoTransforms(Scene):
+ def transform(self):
+ a = Circle()
+ b = Square()
+ c = Triangle()
+ self.play(Transform(a, b))
+ self.play(Transform(a, c))
+ self.play(FadeOut(a))
+
+ def replacement_transform(self):
+ a = Circle()
+ b = Square()
+ c = Triangle()
+ self.play(ReplacementTransform(a, b))
+ self.play(ReplacementTransform(b, c))
+ self.play(FadeOut(c))
+
+ def construct(self):
+ self.transform()
+ self.wait(0.5) # wait for 0.5 seconds
+ self.replacement_transform()
+
+
+However, in some cases it is more beneficial to use ``Transform``, like when you are transforming several mobjects one after the other.
+The code below avoids having to keep a reference to the last mobject that was transformed.
+
+.. manim:: TransformCycle
+
+ class TransformCycle(Scene):
+ def construct(self):
+ a = Circle()
+ t1 = Square()
+ t2 = Triangle()
+ self.add(a)
+ self.wait()
+ for t in [t1,t2]:
+ self.play(Transform(a,t))
+
************
You're done!
************