Skip to content

Commit 955c6dd

Browse files
committed
Merge branch 'master' into examples_folder_structure
2 parents ef10ace + 88a3f63 commit 955c6dd

File tree

9 files changed

+189
-22
lines changed

9 files changed

+189
-22
lines changed

docs/source/examples/plots.rst

Lines changed: 176 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,182 @@
11
Plotting with manim
22
=================================
33

4+
Examples to illustrate the use of :class:`.GraphScene` in manim.
5+
6+
7+
.. manim:: Plot1
8+
:quality: medium
9+
:save_last_frame:
10+
11+
class Plot1(GraphScene):
12+
def construct(self):
13+
self.setup_axes()
14+
func_graph=self.get_graph(lambda x: np.sin(x))
15+
self.add(func_graph)
16+
17+
.. manim:: Plot2yLabel
18+
:quality: medium
19+
:save_last_frame:
20+
21+
class Plot2yLabel(GraphScene):
22+
CONFIG = {
23+
"y_min": 0,
24+
"y_max": 100,
25+
"y_axis_config": {"tick_frequency": 10},
26+
"y_labeled_nums": np.arange(0, 100, 10)
27+
}
28+
29+
def construct(self):
30+
self.setup_axes(animate=True)
31+
dot = Dot().move_to(self.coords_to_point(PI / 2, 20))
32+
func_graph = self.get_graph(lambda x: 20 * np.sin(x))
33+
self.add(func_graph)
34+
self.add(dot)
35+
36+
.. manim:: Plot3DataPoints
37+
:quality: medium
38+
:save_last_frame:
39+
40+
class Plot3DataPoints(GraphScene):
41+
CONFIG = {
42+
"y_axis_label": r"Concentration[\%]",
43+
"x_axis_label": "Time [s]",
44+
}
45+
46+
def construct(self):
47+
data = [1, 2, 2, 4, 4, 1, 3]
48+
self.setup_axes(animate=True)
49+
for time, dat in enumerate(data):
50+
dot = Dot().move_to(self.coords_to_point(time, dat))
51+
self.add(dot)
52+
53+
.. manim:: Plot3bGaussian
54+
:quality: medium
55+
:save_last_frame:
56+
57+
amp = 5
58+
mu = 3
59+
sig = 1
60+
61+
def gaussian(x):
62+
return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))
63+
64+
class Plot3bGaussian(GraphScene):
65+
def construct(self):
66+
self.setup_axes()
67+
graph = self.get_graph(gaussian, x_min=-1, x_max=10).set_stroke(width=5)
68+
self.add(graph)
69+
70+
.. manim:: Plot3cGaussian
71+
:quality: medium
72+
:save_last_frame:
73+
74+
class Plot3cGaussian(GraphScene):
75+
def construct(self):
76+
def gaussian(x):
77+
amp = 5
78+
mu = 3
79+
sig = 1
80+
return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))
81+
self.setup_axes()
82+
graph = self.get_graph(gaussian, x_min=-1, x_max=10).set_style(stroke_width=5, stroke_color=GREEN)
83+
self.add(graph)
84+
85+
86+
.. manim:: Plot4SinCos
87+
:quality: medium
88+
:save_last_frame:
89+
90+
class Plot4SinCos(GraphScene):
91+
CONFIG = {
92+
"x_min": -10,
93+
"x_max": 10.3,
94+
"num_graph_anchor_points": 100,
95+
"y_min": -1.5,
96+
"y_max": 1.5,
97+
"graph_origin": ORIGIN,
98+
"function_color": RED,
99+
"axes_color": GREEN,
100+
"x_labeled_nums": range(-10, 12, 2),
101+
}
102+
103+
def construct(self):
104+
self.setup_axes(animate=False)
105+
106+
def func_cos(x):
107+
return np.cos(x)
108+
109+
def func_sin(x):
110+
return np.sin(x)
111+
112+
func_graph = self.get_graph(func_cos, self.function_color)
113+
func_graph2 = self.get_graph(func_sin)
114+
vert_line = self.get_vertical_line_to_graph(TAU, func_graph, color=YELLOW)
115+
graph_lab = self.get_graph_label(func_graph, label="\\cos(x)")
116+
graph_lab2 = self.get_graph_label(func_graph2, label="\\sin(x)", x_val=-10, direction=UP / 2)
117+
two_pi = MathTex(r"x = 2 \pi")
118+
label_coord = self.input_to_graph_point(TAU, func_graph)
119+
two_pi.next_to(label_coord, RIGHT + UP)
120+
self.add(func_graph, func_graph2, vert_line, graph_lab, graph_lab2, two_pi)
121+
122+
.. manim:: Plot5Area
123+
:quality: medium
124+
:save_last_frame:
125+
126+
class Plot5Area(GraphScene):
127+
CONFIG = {
128+
"x_min" : 0,
129+
"x_max" : 5,
130+
"y_min" : 0,
131+
"y_max" : 6,
132+
"y_tick_frequency" : 1,
133+
"x_tick_frequency" : 1,
134+
"x_labeled_nums" : [0,2,3]
135+
}
136+
def construct(self):
137+
self.setup_axes(animate=False)
138+
curve1 = self.get_graph(lambda x : 4*x-x**2, x_min=0,x_max=4)
139+
curve2 = self.get_graph(lambda x : 0.8*x**2-3*x+4, x_min=0,x_max=4)
140+
line1 = self.get_vertical_line_to_graph(2, curve1, DashedLine, color=YELLOW)
141+
line2 = self.get_vertical_line_to_graph(3, curve1, DashedLine, color=YELLOW)
142+
area1 = self.get_area(curve1, 0.3, 0.6, dx_scaling=10, area_color=BLUE)
143+
area2 = self.get_area(curve2, 2, 3, bounded=curve1)
144+
self.add(curve1, curve2, line1, line2, area1, area2)
145+
146+
.. manim:: Plot6HeatDiagram
147+
:quality: medium
148+
:save_last_frame:
149+
150+
class Plot6HeatDiagram(GraphScene):
151+
CONFIG = {
152+
"y_axis_label": r"T[$^\circ C$]",
153+
"x_axis_label": r"$\Delta Q$",
154+
"y_min": -8,
155+
"y_max": 30,
156+
"x_min": 0,
157+
"x_max": 40,
158+
"y_labeled_nums": np.arange(-5, 34, 5),
159+
"x_labeled_nums": np.arange(0, 40, 5),
160+
161+
}
162+
163+
def construct(self):
164+
data = [20, 0, 0, -5]
165+
x = [0, 8, 38, 39]
166+
self.setup_axes(animate=True)
167+
dot_collection = VGroup()
168+
for time, val in enumerate(data):
169+
dot = Dot().move_to(self.coords_to_point(x[time], val))
170+
self.add(dot)
171+
dot_collection.add(dot)
172+
l1 = Line(dot_collection[0].get_center(), dot_collection[1].get_center())
173+
l2 = Line(dot_collection[1].get_center(), dot_collection[2].get_center())
174+
l3 = Line(dot_collection[2].get_center(), dot_collection[3].get_center())
175+
self.add(l1, l2, l3)
176+
177+
178+
The following example illustrates how to draw parametric function plots.
179+
4180
.. manim:: ParamFunc1
5181
:quality: medium
6182
:save_last_frame:
@@ -11,4 +187,3 @@ Plotting with manim
11187
def construct(self):
12188
func=ParametricFunction(self.func, t_max=TAU, fill_opacity=0).set_color(RED)
13189
self.add(func.scale(3))
14-

docs/source/installation/win.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ instructions.
88
Installing using Chocolatey
99
***************************
1010

11-
You can install chocolatey very easily using chocolatey. Typing the command install Manim.
11+
You can install manim very easily using chocolatey, by typing the following command.
1212

1313

1414
.. code-block:: powershell

docs/source/manim_directive.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
When rendering the HTML documentation, the ``.. manim::`` directive
66
implemented here allows to include rendered videos.
77
8-
Its basic usage that allows processing **inline content**
8+
Its basic usage that allows processing **inline content**
99
looks as follows::
1010
1111
.. manim:: MyScene
@@ -41,9 +41,9 @@ def construct(self):
4141
The following configuration options are supported by the
4242
directive:
4343
44-
display_source
44+
hide_source
4545
If this flag is present without argument,
46-
the source code is displayed above the rendered video.
46+
the source code is not displayed above the rendered video.
4747
4848
quality : {'low', 'medium', 'high', 'fourk'}
4949
Controls render quality of the video, in analogy to
@@ -80,7 +80,7 @@ class ManimDirective(Directive):
8080
required_arguments = 1
8181
optional_arguments = 0
8282
option_spec = {
83-
"display_source": bool,
83+
"hide_source": bool,
8484
"quality": lambda arg: directives.choice(
8585
arg, ("low", "medium", "high", "fourk")
8686
),
@@ -100,7 +100,7 @@ def run(self):
100100
else:
101101
classnamedict[clsname] += 1
102102

103-
display_source = "display_source" in self.options
103+
hide_source = "hide_source" in self.options
104104
save_as_gif = "save_as_gif" in self.options
105105
save_last_frame = "save_last_frame" in self.options
106106
assert not (save_as_gif and save_last_frame)
@@ -211,7 +211,7 @@ def run(self):
211211
raise ValueError("Invalid combination of render flags received.")
212212

213213
rendered_template = jinja2.Template(TEMPLATE).render(
214-
display_source=display_source,
214+
hide_source=hide_source,
215215
filesrc_rel=os.path.relpath(filesrc, setup.confdir),
216216
output_file=output_file,
217217
save_last_frame=save_last_frame,
@@ -238,7 +238,7 @@ def setup(app):
238238

239239

240240
TEMPLATE = r"""
241-
{% if display_source %}
241+
{% if not hide_source %}
242242
.. raw:: html
243243
244244
<div class="manim-example">
@@ -258,7 +258,7 @@ def setup(app):
258258
:align: center
259259
{% endif %}
260260
261-
{% if display_source %}
261+
{% if not hide_source %}
262262
.. raw:: html
263263
264264
</div>

docs/source/tutorials/a_deeper_look.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ will play it once it's done since we are using the ``-p`` flag. The output
6565
should look like this:
6666

6767
.. manim:: SquareToCircle3
68+
:hide_source:
6869
:quality: high
6970

7071
class SquareToCircle3(Scene):

docs/source/tutorials/building_blocks.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ screen, simply call the :meth:`~.Scene.remove` method from the containing
6161
:class:`.Scene`.
6262

6363
.. manim:: CreatingMobjects
64-
:display_source:
6564
:quality: medium
6665

6766
class CreatingMobjects(Scene):
@@ -81,7 +80,6 @@ some mobjects to it. This script generates a static picture that displays a
8180
circle, a square, and a triangle:
8281

8382
.. manim:: Shapes
84-
:display_source:
8583
:quality: medium
8684

8785
class Shapes(Scene):
@@ -114,7 +112,6 @@ There are many other possible ways to place mobjects on the screen, for example
114112
``MobjectPlacement`` uses all three.
115113

116114
.. manim:: MobjectPlacement
117-
:display_source:
118115
:quality: medium
119116

120117
class MobjectPlacement(Scene):
@@ -163,7 +160,6 @@ Styling mobjects
163160
The following scene changes the default aesthetics of the mobjects.
164161

165162
.. manim:: MobjectStyling
166-
:display_source:
167163
:quality: medium
168164

169165
class MobjectStyling(Scene):
@@ -200,7 +196,6 @@ The next scene is exactly the same as the ``MobjectStyling`` scene from the
200196
previous section, except for exactly one line.
201197

202198
.. manim:: MobjectZOrder
203-
:display_source:
204199
:quality: medium
205200

206201
class MobjectZOrder(Scene):
@@ -234,7 +229,6 @@ At the heart of manim is animation. Generally, you can add an animation to
234229
your scene by calling the :meth:`~.Scene.play` method.
235230

236231
.. manim:: SomeAnimations
237-
:display_source:
238232
:quality: medium
239233

240234
class SomeAnimations(Scene):
@@ -271,7 +265,6 @@ method that changes a mobject's property can be used as an animation, through
271265
the use of :class:`.ApplyMethod`.
272266

273267
.. manim:: ApplyMethodExample
274-
:display_source:
275268
:quality: medium
276269

277270
class ApplyMethodExample(Scene):
@@ -300,7 +293,6 @@ By default, any animation passed to :meth:`play` lasts for exactly one second.
300293
Use the :code:`run_time` argument to control the duration.
301294

302295
.. manim:: RunTime
303-
:display_source:
304296
:quality: medium
305297

306298
class RunTime(Scene):

docs/source/tutorials/quickstart.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ and open that file with the default movie player application. You should see a
5858
video playing the following animation.
5959

6060
.. manim:: SquareToCircle
61+
:hide_source:
6162
:quality: low
6263

6364
class SquareToCircle(Scene):
@@ -153,6 +154,7 @@ And render it using the following command:
153154
The output should look as follows.
154155

155156
.. manim:: SquareToCircle2
157+
:hide_source:
156158
:quality: low
157159

158160
class SquareToCircle2(Scene):

manim/mobject/changing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class AnimatedBoundary(VGroup):
1616
Examples
1717
--------
1818
.. manim:: AnimatedBoundaryExample
19-
:display_source:
2019
:quality: low
2120
2221
class AnimatedBoundaryExample(Scene):
@@ -90,7 +89,6 @@ class TracedPath(VMobject):
9089
Examples
9190
--------
9291
.. manim:: TracedPathExample
93-
:display_source:
9492
:quality: low
9593
9694
class TracedPathExample(Scene):

manim/mobject/geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ class ArrowTip(VMobject):
895895
a custom one like this:
896896
897897
.. manim:: CustomTipExample
898-
:display_source:
898+
:quality: low
899899
900900
>>> class MyCustomArrowTip(ArrowTip, RegularPolygon):
901901
... def __init__(self, **kwargs):

manim/mobject/value_tracker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ValueTracker(Mobject):
2121
Examples
2222
--------
2323
.. manim:: ValueTrackerExample
24-
:display_source:
2524
:quality: low
2625
2726
class ValueTrackerExample(Scene):

0 commit comments

Comments
 (0)