Skip to content

Commit 64d398a

Browse files
committed
# removed neat_projects.rst
and renamed shapes_images_positions.rst
1 parent 97a4ea4 commit 64d398a

File tree

5 files changed

+255
-447
lines changed

5 files changed

+255
-447
lines changed

docs/source/examples.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ Examples
33

44
.. toctree::
55

6-
examples/shapes
6+
examples/shapes_images_positions
77
examples/annotations
88
examples/plots
99
examples/text
1010
examples/formulas
1111
examples/3d
1212
examples/camera_settings
1313
examples/animations
14-
examples/neat_projects
1514
examples/advanced_projects

docs/source/examples/advanced_projects.rst

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,247 @@
11
Advanced Projects
22
=================================
33

4+
.. manim:: OpeningManimExample
5+
:quality: low
6+
7+
class OpeningManimExample(Scene):
8+
def construct(self):
9+
title = Tex("This is some \\LaTeX")
10+
basel = MathTex("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")
11+
VGroup(title, basel).arrange(DOWN)
12+
self.play(
13+
Write(title),
14+
FadeInFrom(basel, UP),
15+
)
16+
self.wait()
17+
18+
transform_title = Tex("That was a transform")
19+
transform_title.to_corner(UP + LEFT)
20+
self.play(
21+
Transform(title, transform_title),
22+
LaggedStart(*map(FadeOutAndShiftDown, basel)),
23+
)
24+
self.wait()
25+
26+
grid = NumberPlane()
27+
grid_title = Tex("This is a grid")
28+
grid_title.scale(1.5)
29+
grid_title.move_to(transform_title)
30+
31+
self.add(grid, grid_title) # Make sure title is on top of grid
32+
self.play(
33+
FadeOut(title),
34+
FadeInFromDown(grid_title),
35+
ShowCreation(grid, run_time=3, lag_ratio=0.1),
36+
)
37+
self.wait()
38+
39+
grid_transform_title = Tex(
40+
"That was a non-linear function \\\\" "applied to the grid"
41+
)
42+
grid_transform_title.move_to(grid_title, UL)
43+
grid.prepare_for_nonlinear_transform()
44+
self.play(
45+
grid.apply_function,
46+
lambda p: p
47+
+ np.array(
48+
[
49+
np.sin(p[1]),
50+
np.sin(p[0]),
51+
0,
52+
]
53+
),
54+
run_time=3,
55+
)
56+
self.wait()
57+
self.play(Transform(grid_title, grid_transform_title))
58+
self.wait()
59+
60+
61+
.. manim:: SquareToCircle
62+
:quality: low
63+
64+
class SquareToCircle(Scene):
65+
def construct(self):
66+
circle = Circle()
67+
square = Square()
68+
square.flip(RIGHT)
69+
square.rotate(-3 * TAU / 8)
70+
circle.set_fill(PINK, opacity=0.5)
71+
72+
self.play(ShowCreation(square))
73+
self.play(Transform(square, circle))
74+
self.play(FadeOut(square))
75+
76+
77+
.. manim:: WarpSquare
78+
:quality: low
79+
80+
class WarpSquare(Scene):
81+
def construct(self):
82+
square = Square()
83+
self.play(
84+
ApplyPointwiseFunction(
85+
lambda point: complex_to_R3(np.exp(R3_to_complex(point))), square
86+
)
87+
)
88+
self.wait()
89+
90+
.. manim:: WriteStuff
91+
:quality: low
92+
93+
class WriteStuff(Scene):
94+
def construct(self):
95+
example_text = Tex("This is a some text", tex_to_color_map={"text": YELLOW})
96+
example_tex = MathTex(
97+
"\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
98+
)
99+
group = VGroup(example_text, example_tex)
100+
group.arrange(DOWN)
101+
group.set_width(config["frame_width"] - 2 * LARGE_BUFF)
102+
103+
self.play(Write(example_text))
104+
self.play(Write(example_tex))
105+
self.wait()
106+
107+
.. manim:: UpdatersExample
108+
:quality: low
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+
.. manim:: VDictExample
133+
:quality: low
134+
135+
class VDictExample(Scene):
136+
def construct(self):
137+
square = Square().set_color(RED)
138+
circle = Circle().set_color(YELLOW).next_to(square, UP)
139+
140+
# create dict from list of tuples each having key-mobject pair
141+
pairs = [("s", square), ("c", circle)]
142+
my_dict = VDict(pairs, show_keys=True)
143+
144+
# display it just like a VGroup
145+
self.play(ShowCreation(my_dict))
146+
self.wait()
147+
148+
text = Tex("Some text").set_color(GREEN).next_to(square, DOWN)
149+
150+
# add a key-value pair by wrapping it in a single-element list of tuple
151+
# after attrs branch is merged, it will be easier like `.add(t=text)`
152+
my_dict.add([("t", text)])
153+
self.wait()
154+
155+
rect = Rectangle().next_to(text, DOWN)
156+
# can also do key assignment like a python dict
157+
my_dict["r"] = rect
158+
159+
# access submobjects like a python dict
160+
my_dict["t"].set_color(PURPLE)
161+
self.play(my_dict["t"].scale, 3)
162+
self.wait()
163+
164+
# also supports python dict styled reassignment
165+
my_dict["t"] = Tex("Some other text").set_color(BLUE)
166+
self.wait()
167+
168+
# remove submoject by key
169+
my_dict.remove("t")
170+
self.wait()
171+
172+
self.play(Uncreate(my_dict["s"]))
173+
self.wait()
174+
175+
self.play(FadeOut(my_dict["c"]))
176+
self.wait()
177+
178+
self.play(FadeOutAndShift(my_dict["r"], DOWN))
179+
self.wait()
180+
181+
# you can also make a VDict from an existing dict of mobjects
182+
plain_dict = {
183+
1: Integer(1).shift(DOWN),
184+
2: Integer(2).shift(2 * DOWN),
185+
3: Integer(3).shift(3 * DOWN),
186+
}
187+
188+
vdict_from_plain_dict = VDict(plain_dict)
189+
vdict_from_plain_dict.shift(1.5 * (UP + LEFT))
190+
self.play(ShowCreation(vdict_from_plain_dict))
191+
192+
# you can even use zip
193+
vdict_using_zip = VDict(zip(["s", "c", "r"], [Square(), Circle(), Rectangle()]))
194+
vdict_using_zip.shift(1.5 * RIGHT)
195+
self.play(ShowCreation(vdict_using_zip))
196+
self.wait()
197+
198+
199+
.. manim:: VariableExample
200+
:quality: low
201+
202+
class VariableExample(Scene):
203+
def construct(self):
204+
var = 0.5
205+
on_screen_var = Variable(var, Text("var"), num_decimal_places=3)
206+
207+
# You can also change the colours for the label and value
208+
on_screen_var.label.set_color(RED)
209+
on_screen_var.value.set_color(GREEN)
210+
211+
self.play(Write(on_screen_var))
212+
# The above line will just display the variable with
213+
# its initial value on the screen. If you also wish to
214+
# update it, you can do so by accessing the `tracker` attribute
215+
self.wait()
216+
var_tracker = on_screen_var.tracker
217+
var = 10.5
218+
self.play(var_tracker.set_value, var)
219+
self.wait()
220+
221+
int_var = 0
222+
on_screen_int_var = Variable(
223+
int_var, Text("int_var"), var_type=Integer
224+
).next_to(on_screen_var, DOWN)
225+
on_screen_int_var.label.set_color(RED)
226+
on_screen_int_var.value.set_color(GREEN)
227+
228+
self.play(Write(on_screen_int_var))
229+
self.wait()
230+
var_tracker = on_screen_int_var.tracker
231+
var = 10.5
232+
self.play(var_tracker.set_value, var)
233+
self.wait()
234+
235+
# If you wish to have a somewhat more complicated label for your
236+
# variable with subscripts, superscripts, etc. the default class
237+
# for the label is MathTex
238+
subscript_label_var = 10
239+
on_screen_subscript_var = Variable(subscript_label_var, "{a}_{i}").next_to(
240+
on_screen_int_var, DOWN
241+
)
242+
self.play(Write(on_screen_subscript_var))
243+
self.wait()
244+
4245
.. manim:: ExampleSineCurve
5246

6247
class ExampleSineCurve(Scene):

0 commit comments

Comments
 (0)