Shift

.Shift({Amount} Direction) to align the objects from center.

 circle = Circle()
        square = Square()
        triangle = Triangle()

        circle.shift(1*LEFT)
        square.shift(1*UP)
        triangle.shift(1*RIGHT)

        self.add(circle, square, triangle)

Pasted image 20240109235634.png

set_stroke || set_Fill

  circle = Circle().shift(LEFT)
        square = Square().shift(UP)
        triangle = Triangle().shift(RIGHT)

        circle.set_stroke(color=GREEN, width=20)
        square.set_fill(YELLOW, opacity=1.0)
        triangle.set_fill(PINK, opacity=0.5)

        self.add(circle, square, triangle)

Pasted image 20240109235907.png

FadeIn || FadeOut

from manim import *

class SomeAnimations(Scene):
    def construct(self):
        square = Square()

        self.play(FadeIn(square))

        self.play(Rotate(square, PI/4))

        self.play(FadeOut(square))

        self.wait(1)

Output:

Rotate:


class Rotate(mobject=None, *args, use_override=True, **kwargs)

Animation that rotates a Mobject.

PARAMETERS:

from manim import *

  

class Rotation(Scene):

def construct(self):

square = Square(color=BLUE)

self.play(Create(square))

self.play(

Rotate(

square,

angle=PI/4,

about_point = ORIGIN,

rate_func = linear,

run_time = 3,

),

)

self.remove(square)

self.wait()

circle = Circle(color=RED)

self.play(Create(circle))

self.play(circle.animate.shift(2*UP))

self.play(

Rotate(

circle,

angle=PI/4,

about_point = ORIGIN,

rate_func = linear,

run_time = 3,

),

)

move_to || next_to || edge_to || grow_from_center

self.play(GrowFromEdge(triangle, DOWN))
 self.play(GrowFromPoint(square, ORIGIN))

Custom Example Using Building Blocks

from manim import *


class Custom(Scene):

def construct(self):

square = Square()

square.set_fill(RED, opacity=0.6)

self.play(Create(square))

self.play(Rotate(square, PI/4))

self.play(square.animate.set_stroke(YELLOW, width=20),runtime =2)

square.set_stroke(BLUE, width=10)

self.wait(2)

self.play(square.animate.set_fill(GREEN, opacity=0.2),runtime =2)

triangle = Triangle()

self.play(square.animate.shift(3*UP).rotate(PI/4).scale(2),runtime = 3)

self.play(ReplacementTransform(square, triangle),runtime = 3)
- Here we used our knowledge of animate method along with building blocks to understand how to animate stuff in manim, first we are creating a square , then we learnt above that to fill it any color we would use set fill, now we remember we had already done set fill before the animation in self.play right? - So what happens is it renders the red block directly, to explain this further I have used Rotate which as I explained a way to rotate that mobject,now we want to set a stroke but we also want to animate it then we use .animate.set_stroke rather than just doing it directly, you can see in the video what happens if we do it directly, we used self.wait() to observe that frame and grasp it fully, then we saw how fill can be animated as well. - Now for the shift up, if we would have just shifted up it would not have rotated, but we also want to rotate it and scale it twice, so we use multiple parameters methods here and you can also not specify the runtime, but it's a good practice to do so for convenience of understanding how your animation will look like, then we use ReplacementTransform function which you can find Common Functions in Manim#^3e9409 here. To morph triangle into the square.