Skip to content

Commit 3b6519a

Browse files
Restore examples/basic.py (#560)
* Restore examples/basic.py * Update example_scenes/basic.py Co-authored-by: kolibril13 <[email protected]> * Update example_scenes/basic.py Co-authored-by: kolibril13 <[email protected]> * Format basic.py * Update example_scenes/basic.py Co-authored-by: kolibril13 <[email protected]> * Format basic.py * Remove extra comment Co-authored-by: kolibril13 <[email protected]>
1 parent db4fd9f commit 3b6519a

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

example_scenes/basic.py

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,59 @@
1313
# Use -r <number> to specify a resolution (for example, -r 1080
1414
# for a 1920x1080 video)
1515

16-
from manim import *
17-
1816

19-
class Dot1(Scene):
17+
class OpeningManimExample(Scene):
2018
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()
2469

2570

2671
class SquareToCircle(Scene):
@@ -45,3 +90,43 @@ def construct(self):
4590
)
4691
)
4792
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

Comments
 (0)