1+ from manim import *
2+
3+ class FunctionTable (Scene ):
4+ def construct (self ):
5+ title = MathTex (r"f: \mathbb{R} \rightarrow \mathbb{R}" )
6+ func_def = MathTex (r"f(x) = x^2" )
7+
8+ title .to_edge (UP , buff = 1.0 )
9+ func_def .next_to (title , DOWN )
10+
11+ self .play (Write (title ))
12+ self .play (Write (func_def ))
13+ self .wait (1 )
14+
15+ # ERASE INTRO
16+ self .play (
17+ FadeOut (title ),
18+ FadeOut (func_def )
19+ )
20+ v_line_start = UP * 3
21+ v_line_end = DOWN * 3
22+
23+
24+ h_line_y = 2.0
25+
26+ v_line = Line (v_line_start , v_line_end )
27+
28+ h_line = Line (LEFT * 4 , RIGHT * 4 ).move_to ([0 , h_line_y , 0 ])
29+
30+ header_y = h_line_y + 0.6
31+ col_offset = 2.0
32+
33+ h_x = MathTex ("x" ).scale (1.2 ).move_to ([- col_offset , header_y , 0 ])
34+ h_fx = MathTex ("f(x)" ).scale (1.2 ).move_to ([col_offset , header_y , 0 ])
35+
36+ self .play (
37+ Create (v_line ),
38+ Create (h_line ),
39+ Write (h_x ),
40+ Write (h_fx )
41+ )
42+
43+ x_vals = [- 3 , - 2 , - 1 , 0 , 1 , 2 ]
44+ rows = []
45+
46+ row_start_y = h_line_y - 0.8
47+ row_spacing = 0.8
48+
49+ for i , x in enumerate (x_vals ):
50+ fx = x ** 2
51+
52+ current_y = row_start_y - (i * row_spacing )
53+
54+ t_x = MathTex (str (x ))
55+ t_fx = MathTex (str (fx ))
56+
57+ t_x .move_to ([- col_offset , current_y , 0 ])
58+ t_fx .move_to ([col_offset , current_y , 0 ])
59+
60+ rows .append (VGroup (t_x , t_fx ))
61+
62+ for row in rows :
63+ self .play (Write (row ), run_time = 0.3 )
64+
65+ self .wait (2 )
66+
67+ class ParallelLines (Scene ):
68+ def construct (self ):
69+ ax_top = NumberLine (
70+ x_range = [- 4 , 4 , 1 ],
71+ length = 10 ,
72+ color = BLUE ,
73+ include_numbers = True ,
74+ label_direction = UP ,
75+ ).shift (UP * 1.5 )
76+
77+ ax_bottom = NumberLine (
78+ x_range = [- 1 , 10 , 1 ],
79+ length = 10 ,
80+ color = RED ,
81+ include_numbers = True ,
82+ label_direction = DOWN ,
83+ ).shift (DOWN * 1.5 )
84+
85+ lab_top = MathTex ("x" ).next_to (ax_top , UP , buff = 0.5 )
86+
87+ lab_bot = MathTex ("f(x) = x^2" ).next_to (ax_bottom , UP , buff = 0.3 ).add_background_rectangle ()
88+
89+ self .play (Create (ax_top ), Write (lab_top ))
90+ self .play (Create (ax_bottom ), Write (lab_bot ))
91+
92+ x_values = [- 3 , - 2 , - 1 , 0 , 1 , 2 ]
93+
94+ for x in x_values :
95+ val_x = x
96+ val_y = x ** 2
97+
98+ dot_top = Dot (ax_top .n2p (val_x ), color = BLUE )
99+ dot_bot = Dot (ax_bottom .n2p (val_y ), color = RED )
100+
101+ arrow = Arrow (dot_top .get_center (), dot_bot .get_center (), buff = 0.1 , color = YELLOW )
102+
103+ self .play (FadeIn (dot_top ), run_time = 0.3 )
104+ self .play (GrowArrow (arrow ), FadeIn (dot_bot ), run_time = 0.5 )
105+ self .wait (0.3 )
106+ self .play (FadeOut (arrow ), run_time = 0.2 )
107+
108+ self .wait (2 )
109+
110+ class CartesianConstruction (Scene ):
111+ def construct (self ):
112+ # 1. Create Axes
113+ axes = Axes (
114+ x_range = [- 4 , 4 , 1 ],
115+ y_range = [- 1 , 10 , 1 ],
116+ x_length = 7 ,
117+ y_length = 6 ,
118+ axis_config = {"include_numbers" : True },
119+ )
120+
121+ labels = axes .get_axis_labels (x_label = "x" , y_label = "f(x)" )
122+
123+ self .play (Create (axes ), Write (labels ))
124+ self .wait (0.5 )
125+
126+ x_vals = [- 3 , - 2 , - 1 , 0 , 1 , 2 ]
127+ points = VGroup ()
128+
129+ for x in x_vals :
130+ y = x ** 2
131+
132+ pt_on_x = axes .c2p (x , 0 )
133+ pt_on_y = axes .c2p (0 , y )
134+ final_pt = axes .c2p (x , y )
135+
136+ dot_x = Dot (pt_on_x , color = BLUE , radius = 0.08 )
137+ dot_y = Dot (pt_on_y , color = RED , radius = 0.08 )
138+
139+ line_vert = DashedLine (pt_on_x , final_pt , color = BLUE_E )
140+ line_horiz = DashedLine (pt_on_y , final_pt , color = RED_E )
141+
142+ dot_final = Dot (final_pt , color = YELLOW )
143+ points .add (dot_final )
144+
145+ self .play (FadeIn (dot_x ), FadeIn (dot_y ), run_time = 0.3 )
146+ self .play (Create (line_vert ), Create (line_horiz ), run_time = 0.5 )
147+ self .play (FadeIn (dot_final ), run_time = 0.2 )
148+
149+ self .play (FadeOut (dot_x ), FadeOut (dot_y ), FadeOut (line_vert ), FadeOut (line_horiz ), run_time = 0.2 )
150+
151+ self .wait (1 )
152+
153+ graph = axes .plot (lambda x : x ** 2 , color = YELLOW )
154+
155+
156+ self .play (Create (graph ), run_time = 3 )
157+
158+ self .play (graph .animate .set_stroke (width = 6 ))
159+ self .wait (2 )
160+
161+ from manim import *
162+
163+ class ParaboloidPlot (ThreeDScene ):
164+ def construct (self ):
165+ axes = ThreeDAxes (
166+ x_range = [- 3 , 3 , 1 ],
167+ y_range = [- 3 , 3 , 1 ],
168+ z_range = [- 1 , 9 , 1 ],
169+ x_length = 6 ,
170+ y_length = 6 ,
171+ z_length = 5
172+ )
173+
174+ labels = axes .get_axis_labels (
175+ x_label = "x" ,
176+ y_label = "y" ,
177+ z_label = "g(x,y)"
178+ )
179+
180+ surface = Surface (
181+ lambda u , v : axes .c2p (u , v , u ** 2 + v ** 2 ),
182+ u_range = [- 2.5 , 2.5 ],
183+ v_range = [- 2.5 , 2.5 ],
184+ resolution = (30 , 30 ),
185+ )
186+
187+ surface .set_style (fill_opacity = 0.6 , stroke_color = BLUE )
188+ surface .set_fill_by_checkerboard (BLUE , BLUE_E , opacity = 0.6 )
189+
190+ func_text = MathTex (r"g(x,y) = x^2 + y^2" )
191+ func_text .to_corner (UL )
192+
193+ self .set_camera_orientation (phi = 60 * DEGREES , theta = - 45 * DEGREES )
194+
195+ self .add (axes , labels )
196+
197+ self .add_fixed_in_frame_mobjects (func_text )
198+
199+ self .play (Create (surface ), run_time = 2 )
200+
201+ self .begin_ambient_camera_rotation (rate = 0.2 )
202+ self .wait (9 )
203+ self .stop_ambient_camera_rotation ()
204+
205+ class FourDimensionProblem (ThreeDScene ):
206+ def construct (self ):
207+ self .set_camera_orientation (phi = 75 * DEGREES , theta = - 45 * DEGREES )
208+
209+ ax_x = Arrow3D (start = ORIGIN , end = RIGHT * 4 , color = BLUE )
210+ lab_x = MathTex (r"\text{Re}(z)" ).next_to (ax_x .get_end (), RIGHT ).rotate (PI / 2 , axis = RIGHT )
211+
212+ ax_y = Arrow3D (start = ORIGIN , end = UP * 4 , color = BLUE )
213+ lab_y = MathTex (r"\text{Im}(z)" ).next_to (ax_y .get_end (), UP ).rotate (PI / 2 , axis = RIGHT )
214+
215+ ax_z = Arrow3D (start = ORIGIN , end = OUT * 4 , color = RED )
216+ lab_z = MathTex (r"\text{Re}(f(z))" ).next_to (ax_z .get_end (), OUT ).rotate (PI / 2 , axis = RIGHT )
217+
218+ ax_w = Arrow3D (start = ORIGIN , end = np .array ([2 , 2 , 2 ]), color = RED )
219+ lab_w = MathTex (r"\text{Im}(f(z))" ).next_to (ax_w .get_end (), UP ).rotate (PI / 2 , axis = RIGHT )
220+
221+ text_1 = Text ("1. Real Input" , font_size = 24 ).to_corner (UL )
222+ text_2 = Text ("2. Imaginary Input" , font_size = 24 ).to_corner (UL )
223+ text_3 = Text ("3. Real Output" , font_size = 24 ).to_corner (UL )
224+ text_4 = Text ("4. Imaginary Output...?" , font_size = 24 , color = RED ).to_corner (UL )
225+
226+ self .add_fixed_in_frame_mobjects (text_1 )
227+
228+ self .play (Create (ax_x ), Write (lab_x ))
229+ self .wait (0.5 )
230+
231+ self .remove (text_1 )
232+ self .add_fixed_in_frame_mobjects (text_2 )
233+ self .play (Create (ax_y ), Write (lab_y ))
234+ self .wait (0.5 )
235+
236+ self .remove (text_2 )
237+ self .add_fixed_in_frame_mobjects (text_3 )
238+ self .play (Create (ax_z ), Write (lab_z ))
239+ self .wait (1 )
240+
241+ self .remove (text_3 )
242+ self .add_fixed_in_frame_mobjects (text_4 )
243+
244+ self .play (Create (ax_w ), Write (lab_w ))
245+
246+ w_group = VGroup (ax_w , lab_w )
247+
248+ self .play (Rotate (w_group , angle = PI , axis = UP ), run_time = 1 )
249+ self .wait (0.3 )
250+
251+ self .play (Rotate (w_group , angle = PI / 2 , axis = RIGHT ), run_time = 1 )
252+ self .wait (0.3 )
253+
254+ self .play (Rotate (w_group , angle = 2 * PI , axis = OUT ), run_time = 2 )
255+
256+ failure_text = MathTex (r"\text{No Space!}" , color = RED ).move_to (ax_w .get_end ())
257+ self .add_fixed_in_frame_mobjects (failure_text )
258+
259+ self .play (
260+ Wiggle (w_group ),
261+ FadeIn (failure_text , shift = UP )
262+ )
263+ self .wait (1 )
264+
265+ self .play (FadeOut (w_group ), FadeOut (failure_text ))
266+ self .wait (1 )
0 commit comments