Untitled

 avatar
unknown
python
2 years ago
7.4 kB
11
Indexable
from manim import *

class Euler(Scene):
    def construct(self):
        # Créer les labels pour Re et Im
        real_label = MathTex(r"\text{Re}").next_to(RIGHT*3.5, UP, buff=SMALL_BUFF)
        imag_label = MathTex(r"\text{Im}").next_to(UP*3.5, LEFT, buff=SMALL_BUFF)

        # Créer les flèches pour Re et Im
        real_arrow = Arrow(LEFT*0.25, RIGHT*3.5, tip_length=0.15, stroke_width=1)
        imag_arrow = Arrow(DOWN*0.25, UP*3.5, tip_length=0.15, stroke_width=1)

        # Ajouter les labels à la fin des flèches
        real_label.next_to(real_arrow.get_end(), RIGHT, buff=SMALL_BUFF)
        imag_label.next_to(imag_arrow.get_end(), UP, buff=SMALL_BUFF)

        # Créer le cercle de rayon
        circle = Circle(radius=2.25, stroke_width=1.5, color=WHITE)

        # Créer les points d'intersection
        un_point = MathTex(r"\text{1}").next_to(RIGHT*2.5, UP*0.4)
        i_point = MathTex(r"\text{i}").next_to( UP*2.5, RIGHT*0.4)
        
        # Cos et Sin au point 0
        cos_point = MathTex(r"{\cos\theta}").next_to(RIGHT*0.5, DOWN*0.2)
        sin_point = MathTex(r"{\sin\theta}").next_to(UP*0.4, LEFT*0.7)
        theta = MathTex(r"{\theta}", font_size=40).next_to(RIGHT*0.65, UP*0.4)
        
        # Fleche de la démonstration 
        line45d = Line(start=[-0, -0, 0], end=[1.59, 1.59, 0], stroke_width=1.5)
        linesin = Line(start=[1.59, 0, 0], end=[1.59, 1.59, 0], stroke_width=1.5)
        
        # Arc theta 
        arc = Arc(radius=0.5, start_angle=0, angle=45*DEGREES, stroke_width=1.5)
        
        #Objet de la formule 
        formule = MathTex(r"e^{i\theta}", "=", r"\cos(\theta) + i\sin(\theta)")
        serie1 = MathTex(r"e^{i\theta} = 1+i\theta+\frac{i\theta^{2}}{2!}+...+\frac{i\theta^{n}}{n!}+...").next_to(formule, UP*2, LEFT*5)
        serie2 = MathTex(r"e^{i\theta} = \sum^{\infty}_{n=0}(\frac{(i\theta)^n}{n!})= ").next_to(serie1,LEFT*0.9, buff=SMALL_BUFF)
        serie3 = MathTex(r"\sum^{\infty}_{n=0}(\frac{i^n \theta^n}{n!})").next_to(serie2,RIGHT*0.9, buff=SMALL_BUFF)
        convi = MathTex(r"[With : ", "i^{2k} = (i^2)^k = (-1)^k]").next_to(serie3,LEFT*0.9, buff=SMALL_BUFF)
        equival = MathTex(r"\Leftrightarrow").next_to(convi,DOWN, buff=SMALL_BUFF)
        equival2 = MathTex(r"\Leftrightarrow").next_to(convi,DOWN, buff=SMALL_BUFF)
        serie4 = MathTex(r"=\sum^{\infty}_{k=0}(\frac{i^{2k} \theta^{2k}}{2k!}) + \sum^{\infty}_{k=0}(\frac{i^{2k+1} \theta^{2k+1}}{2k+1!})").next_to(serie2,RIGHT*0.9, buff=SMALL_BUFF)
        serie5 = MathTex(r"\sum^{\infty}_{k=0}\frac{(-1)^{k} \theta^{2k}}{2k!} + i\sum^{\infty}_{k=0}\frac{(-1)^{k+1} \theta^{2k+1}}{(2k+1)!}").next_to(equival2, RIGHT, buff=SMALL_BUFF)
        cost = MathTex(r"{\cos\theta}").next_to(serie5, DOWN*14, buff=SMALL_BUFF)
        sint = MathTex(r"{i\sin\theta}").next_to(serie5, DOWN*14, buff=SMALL_BUFF)
        plus=MathTex(r"+").next_to(serie5, DOWN*14, buff=SMALL_BUFF)
        equal=MathTex(r"=").next_to(sint,RIGHT, buff=SMALL_BUFF)
        eitheta = MathTex(r"e^{i\theta}").next_to(sint,RIGHT, buff=SMALL_BUFF)
        equal2 = MathTex(r"=").next_to(serie4,RIGHT*2, buff=SMALL_BUFF)
        eitheta2 = MathTex(r"e^{i\theta}").next_to(serie4,RIGHT, buff=SMALL_BUFF)
        equal3 = MathTex(r"=").next_to(serie4,RIGHT*2, buff=SMALL_BUFF)
        eitheta3 = MathTex(r"e^{i\theta}").next_to(serie4,RIGHT, buff=SMALL_BUFF)
        
        # Regrouper la dernière equation dans un seul groupe
        group = VGroup(cost, plus, sint, equal, eitheta2)
        
        
        
        formule.shift(RIGHT*3.8 + UP*2)
        serie1.shift(LEFT*2.5, UP*0.8)
        serie2.shift(DOWN*0.8, RIGHT*1.8)
        serie3.shift(DOWN*0.8, RIGHT*1.8)
        convi.shift(DOWN*2.3, RIGHT*3.5)
        equival.shift(UP*1, RIGHT*1.2)
        equival2.shift(DOWN, RIGHT*1.2)
        serie4.shift(RIGHT, UP*0.5)
        serie5.shift(RIGHT*1.4, DOWN*1)
        cost.shift(LEFT*0.4)
        plus.shift(RIGHT*1.7)        
        sint.shift(RIGHT*3.5)
        equal.shift(UP*2.45, RIGHT*2.1)
        eitheta.shift(UP*2.6, RIGHT*2.6)
        equal2.shift(UP*0.565, RIGHT)
        equal3.shift(DOWN*1.5, LEFT)
        eitheta2.shift(UP*0.7, RIGHT*1.6)
        eitheta3.shift(DOWN*1.35, LEFT*0.42)
        
        # Regrouper la dernière equation dans un seul groupe
        group = VGroup(cost, plus, sint, equal, eitheta2)
        

        # Animer l'apparition des labels, des flèches et du cercle
        self.play(Create(real_label), Create(imag_label))
        self.play(Create(real_arrow), Create(imag_arrow))
        self.play(Create(circle))
        self.play(Create(i_point))
        self.play(Create(un_point))
        self.play(Create(cos_point))
        self.play(Create(sin_point))
        self.play(Create(line45d))
        self.play(Create(linesin))
        self.play(Create(arc))
        self.play(Create(theta))
        self.play(Create(formule))
        
        # Attendre quelques secondes
        self.wait(1)
        
        #Transition puis attente
        self.play(FadeOut(circle), FadeOut(un_point), FadeOut(i_point), FadeOut(arc), FadeOut(theta))
        self.play(FadeOut(linesin), FadeOut(line45d), FadeOut(cos_point), FadeOut(sin_point))
        self.play(FadeOut(real_arrow), FadeOut(imag_arrow), FadeOut(real_label), FadeOut(imag_label))
        
        # Faire bouger la formule
        self.play(formule.animate.to_corner(UL, buff=1))
        
        #Démonstraton par séries partie une
        self.play(Create(serie1))
        self.play(Create(serie2))
        self.play(Create(serie3))
        self.play(Create(convi))
        
        self.wait(1.5)
        
        #Transition 
        self.play(FadeOut(formule), FadeOut(serie1), FadeOut(serie2))
        self.play(convi.animate.to_corner(UL, buff=1))
        self.play(serie3.animate.to_corner(UL, buff=2))
        
        # Démonstraton par séries partie deux
        self.play(Create(equival))
        self.play(Create(serie4))
        self.play(Create(equal2))
        self.play(Create(eitheta2))
        self.play(Create(equival2))
        self.play(Create(serie5))
        self.play(Create(equal3))
        self.play(Create(eitheta3))
        self.wait(1)
        self.play(Create(cost))
        self.play(Create(sint))
        self.play(Create(plus))
        
        #Transition Finale
        self.play(FadeOut(convi))
        self.play(FadeOut(serie3), FadeOut(serie4), FadeOut(equival), FadeOut(equal2))
        self.play(FadeOut(equival2), FadeOut(serie5), FadeOut(equal3))
        
        #Démonstration partie finale
        self.play(cost.animate.shift(UP*2.5, RIGHT*0.6))
        self.play(plus.animate.shift(UP*2.47, LEFT*0.62))
        self.play(sint.animate.shift(UP*2.5, LEFT*1.5))
        self.play(eitheta2.animate.move_to(RIGHT*0.9 + UP*0.625), eitheta3.animate.move_to(RIGHT*0.9 + UP*0.625), run_time=2)
        self.play(Create(equal))
        
        #Création du rèctangle final
        framebox1 = SurroundingRectangle(group, buff = 0.3, color=WHITE)
        
        self.play(Create(framebox1), runtime=2)

        self.wait(2)
        
        
        


        
        
        
        
        
        
    
Editor is loading...