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,…
- User
Generate a Manim animation for the following description. Output ONLY the Python code, wrapped in triple backticks (
python ...). Description: gravityNOTE!!!: 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.
- Assistant
from manim import * class Gravity(Scene): def construct(self): # Scene 1: Title title = Text("Gravity").scale(1.5) self.play(Write(title)) self.wait(AUDIO1_DURATION) self.play(FadeOut(title)) # Scene 2: Ball falling under gravity ball = Dot(point=3*UP, radius=0.3, color=BLUE) ground = Line(6*LEFT, 6*RIGHT).shift(3*DOWN) self.add(ground, ball) # Simulate falling motion self.play(ball.animate.move_to(ground.get_center() + UP * 0.3), run_time=2, rate_func=rate_functions.ease_in) self.wait(AUDIO2_DURATION) self.play(FadeOut(ball), FadeOut(ground)) # Scene 3: Display formula for gravitational acceleration formula = MathTex("s(t) = \\frac{1}{2}gt^{2}").to_edge(UP) g_text = Tex("where ", "g", " is gravitational acceleration").next_to(formula, DOWN) g_text[1].set_color(YELLOW) self.play(Write(formula)) self.wait(AUDIO3_DURATION) self.play(Write(g_text)) self.wait(AUDIO4_DURATION) self.play(FadeOut(formula), FadeOut(g_text)) # Scene 4: Show a ball falling with trajectory path ball = Dot(radius=0.3, color=GREEN).to_edge(UP) path = VMobject(color=GREEN) self.add(ball, path) dt = 0.05 g = 9.8 initial_pos = ball.get_center() times = [] points = [] for i in range(40): t = i * dt x = 0 y = initial_pos[1] - 0.5 * g * t**2 point = np.array([x, y, 0]) points.append(point) times.append(t) # Animate the ball and draw the falling path def update_path(mob): mob.set_points_smoothly(points[:int(self.time / dt) + 1]) ball.add_updater(lambda m: m.move_to(points[min(int(self.time / dt), len(points)-1)])) path.add_updater(update_path) self.wait(AUDIO5_DURATION) ball.remove_updater(lambda m: m.move_to(points[min(int(self.time / dt), len(points)-1)])) path.remove_updater(update_path) self.play(FadeOut(ball), FadeOut(path))