Elteoremadebeethoven/AnimationsWithManim

Shift animation returns a black screen video

Closed this issue · 7 comments

qo4on commented

Is it a bug? Or there is another way to shift an animation?

text = Text("Manim Animation", font="Arial", stroke_width=0)

self.play(
    LaggedStartMap(FadeIn, text),
    ApplyMethod(text.shift, UP)
)

Thanks for these awesome examples!

As I explained in video 8.2 you cannot apply two Animation's classes to the same object, you must do it either using methods, or create a function and apply it with ApplyFunction (you can see it in my documentation), or creating a specific updater function. It is not a bug.

class Test(Scene):
    def construct(self):
        text = Text("Manim Animation", font="Arial", stroke_width=0,fill_opacity=0)

        def shift_and_fade(mob):
            mob.shift(UP)
            mob.set_fill(opacity=1)
            return mob
        self.play(
                LaggedStart(
                    ApplyFunction(shift_and_fade,text)
                )
        )
        self.wait()
qo4on commented

You got me wrong. My code renders letter by letter. Your code creates different animation: the whole line appears at the same time. I mean suppose you have an AnimationGroup with some lagged start animation. Is there a way to animate shifting at the same time with this letter by letter animation I didn't find it in your tutorials?

class test(Scene):
    def construct(self):
        text = Text("Manim Animation", font="Arial", stroke_width=0)
        self.play(
            LaggedStartMap(FadeIn, text),
        )

Well in that case you can make use of what I tried to explain in those examples. You can do it in different ways:

class T1(Scene):
    def construct(self):
        text = Text("Manim Animation", font="Arial", stroke_width=0,fill_opacity=0)

        def shift_and_fade(mob):
            mob.shift(UP)
            mob.set_fill(opacity=1)
            return mob
        self.play(
                LaggedStart(*[ApplyFunction(shift_and_fade,t) for t in text])
        )
        self.wait()

class T2(Scene):
    def construct(self):
        text = Text("Manim Animation", font="Arial", stroke_width=0)

        self.play(
                LaggedStart(*[FadeInFromDown(t) for t in text])
        )
        self.wait()

class T3(Scene):
    def construct(self):
        text = Text("Manim Animation", font="Arial", stroke_width=0)

        self.play(
                LaggedStartMap(FadeInFromDown,text)
        )
        self.wait()

I recommend that you watch the videos "My projects" 1 and 2 for more examples of how to create your own animations like these.

qo4on commented

Thanks, I understand all your examples. My question is a bit different. Is it possible to animate shifting of an AnimationGroup? I mean this is the video from one of your examples:

class test(Scene):
    def construct(self):
        text = Text("Manim Animation", font="Arial", stroke_width=0)
        anims = [FadeInFromPoint(obj, obj.get_center() * 1.4) for obj in text]
        self.play(LaggedStart(*anims))

Can I shift the whole animation and get this video? Animate letter by letter with an AnimationGroup and animate shifting of the whole line of text. Or any workaround if it's not possible?

It is useful when you already have some animation groups playing and you want to move them while they are still playing.

Sorry for the dalay, you can try somethink like this:

class Test(Scene):
    def construct(self):
        triangle = Triangle()
        square = Square()
        triangle.add_updater(lambda mob,dt: mob.shift(RIGHT*0.1))
        anim1 = Write(triangle)
        anim2 = Write(square)
        self.add(triangle)
        turn_animation_into_updater(anim1)
        self.wait(0.4)
        self.add(square)
        turn_animation_into_updater(anim2)
        self.wait(3)
qo4on commented

Thank you! Unfortunately, updaters run forever. How can I apply smooth rate function to this triangle shifting to specific point (not shift forever) and change its run_time?