Certainly! To create an animation explaining the Pythagorean Theorem using Manim, we need to follow these steps:
- Draw a right triangle.
- Label the sides (
a, b, c).
- Draw squares on each of the three sides.
- Use animations to sequentially explain how the areas of the squares on sides
a and b together equal the area of the square on side c.
Below is a complete example of Manim code to create this animated explanation. This code assumes you're using Manim Community edition.
from manim import *
class PythagoreanTheorem(Scene):
def construct(self):
# Create a right triangle
right_triangle = Polygon(ORIGIN, 4*RIGHT, 3*UP, color=WHITE)
right_triangle.set_fill(BLUE, opacity=0.5)
# Labels for sides
a_label = Tex("a").next_to(right_triangle, LEFT)
b_label = Tex("b").next_to(right_triangle, DOWN)
c_label = Tex("c").next_to(right_triangle, RIGHT).shift(0.5*UP+0.5*RIGHT)
# Side Lengths for squares
a_length = 3
b_length = 4
c_length = 5 # For a 3-4-5 right triangle
# Squares on sides
square_a = Square(side_length=a_length).move_to(right_triangle.get_vertices()[2]).rotate(PI).set_color(RED).set_fill(RED, opacity=0.5)
square_b = Square(side_length=b_length).move_to(right_triangle.get_vertices()[0]).rotate(-PI/2).set_color(GREEN).set_fill(GREEN, opacity=0.5)
square_c = Square(side_length=c_length).move_to(right_triangle.get_vertices()[1]).set_color(YELLOW).set_fill(YELLOW, opacity=0.5)
# Grouping the text and triangle for alignment
triangle_group = VGroup(right_triangle, a_label, b_label, c_label)
# Step-by-step animation
self.play(Create(triangle_group))
self.wait(1)
self.play(Create(square_a), Create(square_b), Create(square_c))
self.wait(1)
# Annotated proof
eq1 = Tex("a^2 + b^2 = c^2").next_to(right_triangle, UP, buff=1)
self.play(Write(eq1))
self.wait(2)
self.play(FadeOut(square_a), FadeOut(square_b), FadeOut(square_c))
self.play(triangle_group.animate.shift(3*LEFT))
# Explaining area equivalence
area_a = square_a.copy().next_to(eq1, RIGHT, buff=1)
area_b = square_b.copy().next_to(area_a, RIGHT, buff=0.5)
area_c = square_c.copy().next_to(area_b, RIGHT, buff=0.5)
self.play(TransformFromCopy(square_a, area_a), TransformFromCopy(square_b, area_b), TransformFromCopy(square_c, area_c))
self.wait(2)
# Final conclusion
conclusion = Tex("The area of the yellow square is equal to \\\\ the sum of the areas of the red and green squares.").next_to(eq1, DOWN, buff=1)
self.play(Write(conclusion))
self.wait(3)
# Clear scene
self.play(FadeOut(VGroup(*self.mobjects)))
# Remember to add this file to your project, and run using the `manim` command.
How to Run the Code
This script sets up a scene with animation to visually explain and demonstrate the Pythagorean Theorem, making use of Manim's capabilities to display geometric relationships and transformations.