Skip to content

Commit 51c6ebf

Browse files
committed
moved neat projects from the example folder to docs
1 parent a32302e commit 51c6ebf

File tree

1 file changed

+241
-1
lines changed

1 file changed

+241
-1
lines changed
Lines changed: 241 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,244 @@
11
NeatProjects
22
=================================
33

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

0 commit comments

Comments
 (0)