Skip to content
The Chat Archive
gpt-4.1-mini-2025-04-14· OpenAI WildChat-4.8M (AI2)

Generate a Manim animation for the following description. Output ONLY the Python code,…

  1. User

    Generate a Manim animation for the following description. Output ONLY the Python code, wrapped in triple backticks (python ... ). Description: Explain Young's double slit experiment

    NOTE!!!: Make sure the objects or text in the generated code are not overlapping at any point in the video. Make sure that each scene is properly cleaned up before transitioning to the next scene. IMPORTANT: Never assign a value to AUDIO*_DURATION placeholders. Only use them as arguments in function calls, e.g., self.wait(AUDIO1_DURATION). Do not write lines like AUDIO1_DURATION = ... or AUDIO2_DURATION = ... in the code. Only use rate functions that exist in manim.utils.rate_functions for Manim v0.18.1, such as linear, smooth, rush_into, rush_from, there_and_back, ease_in_sine, ease_out_sine, etc. Do NOT use ease_in or any function that does not exist. Only use color constants that are defined in Manim v0.18.1, such as BLUE, RED, GREEN, YELLOW, WHITE, BLACK, etc. Do NOT use colors like DARK_GREEN or any color that is not defined by default.

  2. Assistant
    from manim import *
    from manim.utils.rate_functions import smooth, ease_out_sine
    
    class YoungsDoubleSlitExperiment(Scene):
        def construct(self):
            # Scene 1: Title Introduction
            title = Text("Young's Double Slit Experiment", font_size=48, color=WHITE)
            self.play(Write(title), run_time=2)
            self.wait(1)
            self.play(FadeOut(title), run_time=1.5)
    
            # Scene 2: Setup Explanation
            # Show screen setup
            setup_text = Text("Setup", font_size=36).to_edge(UP)
            self.play(Write(setup_text), run_time=1.5)
    
            # Draw light source
            source = Circle(radius=0.3, color=YELLOW, fill_opacity=1).shift(3.5*LEFT + 1.5*UP)
            source_label = Text("Light Source", font_size=24).next_to(source, DOWN)
            self.play(FadeIn(source), Write(source_label), run_time=2)
    
            # Draw barrier with two slits
            barrier = Rectangle(height=4, width=0.2, color=BLUE).next_to(source, RIGHT, buff=2)
            slit_distance = 0.5
            slit1 = Rectangle(height=0.4, width=0.05, fill_color=BLACK, fill_opacity=1).move_to(barrier.get_center() + UP*slit_distance)
            slit2 = Rectangle(height=0.4, width=0.05, fill_color=BLACK, fill_opacity=1).move_to(barrier.get_center() + DOWN*slit_distance)
            barrier_group = VGroup(barrier, slit1, slit2)
    
            self.play(FadeIn(barrier_group), run_time=2)
    
            slit_text = Text("Double Slits", font_size=24).next_to(barrier_group, RIGHT)
            self.play(Write(slit_text), run_time=1.5)
            
            self.wait(1)
    
            # Clean up setup text only (keep the setup objects)
            self.play(FadeOut(setup_text), FadeOut(slit_text), run_time=1)
    
            # Scene 3: Wavefront demonstration
            wavefronts = VGroup()
            for i in range(5):
                circle1 = Circle(radius=0.2 + i*0.4, color=YELLOW, stroke_width=2).move_to(slit1.get_center())
                circle2 = Circle(radius=0.2 + i*0.4, color=YELLOW, stroke_width=2).move_to(slit2.get_center())
                wavefronts.add(circle1, circle2)
    
            self.play(LaggedStartMap(ShowCreation, wavefronts, lag_ratio=0.4, run_time=4))
    
            self.wait(0.5)
    
            # Animate waves spreading from slits by pulsating the wavefronts
            def wave_pulse(mob, alpha):
                for i, c in enumerate(mob):
                    scale_factor = 1 + 0.05 * (alpha*20 - i*4)
                    scale_factor = max(scale_factor, 1)
                    c.set_stroke(width=2 * scale_factor)
            self.play(UpdateFromAlphaFunc(wavefronts, wave_pulse), run_time=3)
    
            self.wait(1)
            self.play(FadeOut(wavefronts), FadeOut(source), FadeOut(source_label), FadeOut(barrier_group), run_time=1.5)
    
            # Scene 4: Interference Pattern on Screen
            screen_text = Text("Interference Pattern", font_size=36).to_edge(UP)
            self.play(Write(screen_text), run_time=1.5)
    
            # Draw screen
            screen = Line(start=5*RIGHT+3*UP, end=5*RIGHT+3*DOWN, color=BLUE, stroke_width=6)
            self.play(Create(screen), run_time=2)
    
            # Draw two coherent point sources representing slits
            slit_dot1 = Dot(point=2*RIGHT + 0.5*UP, color=YELLOW)
            slit_dot2 = Dot(point=2*RIGHT + 0.5*DOWN, color=YELLOW)
            self.play(FadeIn(slit_dot1), FadeIn(slit_dot2), run_time=1.5)
    
            # Animate wavefront circles from each slit to screen
            waves_source1 = VGroup(*[Circle(radius=r, color=YELLOW, stroke_width=1).move_to(slit_dot1.get_center()) for r in [0.3,0.6,0.9,1.2,1.5]])
            waves_source2 = VGroup(*[Circle(radius=r, color=YELLOW, stroke_width=1).move_to(slit_dot2.get_center()) for r in [0.3,0.6,0.9,1.2,1.5]])
    
            self.play(LaggedStartMap(ShowCreation, waves_source1, lag_ratio=0.4), LaggedStartMap(ShowCreation, waves_source2, lag_ratio=0.4), run_time=3)
    
            # Fade out wavefronts for clarity
            self.play(FadeOut(waves_source1), FadeOut(waves_source2))
    
            # Draw fringes representing constructive and destructive interference on screen
            fringes = VGroup()
            num_fringes = 11
            height_spacing = 0.6
            for i in range(num_fringes):
                y = 3 - i * height_spacing
                color = WHITE if i % 2 == 0 else BLACK
                line = Rectangle(width=0.1, height=height_spacing*0.9, fill_color=color, fill_opacity=1, stroke_width=0)
                line.move_to(np.array([5, y - height_spacing/2, 0]))
                fringes.add(line)
    
            self.play(FadeIn(fringes), run_time=2)
    
            self.wait(1)
    
            explanation = Text("Bright and dark fringes on the screen due to interference", font_size=24).to_edge(DOWN)
            self.play(Write(explanation), run_time=2)
            self.wait(2)
    
            # Clean up entire scene
            self.play(
                FadeOut(screen_text),
                FadeOut(screen),
                FadeOut(slit_dot1),
                FadeOut(slit_dot2),
                FadeOut(fringes),
                FadeOut(explanation),
                run_time=1.5
            )
    
            # Scene 5: Summary
            summary_title = Text("Summary", font_size=40).to_edge(UP)
            self.play(Write(summary_title), run_time=1.5)
    
            points = BulletedList(
                "Light passes through two narrow slits",
                "Each slit acts as a coherent wave source",
                "Waves interfere causing bright and dark fringes",
                "Confirms wave nature of light",
                font_size=28,
                dot_color=YELLOW,
                color=WHITE,
            ).scale(0.9).to_edge(DOWN)
    
            self.play(Write(points, run_time=3))
            self.wait(3)
    
            self.play(FadeOut(summary_title), FadeOut(points), run_time=1.5)