Skip to content

Custom Animation Class #1669

Discussion options

You must be logged in to vote
class RotationAnimation(Animation):
    def __init__(self, mobject, angle, **kwargs):
        self.angle = angle
        super().__init__(mobject, **kwargs)
    
    def interpolate_mobject(self, alpha):
        self.mobject.set_points(self.starting_mobject.get_points())
        self.mobject.rotate(alpha * self.angle)

class RotationScene(Scene):
    def construct(self):
        self.play(
            RotationAnimation(Square(), 45 * DEGREES),
            rate_func=linear,
            run_time=1
        )

Check this example for Custom Animation.

While defining custom animation, you should know what alpha is. Alpha ranges from 0 to 1 throughout the animation. For rotation, Now, when animat…

Replies: 2 comments 16 replies

Comment options

You must be logged in to vote
16 replies
@WampyCakes
Comment options

@sahilmakhijani
Comment options

@sahilmakhijani
Comment options

@sahilmakhijani
Comment options

@WampyCakes
Comment options

Answer selected by AhmedMajedKaz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants