From 13348442a44aff968cb8da5da95b65d4b19a6e91 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Wed, 6 Dec 2023 21:38:53 -0500 Subject: [PATCH 1/8] Explained ReplacementTransform vs Transform --- docs/source/tutorials/quickstart.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index 2a93e0b1f6..bdb40f8b0e 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -304,6 +304,27 @@ with the changes already applied. Try other methods, like ``flip`` or ``shift``, and see what happens. +.. note:: + 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``. This is best + illustrated with the example below: + + .. code-block:: python + + class TwoTransforms(Scene): + def construct(self): + c = Circle() + self.add(c) + self.play(Transform(c, Square())) + self.play(FadeOut(c)) # fadout c + s = Square() + c = Circle() + self.add(c) + self.play(ReplacementTransform(c, s)) + self.play(FadeOut(s)) # fadeout s + 3. Open ``scene.py``, and add the following code snippet below the ``AnimatedSquareToCircle`` class: .. code-block:: python From d18e9937479a17951c6bea072c5cafdc5deca5d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 02:41:22 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/tutorials/quickstart.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index ee93236626..8dac0f39c1 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -312,18 +312,18 @@ Try other methods, like ``flip`` or ``shift``, and see what happens. illustrated with the example below: .. code-block:: python - + class TwoTransforms(Scene): def construct(self): c = Circle() self.add(c) self.play(Transform(c, Square())) - self.play(FadeOut(c)) # fadout c + self.play(FadeOut(c)) # fadout c s = Square() c = Circle() self.add(c) self.play(ReplacementTransform(c, s)) - self.play(FadeOut(s)) # fadeout s + self.play(FadeOut(s)) # fadeout s 3. Open ``scene.py``, and add the following code snippet below the ``AnimatedSquareToCircle`` class: From 05ec2d5476832fd7fe7edc6460b492b3af40f815 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 7 Dec 2023 07:48:58 -0500 Subject: [PATCH 3/8] Added section explaining Transform vs ReplacementTransform --- docs/source/tutorials/quickstart.rst | 62 +++++++++++++++++----------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index 8dac0f39c1..01ba503b80 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -269,10 +269,10 @@ 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( - ReplacementTransform(square, circle) + Transform(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 +293,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. @@ -304,27 +304,6 @@ with the changes already applied. Try other methods, like ``flip`` or ``shift``, and see what happens. -.. note:: - 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``. This is best - illustrated with the example below: - - .. code-block:: python - - class TwoTransforms(Scene): - def construct(self): - c = Circle() - self.add(c) - self.play(Transform(c, Square())) - self.play(FadeOut(c)) # fadout c - s = Square() - c = Circle() - self.add(c) - self.play(ReplacementTransform(c, s)) - self.play(FadeOut(s)) # fadeout s - 3. Open ``scene.py``, and add the following code snippet below the ``AnimatedSquareToCircle`` class: .. code-block:: python @@ -369,6 +348,39 @@ 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(Trasnform(a, b)) + self.play(Trasnform(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() + ************ You're done! ************ From c862f2de3b55236be2bfc90935be7d481e70a0b1 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sat, 9 Dec 2023 16:58:14 -0500 Subject: [PATCH 4/8] Added a->b->c example --- docs/source/tutorials/quickstart.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index 01ba503b80..4feac67a53 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -381,6 +381,21 @@ The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal pr 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. + +.. 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! ************ From df26b9f6c9e5334e78ffc97dababafe2609998df Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sat, 9 Dec 2023 17:00:23 -0500 Subject: [PATCH 5/8] Clarified explanation --- docs/source/tutorials/quickstart.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index 4feac67a53..58508a828c 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -383,6 +383,7 @@ The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal pr 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 From 9478efed48c5631e999d6dbba8537833d9c05cce Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sat, 9 Dec 2023 17:05:56 -0500 Subject: [PATCH 6/8] Fixed Typo --- docs/source/tutorials/quickstart.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index 58508a828c..bf309dd2af 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -364,8 +364,8 @@ The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal pr a = Circle() b = Square() c = Triangle() - self.play(Trasnform(a, b)) - self.play(Trasnform(a, c)) + self.play(Transform(a, b)) + self.play(Transform(a, c)) self.play(FadeOut(a)) def replacement_transform(self) From c73887b990066321d7d385600419d9c99895ef09 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sat, 9 Dec 2023 17:12:15 -0500 Subject: [PATCH 7/8] Fixed missing colon --- docs/source/tutorials/quickstart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index bf309dd2af..79351c6442 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -368,7 +368,7 @@ The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal pr self.play(Transform(a, c)) self.play(FadeOut(a)) - def replacement_transform(self) + def replacement_transform(self): a = Circle() b = Square() c = Triangle() From 590de18c5b2d6fbaaa24f3bc6e9a1941647a2da3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:12:51 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/tutorials/quickstart.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst index 79351c6442..bd681add5b 100644 --- a/docs/source/tutorials/quickstart.rst +++ b/docs/source/tutorials/quickstart.rst @@ -268,9 +268,7 @@ 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(Transform(square, circle)) # transform the square into a circle self.play( square.animate.set_fill(PINK, opacity=0.5) ) # color the circle on screen @@ -378,7 +376,7 @@ The use of ``ReplacementTransform`` or ``Transform`` is mostly up to personal pr def construct(self): self.transform() - self.wait(0.5) # wait for 0.5 seconds + self.wait(0.5) # wait for 0.5 seconds self.replacement_transform()