Custom Animation Class #1669
-
I have two question, Can you please answer it if you know. First: I search in "https://github.com/3b1b/videos" and found some classes that are inherited from Animation and Transform Class, my question is how to make my custom animation class ?, I don't think this is mentioned in the documentation of Manim. Second: how transform animation work? I search in Transform Class, but I don't understand how it work because I learn python recently, And I want to know how transform and interpolate between two shapes happens. and thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
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 animation starts I want object to be 0 degrees tilted from starting object and at the end it should be 45 degrees tilted. So, if I tilt alpha * 45 Degrees, then it should work properly. If the frame rate is 60 and runtime is 1 second, so interpolate_mobject will be called 60 time per second. At first alpha will be 0, so 0 degress tilt. After half second, alpha will be 0.5, so you will tilt 22.5 degrees. At last alpha will be 1, so you will tilt 45 degrees. That's why it would be a smooth animation from 0 degrees to 45 degrees tilt. |
Beta Was this translation helpful? Give feedback.
-
For the second question, transform animation works by calling interpolate on the corresponding type of |
Beta Was this translation helpful? Give feedback.
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…