Skip to content

Commit d586b11

Browse files
authored
Merge pull request #576 from MysaaJava/newExamples
New examples
2 parents 1e39b37 + 838cd7f commit d586b11

File tree

14 files changed

+397
-138
lines changed

14 files changed

+397
-138
lines changed

docs/source/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Example Gallery
2-
============
2+
===============
33

44
.. toctree::
55

docs/source/examples/3d.rst

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
3D Scenes
22
=================================
33

4-
.. manim:: Example3DNo1
4+
.. manim:: ThreeDSphere
55
:save_last_frame:
66

7-
class Example3DNo1(ThreeDScene):
7+
class ThreeDSphere(ThreeDScene):
88
def construct(self):
99
axes = ThreeDAxes()
1010
sphere = ParametricSurface(
@@ -18,10 +18,10 @@
1818
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
1919
self.add(axes, sphere)
2020

21-
.. manim:: Example3DLightSourcePosition
21+
.. manim:: ThreeDLightSourcePosition
2222
:save_last_frame:
2323

24-
class Example3DLightSourcePosition(ThreeDScene):
24+
class ThreeDLightSourcePosition(ThreeDScene):
2525
def construct(self):
2626
axes = ThreeDAxes()
2727
sphere = ParametricSurface(
@@ -36,9 +36,9 @@
3636
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
3737
self.add(axes, sphere)
3838

39-
.. manim:: Example3DNo3
39+
.. manim:: ThreeDCameraRotation
4040

41-
class Example3DNo3(ThreeDScene):
41+
class ThreeDCameraRotation(ThreeDScene):
4242
def construct(self):
4343
axes = ThreeDAxes()
4444
circle=Circle()
@@ -50,9 +50,9 @@
5050
self.move_camera(phi=75 * DEGREES, theta=30 * DEGREES)
5151
self.wait()
5252

53-
.. manim:: Example3DNo4
53+
.. manim:: ThreeDCameraIllusionRotation
5454

55-
class Example3DNo4(ThreeDScene):
55+
class ThreeDCameraIllusionRotation(ThreeDScene):
5656
def construct(self):
5757
axes = ThreeDAxes()
5858
circle=Circle()
@@ -62,10 +62,10 @@
6262
self.wait(PI)
6363
self.stop_3dillusion_camera_rotation()
6464

65-
.. manim:: Example3DNo5
65+
.. manim:: ThreeDParametricSpring
6666
:save_last_frame:
6767

68-
class Example3DNo5(ThreeDScene):
68+
class ThreeDParametricSpring(ThreeDScene):
6969
def construct(self):
7070
curve1 = ParametricFunction(
7171
lambda u: np.array([
@@ -79,3 +79,54 @@
7979
self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)
8080
self.wait()
8181

82+
.. manim:: ThreeDFunctionPlot
83+
84+
class ThreeDFunctionPlot(ThreeDScene):
85+
def construct(self):
86+
resolution_fa = 22
87+
self.set_camera_orientation(phi=75 * DEGREES, theta=-30 * DEGREES)
88+
89+
def param_plane(u, v):
90+
x = u
91+
y = v
92+
z = 0
93+
return np.array([x, y, z])
94+
95+
plane = ParametricSurface(
96+
param_plane,
97+
resolution=(resolution_fa, resolution_fa),
98+
v_min=-2,
99+
v_max=+2,
100+
u_min=-2,
101+
u_max=+2,
102+
)
103+
plane.scale_about_point(2, ORIGIN)
104+
105+
def param_gauss(u, v):
106+
x = u
107+
y = v
108+
d = np.sqrt(x * x + y * y)
109+
sigma, mu = 0.4, 0.0
110+
z = np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))
111+
return np.array([x, y, z])
112+
113+
gauss_plane = ParametricSurface(
114+
param_gauss,
115+
resolution=(resolution_fa, resolution_fa),
116+
v_min=-2,
117+
v_max=+2,
118+
u_min=-2,
119+
u_max=+2,
120+
)
121+
122+
gauss_plane.scale_about_point(2, ORIGIN)
123+
gauss_plane.set_style(fill_opacity=1)
124+
gauss_plane.set_style(stroke_color=GREEN)
125+
gauss_plane.set_fill_by_checkerboard(GREEN, BLUE, opacity=0.1)
126+
127+
axes = ThreeDAxes()
128+
129+
self.add(axes)
130+
self.play(Write(plane))
131+
self.play(Transform(plane, gauss_plane))
132+
self.wait()

docs/source/examples/advanced_projects.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Advanced Projects
22
=================================
33

4-
.. manim:: OpeningManimExample
4+
.. manim:: OpeningManim
55
:ref_classes: Tex MathTex NumberPlane
66

7-
class OpeningManimExample(Scene):
7+
class OpeningManim(Scene):
88
def construct(self):
99
title = Tex("This is some \\LaTeX")
1010
basel = MathTex("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")
@@ -19,7 +19,7 @@ Advanced Projects
1919
transform_title.to_corner(UP + LEFT)
2020
self.play(
2121
Transform(title, transform_title),
22-
LaggedStart(*map(FadeOutAndShiftDown, basel)),
22+
LaggedStart(*map(lambda obj: FadeOutAndShift(obj, direction=DOWN), basel)),
2323
)
2424
self.wait()
2525
@@ -31,7 +31,7 @@ Advanced Projects
3131
self.add(grid, grid_title) # Make sure title is on top of grid
3232
self.play(
3333
FadeOut(title),
34-
FadeInFromDown(grid_title),
34+
FadeInFrom(grid_title, direction=DOWN),
3535
ShowCreation(grid, run_time=3, lag_ratio=0.1),
3636
)
3737
self.wait()
@@ -104,10 +104,10 @@ Advanced Projects
104104
self.play(Write(example_tex))
105105
self.wait()
106106

107-
.. manim:: UpdatersExample
107+
.. manim:: SquareMovingWithUpdaters
108108
:quality: low
109109

110-
class UpdatersExample(Scene):
110+
class SquareMovingWithUpdaters(Scene):
111111
def construct(self):
112112
decimal = DecimalNumber(
113113
0,
@@ -129,10 +129,10 @@ Advanced Projects
129129
self.wait()
130130

131131

132-
.. manim:: VDictExample
132+
.. manim:: ShapesWithVDics
133133
:quality: low
134134

135-
class VDictExample(Scene):
135+
class ShapesWithVDics(Scene):
136136
def construct(self):
137137
square = Square().set_color(RED)
138138
circle = Circle().set_color(YELLOW).next_to(square, UP)
@@ -196,10 +196,10 @@ Advanced Projects
196196
self.wait()
197197

198198

199-
.. manim:: VariableExample
199+
.. manim:: VariablesWithValueTracker
200200
:quality: low
201201

202-
class VariableExample(Scene):
202+
class VariablesWithValueTracker(Scene):
203203
def construct(self):
204204
var = 0.5
205205
on_screen_var = Variable(var, Text("var"), num_decimal_places=3)
@@ -242,9 +242,9 @@ Advanced Projects
242242
self.play(Write(on_screen_subscript_var))
243243
self.wait()
244244

245-
.. manim:: ExampleSineCurve
245+
.. manim:: SineCurvePlot
246246

247-
class ExampleSineCurve(Scene):
247+
class SineCurvePlot(Scene):
248248
# contributed by heejin_park, https://infograph.tistory.com/230
249249
def construct(self):
250250
self.show_axis()

docs/source/examples/animations.rst

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Some more examples will come soon here!
1010
Updaters
1111
##########
1212

13-
.. manim:: Updater1Example
13+
.. manim:: RotationUpdater
1414

15-
class Updater1Example(Scene):
15+
class RotationUpdater(Scene):
1616
def construct(self):
1717
def my_rotation_updater(mobj,dt):
1818
mobj.rotate_about_origin(dt)
@@ -22,9 +22,9 @@ Updaters
2222
self.add(line_reference, line_moving)
2323
self.wait(PI)
2424

25-
.. manim:: Updater2Example
25+
.. manim:: RotationUpdater2
2626

27-
class Updater2Example(Scene):
27+
class RotationUpdater2(Scene):
2828
def construct(self):
2929
def updater_forth(mobj, dt):
3030
mobj.rotate_about_origin(dt)
@@ -41,9 +41,9 @@ Updaters
4141
line_moving.remove_updater(updater_back)
4242
self.wait(0.5)
4343

44-
.. manim:: Example3
44+
.. manim:: NumberLinePointer
4545

46-
class Example3(Scene):
46+
class NumberLinePointer(Scene):
4747
def construct(self):
4848
number_line = NumberLine() ##with all your parameters and stuff
4949
pointer = Vector(DOWN)
@@ -57,10 +57,11 @@ Updaters
5757
self.play(pointer_value.set_value, 5)
5858
self.wait()
5959
self.play(pointer_value.set_value, 3)
60+
self.wait()
6061

61-
.. manim:: Example4
62+
.. manim:: PointWithTrace
6263

63-
class Example4(Scene):
64+
class PointWithTrace(Scene):
6465
def construct(self):
6566
path = VMobject()
6667
dot = Dot()
@@ -77,9 +78,9 @@ Updaters
7778
self.play(dot.shift, LEFT)
7879
self.wait()
7980

80-
.. manim:: Example1ValTracker
81+
.. manim:: PointMovingWithValTracker
8182

82-
class Example1ValTracker(Scene):
83+
class PointMovingWithValTracker(Scene):
8384
def construct(self):
8485
dot_disp = Dot().set_color(RED)
8586
self.add(dot_disp)
@@ -92,9 +93,9 @@ Updaters
9293
self.play(val_tracker.set_value, tick_end, rate_func=linear)
9394
self.wait()
9495

95-
.. manim:: Example2ValTracker
96+
.. manim:: RotationValTracker
9697

97-
class Example2ValTracker(Scene):
98+
class RotationValTracker(Scene):
9899
def construct(self):
99100
tick_start = 0
100101
tick_end = 2 * PI
@@ -105,4 +106,38 @@ Updaters
105106
line_moving = Line(ORIGIN, LEFT).set_color(ORANGE)
106107
line_moving.add_updater(my_rotation_updater)
107108
self.add(line_reference, line_moving)
108-
self.play(val_tracker.set_value, tick_end, run_time=PI)
109+
self.play(val_tracker.set_value, tick_end, run_time=PI)
110+
111+
.. manim:: PlaneFadeOut
112+
113+
class PlaneFadeOut(Scene):
114+
def construct(self):
115+
sq2 = Square()
116+
117+
sq1 = Square()
118+
sq1.next_to(sq2, LEFT)
119+
120+
sq3 = Square()
121+
sq3.next_to(sq2, RIGHT)
122+
123+
circ = Circle()
124+
circ.next_to(sq2, DOWN)
125+
126+
self.add(sq1, sq2, sq3, circ)
127+
self.wait()
128+
129+
self.play(FadeOut(sq1), FadeOut(sq2), FadeOut(sq3))
130+
self.wait()
131+
132+
.. manim:: FadeInAndOut
133+
134+
class FadeInAndOut(Scene):
135+
def construct(self):
136+
square = Square(color=BLUE).shift(2 * UP)
137+
annotation = Text("Fade In", height=0.8)
138+
self.add(annotation)
139+
self.play(FadeIn(square))
140+
141+
annotation.become(Text("Fade Out", height=0.8))
142+
self.add(annotation)
143+
self.play(FadeOut(square))

docs/source/examples/annotations.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Annotations
22
=================================
33

4-
.. manim:: AnnotateBrace
4+
.. manim:: BraceAnnotation
55
:save_last_frame:
66

7-
class AnnotateBrace(Scene):
7+
class BraceAnnotation(Scene):
88
def construct(self):
99
dot = Dot([0, 0, 0])
1010
dot2 = Dot([2, 1, 0])
@@ -15,26 +15,26 @@ Annotations
1515
b2text = b2.get_tex("x-x_1")
1616
self.add(dot, dot2, line, b1, b2, b1text, b2text)
1717

18-
.. manim:: ExampleArrow
18+
.. manim:: VectorArrow
1919
:quality: medium
2020
:save_last_frame:
2121

22-
class ExampleArrow(Scene):
22+
class VectorArrow(Scene):
2323
def construct(self):
2424
dot = Dot(ORIGIN)
2525
arrow = Arrow(ORIGIN, [2, 2, 0], buff=0)
2626
numberplane = NumberPlane()
27-
origin_text = TextMobject('(0, 0)').next_to(dot, DOWN)
28-
tip_text = TextMobject('(2, 2)').next_to(arrow.get_end(), RIGHT)
27+
origin_text = Text('(0, 0)').next_to(dot, DOWN)
28+
tip_text = Text('(2, 2)').next_to(arrow.get_end(), RIGHT)
2929
self.add(numberplane, dot, arrow, origin_text, tip_text)
3030

31-
.. manim:: ExampleArrowTips
31+
.. manim:: ArrowTipsShowcase
3232
:quality: medium
3333
:save_last_frame:
3434

3535
from manim.mobject.geometry import ArrowTriangleTip, ArrowSquareTip, ArrowSquareFilledTip,\
3636
ArrowCircleTip, ArrowCircleFilledTip
37-
class ExampleArrowTips(Scene):
37+
class ArrowTipsShowcase(Scene):
3838
def construct(self):
3939
a00 = Arrow(start=[-2, 3, 0], end=[2, 3, 0], color=YELLOW)
4040
a11 = Arrow(start=[-2, 2, 0], end=[2, 2, 0], tip_shape=ArrowTriangleTip)

0 commit comments

Comments
 (0)