Manim: `FadeOut` is not Working with Transformed text

Created on 7 May 2019  路  4Comments  路  Source: 3b1b/manim

I was trying to remove the transformed text from the scene, I tried Fading Out the transformed text and then adding a new one.

_i.e._

text1 --> text2

text2 --> fadeout

text3 (ShowCreation)

But apparently, FadeOut is not working for transformed text (text2).
I have added the sample code below:

from big_ol_pile_of_manim_imports import *

class TestFadeOut(Scene):
    def construct(self):
        sentence1 = TextMobject(r"$Some Random Equation: e^{i\pi}=-1$")
        sentence2 = TextMobject("This is a tranformed text")
        sentence3 = TextMobject("Third Text")
        self.play(Transform(sentence1, sentence2))
        self.wait(2)
        self.play(FadeOut(sentence2))
        self.wait(2)
        self.play(ShowCreation(sentence3))

I am not particular about FadeOut I just want to remove the transformed text so that I can place another text in the same position. I even tried shifting it out of the scene but it seems as if most of the TextMobject functions are not working on the transformed text.

from big_ol_pile_of_manim_imports import *

class TestFadeOut(Scene):
    def construct(self):
        sentence1 = TextMobject(r"$Some Random Equation: e^{i\pi}=-1$")
        sentence2 = TextMobject("This is a tranformed text")
        sentence3 = TextMobject("Third Text")
        self.play(Transform(sentence1, sentence2))
        self.wait(2)
        sentence2.move_to(sentence2, 50*LEFT)
        self.wait(2)
        self.play(ShowCreation(sentence3))

Most helpful comment

This should works:

from big_ol_pile_of_manim_imports import *

class TestFadeOut2(Scene):
    def construct(self):
        sentence1 = TextMobject(r"$Some Random Equation: e^{i\pi}=-1$")
        sentence2 = TextMobject("This is a tranformed text")
        sentence3 = TextMobject("Third Text")
        self.play(ReplacementTransform(sentence1, sentence2)) # <- Use ReplacementTransform
        self.wait(2)
        self.play(FadeOut(sentence2))
        self.wait(2)
        self.play(ShowCreation(sentence3))

The difference between Transform(s1, s2) and ReplacementTransform(s1, s2) is that Transform keeps the value intact of s2 and ReplacementTransform makes s2 = s1. I leave you a couple of animations to make it clearer.

class WhatIsTransform(Scene):
    def construct(self):
        sentence1 = TextMobject("A")
        sentence2 = TextMobject("B")
        sentence3 = TextMobject("C")
        sentence4 = TextMobject("D")
        self.add(sentence1)
        self.wait()

        self.play(Transform(sentence1,sentence2)) # s1<-s2 but s2 mantains it value, in the screen you see s1, not s2
        self.wait()

        self.play(Transform(sentence1,sentence3)) # s1<-s3 but s3 mantains it value, in the screen you see s1, not s3
        self.wait()

        self.play(Transform(sentence1,sentence4)) # s1<-s4 but s4 mantains it value, in the screen you see s1, not s4
        self.wait()

        self.play(FadeOut(sentence1))

class WhatIsReplacementTransform(Scene):
    def construct(self):
        sentence1 = TextMobject("A")
        sentence2 = TextMobject("B")
        sentence3 = TextMobject("C")
        sentence4 = TextMobject("D")
        self.add(sentence1)
        self.wait()

        self.play(ReplacementTransform(sentence1,sentence2)) # s1<-s2, in the screen you see s2, not s1
        self.wait()

        self.play(ReplacementTransform(sentence2,sentence3)) # s2<-s3, in the screen you see s3, not s2, then, s1="B"
        self.wait()

        self.play(ReplacementTransform(sentence3,sentence4)) # s3<-s4, in the screen you see s4, not s3, then, s1="B" and s2="C".
        self.wait()

        self.play(FadeOut(sentence4))

All 4 comments

Call FadeOut on sentence1 rather than sentence2.

But why dosen't it work with sentence2? And is there a better way to do remove the transformed text?

This should works:

from big_ol_pile_of_manim_imports import *

class TestFadeOut2(Scene):
    def construct(self):
        sentence1 = TextMobject(r"$Some Random Equation: e^{i\pi}=-1$")
        sentence2 = TextMobject("This is a tranformed text")
        sentence3 = TextMobject("Third Text")
        self.play(ReplacementTransform(sentence1, sentence2)) # <- Use ReplacementTransform
        self.wait(2)
        self.play(FadeOut(sentence2))
        self.wait(2)
        self.play(ShowCreation(sentence3))

The difference between Transform(s1, s2) and ReplacementTransform(s1, s2) is that Transform keeps the value intact of s2 and ReplacementTransform makes s2 = s1. I leave you a couple of animations to make it clearer.

class WhatIsTransform(Scene):
    def construct(self):
        sentence1 = TextMobject("A")
        sentence2 = TextMobject("B")
        sentence3 = TextMobject("C")
        sentence4 = TextMobject("D")
        self.add(sentence1)
        self.wait()

        self.play(Transform(sentence1,sentence2)) # s1<-s2 but s2 mantains it value, in the screen you see s1, not s2
        self.wait()

        self.play(Transform(sentence1,sentence3)) # s1<-s3 but s3 mantains it value, in the screen you see s1, not s3
        self.wait()

        self.play(Transform(sentence1,sentence4)) # s1<-s4 but s4 mantains it value, in the screen you see s1, not s4
        self.wait()

        self.play(FadeOut(sentence1))

class WhatIsReplacementTransform(Scene):
    def construct(self):
        sentence1 = TextMobject("A")
        sentence2 = TextMobject("B")
        sentence3 = TextMobject("C")
        sentence4 = TextMobject("D")
        self.add(sentence1)
        self.wait()

        self.play(ReplacementTransform(sentence1,sentence2)) # s1<-s2, in the screen you see s2, not s1
        self.wait()

        self.play(ReplacementTransform(sentence2,sentence3)) # s2<-s3, in the screen you see s3, not s2, then, s1="B"
        self.wait()

        self.play(ReplacementTransform(sentence3,sentence4)) # s3<-s4, in the screen you see s4, not s3, then, s1="B" and s2="C".
        self.wait()

        self.play(FadeOut(sentence4))

This should be included in the doc

Was this page helpful?
0 / 5 - 0 ratings