13
13
# Use -r <number> to specify a resolution (for example, -r 1080
14
14
# for a 1920x1080 video)
15
15
16
- from manim import *
17
-
18
16
19
- class Dot1 (Scene ):
17
+ class OpeningManimExample (Scene ):
20
18
def construct (self ):
21
- dot = Dot ().set_color (GREEN )
22
- self .add (dot )
23
- self .wait (1 )
19
+ title = Tex ("This is some \\ LaTeX" )
20
+ basel = MathTex ("\\ sum_{n=1}^\\ infty " "\\ frac{1}{n^2} = \\ frac{\\ pi^2}{6}" )
21
+ VGroup (title , basel ).arrange (DOWN )
22
+ self .play (
23
+ Write (title ),
24
+ FadeInFrom (basel , UP ),
25
+ )
26
+ self .wait ()
27
+
28
+ transform_title = Tex ("That was a transform" )
29
+ transform_title .to_corner (UP + LEFT )
30
+ self .play (
31
+ Transform (title , transform_title ),
32
+ LaggedStart (* map (FadeOutAndShiftDown , basel )),
33
+ )
34
+ self .wait ()
35
+
36
+ grid = NumberPlane ()
37
+ grid_title = Tex ("This is a grid" )
38
+ grid_title .scale (1.5 )
39
+ grid_title .move_to (transform_title )
40
+
41
+ self .add (grid , grid_title ) # Make sure title is on top of grid
42
+ self .play (
43
+ FadeOut (title ),
44
+ FadeInFromDown (grid_title ),
45
+ ShowCreation (grid , run_time = 3 , lag_ratio = 0.1 ),
46
+ )
47
+ self .wait ()
48
+
49
+ grid_transform_title = Tex (
50
+ "That was a non-linear function \\ \\ " "applied to the grid"
51
+ )
52
+ grid_transform_title .move_to (grid_title , UL )
53
+ grid .prepare_for_nonlinear_transform ()
54
+ self .play (
55
+ grid .apply_function ,
56
+ lambda p : p
57
+ + np .array (
58
+ [
59
+ np .sin (p [1 ]),
60
+ np .sin (p [0 ]),
61
+ 0 ,
62
+ ]
63
+ ),
64
+ run_time = 3 ,
65
+ )
66
+ self .wait ()
67
+ self .play (Transform (grid_title , grid_transform_title ))
68
+ self .wait ()
24
69
25
70
26
71
class SquareToCircle (Scene ):
@@ -45,3 +90,43 @@ def construct(self):
45
90
)
46
91
)
47
92
self .wait ()
93
+
94
+
95
+ class WriteStuff (Scene ):
96
+ def construct (self ):
97
+ example_text = Tex ("This is a some text" , tex_to_color_map = {"text" : YELLOW })
98
+ example_tex = MathTex (
99
+ "\\ sum_{k=1}^\\ infty {1 \\ over k^2} = {\\ pi^2 \\ over 6}" ,
100
+ )
101
+ group = VGroup (example_text , example_tex )
102
+ group .arrange (DOWN )
103
+ group .set_width (config ["frame_width" ] - 2 * LARGE_BUFF )
104
+
105
+ self .play (Write (example_text ))
106
+ self .play (Write (example_tex ))
107
+ self .wait ()
108
+
109
+
110
+ class UpdatersExample (Scene ):
111
+ def construct (self ):
112
+ decimal = DecimalNumber (
113
+ 0 ,
114
+ show_ellipsis = True ,
115
+ num_decimal_places = 3 ,
116
+ include_sign = True ,
117
+ )
118
+ square = Square ().to_edge (UP )
119
+
120
+ decimal .add_updater (lambda d : d .next_to (square , RIGHT ))
121
+ decimal .add_updater (lambda d : d .set_value (square .get_center ()[1 ]))
122
+ self .add (square , decimal )
123
+ self .play (
124
+ square .to_edge ,
125
+ DOWN ,
126
+ rate_func = there_and_back ,
127
+ run_time = 5 ,
128
+ )
129
+ self .wait ()
130
+
131
+
132
+ # See many more examples at https://manimce.readthedocs.io/en/latest/examples.html
0 commit comments