from manim import *
class PythagoreanTheorem(Scene):
def construct(self):
triangle = Polygon(
ORIGIN, 3 * RIGHT, 3 * RIGHT + 4 * UP,
stroke_color=WHITE,
fill_color=BLUE,
fill_opacity=0.5
)
square_a = Square(side_length=3, color=GREEN, fill_opacity=0.5).move_to(triangle.get_left())
square_b = Square(side_length=4, color=RED, fill_opacity=0.5).move_to(triangle.get_top())
square_c = Square(side_length=5, color=YELLOW, fill_opacity=0.5).move_to(triangle.get_corner(UP + RIGHT))
self.play(Create(triangle))
self.play(Create(square_a), Create(square_b), Create(square_c))
self.wait(1)
self.play(triangle.animate.set_fill(opacity=0.2))
self.play(square_a.animate.set_fill(opacity=0.2), square_b.animate.set_fill(opacity=0.2), square_c.animate.set_fill(opacity=0.2))
self.wait(1)
theorem_text = Tex("a^2 + b^2 = c^2").move_to(3 * DOWN)
self.play(Write(theorem_text))
self.wait(2)
self.play(FadeOut(VGroup(triangle, square_a, square_b, square_c, theorem_text)))
self.wait(1)
if __name__ == "__main__":
pythagorean_scene = PythagoreanTheorem()
pythagorean_scene.render()