Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Bunch of more examples for the docs (#458)

kolibril135233c598ac72
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index 7aa8dc1d3..fea2e23c5 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -12,4 +12,4 @@ Examples
examples/camera_settings
examples/animations
examples/neat_projects
- examples/advanced_projects
\ No newline at end of file
+ examples/advanced_projects
diff --git a/docs/source/examples/3d.rst b/docs/source/examples/3d.rst
index e6614c576..6a46f018d 100644
--- a/docs/source/examples/3d.rst
+++ b/docs/source/examples/3d.rst
@@ -2,7 +2,6 @@
=================================
.. manim:: Example3DNo1
- :quality: medium
:save_last_frame:
class Example3DNo1(ThreeDScene):
@@ -19,3 +18,64 @@
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
self.add(axes, sphere)
+.. manim:: Example3DLightSourcePosition
+ :save_last_frame:
+
+ class Example3DLightSourcePosition(ThreeDScene):
+ def construct(self):
+ axes = ThreeDAxes()
+ sphere = ParametricSurface(
+ lambda u, v: np.array([
+ 1.5 * np.cos(u) * np.cos(v),
+ 1.5 * np.cos(u) * np.sin(v),
+ 1.5 * np.sin(u)
+ ]), v_min=0, v_max=TAU, u_min=-PI / 2, u_max=PI / 2,
+ checkerboard_colors=[RED_D, RED_E], resolution=(15, 32)
+ )
+ self.camera.light_source.move_to(3*IN) # changes the source of the light
+ self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
+ self.add(axes, sphere)
+
+.. manim:: Example3DNo3
+
+ class Example3DNo3(ThreeDScene):
+ def construct(self):
+ axes = ThreeDAxes()
+ circle=Circle()
+ self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
+ self.add(circle,axes)
+ self.begin_ambient_camera_rotation(rate=0.1)
+ self.wait(3)
+ self.stop_ambient_camera_rotation()
+ self.move_camera(phi=75 * DEGREES, theta=30 * DEGREES)
+ self.wait()
+
+.. manim:: Example3DNo4
+
+ class Example3DNo4(ThreeDScene):
+ def construct(self):
+ axes = ThreeDAxes()
+ circle=Circle()
+ self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
+ self.add(circle,axes)
+ self.begin_3dillusion_camera_rotation(rate=2)
+ self.wait(PI)
+ self.stop_3dillusion_camera_rotation()
+
+.. manim:: Example3DNo5
+ :save_last_frame:
+
+ class Example3DNo5(ThreeDScene):
+ def construct(self):
+ curve1 = ParametricFunction(
+ lambda u: np.array([
+ 1.2 * np.cos(u),
+ 1.2 * np.sin(u),
+ u * 0.05
+ ]), color=RED, t_min=-3 * TAU, t_max=5 * TAU,
+ ).set_shade_in_3d(True)
+ axes = ThreeDAxes()
+ self.add(axes, curve1)
+ self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)
+ self.wait()
+
diff --git a/docs/source/examples/advanced_projects.rst b/docs/source/examples/advanced_projects.rst
index 1e5938197..4626cf74d 100644
--- a/docs/source/examples/advanced_projects.rst
+++ b/docs/source/examples/advanced_projects.rst
@@ -1,4 +1,91 @@
Advanced Projects
=================================
-This page is currently under construction. It will feature a selection of advanced projects built with manim.
+.. manim:: ExampleSineCurve
+
+ class ExampleSineCurve(Scene):
+ # contributed by heejin_park, https://infograph.tistory.com/230
+ def construct(self):
+ self.show_axis()
+ self.show_circle()
+ self.move_dot_and_draw_curve()
+ self.wait()
+
+ def show_axis(self):
+ x_start = np.array([-6,0,0])
+ x_end = np.array([6,0,0])
+
+ y_start = np.array([-4,-2,0])
+ y_end = np.array([-4,2,0])
+
+ x_axis = Line(x_start, x_end)
+ y_axis = Line(y_start, y_end)
+
+ self.add(x_axis, y_axis)
+ self.add_x_labels()
+
+ self.orgin_point = np.array([-4,0,0])
+ self.curve_start = np.array([-3,0,0])
+
+ def add_x_labels(self):
+ x_labels = [
+ TexMobject("\pi"), TexMobject("2 \pi"),
+ TexMobject("3 \pi"), TexMobject("4 \pi"),
+ ]
+
+ for i in range(len(x_labels)):
+ x_labels[i].next_to(np.array([-1 + 2*i, 0, 0]), DOWN)
+ self.add(x_labels[i])
+
+ def show_circle(self):
+ circle = Circle(radius=1)
+ circle.move_to(self.orgin_point)
+
+ self.add(circle)
+ self.circle = circle
+
+ def move_dot_and_draw_curve(self):
+ orbit = self.circle
+ orgin_point = self.orgin_point
+
+ dot = Dot(radius=0.08, color=YELLOW)
+ dot.move_to(orbit.point_from_proportion(0))
+ self.t_offset = 0
+ rate = 0.25
+
+ def go_around_circle(mob, dt):
+ self.t_offset += (dt * rate)
+ # print(self.t_offset)
+ mob.move_to(orbit.point_from_proportion(self.t_offset % 1))
+
+ def get_line_to_circle():
+ return Line(orgin_point, dot.get_center(), color=BLUE)
+
+ def get_line_to_curve():
+ x = self.curve_start[0] + self.t_offset * 4
+ y = dot.get_center()[1]
+ return Line(dot.get_center(), np.array([x,y,0]), color=YELLOW_A, stroke_width=2 )
+
+
+ self.curve = VGroup()
+ self.curve.add(Line(self.curve_start,self.curve_start))
+ def get_curve():
+ last_line = self.curve[-1]
+ x = self.curve_start[0] + self.t_offset * 4
+ y = dot.get_center()[1]
+ new_line = Line(last_line.get_end(),np.array([x,y,0]), color=YELLOW_D)
+ self.curve.add(new_line)
+
+ return self.curve
+
+ dot.add_updater(go_around_circle)
+
+ origin_to_circle_line = always_redraw(get_line_to_circle)
+ dot_to_curve_line = always_redraw(get_line_to_curve)
+ sine_curve_line = always_redraw(get_curve)
+
+ self.add(dot)
+ self.add(orbit, origin_to_circle_line, dot_to_curve_line, sine_curve_line)
+ self.wait(8.5)
+
+ dot.remove_updater(go_around_circle)
diff --git a/docs/source/examples/animations.rst b/docs/source/examples/animations.rst
index 7dea2d1b6..33eab8e9c 100644
--- a/docs/source/examples/animations.rst
+++ b/docs/source/examples/animations.rst
@@ -11,17 +11,98 @@ Updaters
##########
.. manim:: Updater1Example
- :quality: medium
class Updater1Example(Scene):
def construct(self):
- curve_reference = Line(ORIGIN, LEFT).set_color(GREEN)
- self.add(curve_reference)
+ def my_rotation_updater(mobj,dt):
+ mobj.rotate_about_origin(dt)
+ line_reference = Line(ORIGIN, LEFT).set_color(WHITE)
+ line_moving = Line(ORIGIN, LEFT).set_color(BLUE)
+ line_moving.add_updater(my_rotation_updater)
+ self.add(line_reference, line_moving)
+ self.wait(PI)
- def update_curve(mob, dt):
- mob.rotate_about_origin(dt)
+.. manim:: Updater2Example
- curve2 = Line(ORIGIN, LEFT)
- curve2.add_updater(update_curve)
- self.add(curve_reference, curve2)
- self.wait(PI)
+ class Updater2Example(Scene):
+ def construct(self):
+ def updater_forth(mobj, dt):
+ mobj.rotate_about_origin(dt)
+ def updater_back(mobj, dt):
+ mobj.rotate_about_origin(-dt)
+ line_reference = Line(ORIGIN, LEFT).set_color(WHITE)
+ line_moving = Line(ORIGIN, LEFT).set_color(YELLOW)
+ line_moving.add_updater(updater_forth)
+ self.add(line_reference, line_moving)
+ self.wait(2)
+ line_moving.remove_updater(updater_forth)
+ line_moving.add_updater(updater_back)
+ self.wait(2)
+ line_moving.remove_updater(updater_back)
+ self.wait(0.5)
+
+.. manim:: Example3
+
+ class Example3(Scene):
+ def construct(self):
+ number_line = NumberLine() ##with all your parameters and stuff
+ pointer = Vector(DOWN)
+ label = MathTex("x").add_updater(lambda m: m.next_to(pointer, UP))
+
+ pointer_value = ValueTracker(0)
+ pointer.add_updater(
+ lambda m: m.next_to( number_line.n2p(pointer_value.get_value()), UP)
+ )
+ self.add(number_line, pointer, label)
+ self.play(pointer_value.set_value, 5)
+ self.wait()
+ self.play(pointer_value.set_value, 3)
+
+.. manim:: Example4
+
+ class Example4(Scene):
+ def construct(self):
+ path = VMobject()
+ dot = Dot()
+ path.set_points_as_corners([dot.get_center(), dot.get_center()])
+ def update_path(path):
+ previus_path = path.copy()
+ previus_path.add_points_as_corners([dot.get_center()])
+ path.become(previus_path)
+ path.add_updater(update_path)
+ self.add(path, dot)
+ self.play(Rotating(dot, radians=PI, about_point=RIGHT, run_time=2))
+ self.wait()
+ self.play(dot.shift, UP)
+ self.play(dot.shift, LEFT)
+ self.wait()
+
+.. manim:: Example1ValTracker
+
+ class Example1ValTracker(Scene):
+ def construct(self):
+ dot_disp = Dot().set_color(RED)
+ self.add(dot_disp)
+ tick_start = 1
+ tick_end = 2
+ val_tracker = ValueTracker(tick_start)
+ def dot_updater(mob):
+ mob.set_y(val_tracker.get_value())
+ dot_disp.add_updater(dot_updater)
+ self.play(val_tracker.set_value, tick_end, rate_func=linear)
+ self.wait()
+
+.. manim:: Example2ValTracker
+
+ class Example2ValTracker(Scene):
+ def construct(self):
+ tick_start = 0
+ tick_end = 2 * PI
+ val_tracker = ValueTracker(tick_start)
+ def my_rotation_updater(mobj):
+ mobj.rotate_about_origin(1 / 30) # be careful: This is framerate dependent!
+ line_reference = Line(ORIGIN, LEFT).set_color(WHITE)
+ line_moving = Line(ORIGIN, LEFT).set_color(ORANGE)
+ line_moving.add_updater(my_rotation_updater)
+ self.add(line_reference, line_moving)
+ self.play(val_tracker.set_value, tick_end, run_time=PI)
\ No newline at end of file
diff --git a/docs/source/examples/annotations.rst b/docs/source/examples/annotations.rst
index d325eedc2..1d1783386 100644
--- a/docs/source/examples/annotations.rst
+++ b/docs/source/examples/annotations.rst
@@ -2,7 +2,6 @@ Annotations
=================================
.. manim:: AnnotateBrace
- :quality: medium
:save_last_frame:
class AnnotateBrace(Scene):
diff --git a/docs/source/examples/camera_settings.rst b/docs/source/examples/camera_settings.rst
index 0f1df6a41..5b28addf0 100644
--- a/docs/source/examples/camera_settings.rst
+++ b/docs/source/examples/camera_settings.rst
@@ -1,18 +1,215 @@
Camera Settings
=================================
-.. manim:: TestZoom1
- :quality: medium
+.. manim:: Example1
- class TestZoom1(ZoomedScene):
+ class Example1(MovingCameraScene):
+ def construct(self):
+ text = Text("Hello World")
+ self.add(text)
+ self.play(self.camera_frame.set_width, text.get_width() * 1.2)
+ self.wait()
+
+.. manim:: Example2a
+
+ class Example2a(MovingCameraScene):
+ def construct(self):
+ text = Text("Hello World").set_color(BLUE)
+ self.add(text)
+ self.camera_frame.save_state()
+ self.play(self.camera_frame.set_width, text.get_width() * 1.2)
+ self.wait(0.3)
+ self.play(Restore(self.camera_frame))
+
+.. manim:: Example2b
+
+ class Example2b(MovingCameraScene):
+ def construct(self):
+ text = Text("Hello World").set_color(BLUE)
+ self.add(text)
+ self.play(self.camera_frame.set_width, text.get_width() * 1.2)
+ self.wait(0.3)
+ self.play(self.camera_frame.set_width, 14)
+
+
+.. manim:: Example3
+
+ class Example3(MovingCameraScene):
+ def construct(self):
+ s = Square(color=RED, fill_opacity=0.5).move_to(2 * LEFT)
+ t = Triangle(color=GREEN, fill_opacity=0.5).move_to(2 * RIGHT)
+ self.add(s, t)
+ self.play(self.camera_frame.move_to, s)
+ self.wait(0.3)
+ self.play(self.camera_frame.move_to, t)
+
+.. manim:: Example4
+
+ class Example4(MovingCameraScene):
+ def construct(self):
+ s = Square(color=BLUE, fill_opacity=0.5).move_to(2 * LEFT)
+ t = Triangle(color=YELLOW, fill_opacity=0.5).move_to(2 * RIGHT)
+ self.add(s, t)
+ self.play(self.camera_frame.move_to, s,
+ self.camera_frame.set_width,s.get_width()*2)
+ self.wait(0.3)
+ self.play(self.camera_frame.move_to, t,
+ self.camera_frame.set_width,t.get_width()*2)
+
+ self.play(self.camera_frame.move_to, ORIGIN,
+ self.camera_frame.set_width,14)
+
+.. manim:: Example5
+
+ class Example5(GraphScene, MovingCameraScene):
+ def setup(self):
+ GraphScene.setup(self)
+ MovingCameraScene.setup(self)
+ def construct(self):
+ self.camera_frame.save_state()
+ self.setup_axes(animate=False)
+ graph = self.get_graph(lambda x: np.sin(x),
+ color=WHITE,
+ x_min=0,
+ x_max=3 * PI
+ )
+ dot_at_start_graph = Dot().move_to(graph.points[0])
+ dot_at_end_grap = Dot().move_to(graph.points[-1])
+ self.add(graph, dot_at_end_grap, dot_at_start_graph)
+ self.play(self.camera_frame.scale, 0.5, self.camera_frame.move_to, dot_at_start_graph)
+ self.play(self.camera_frame.move_to, dot_at_end_grap)
+ self.play(Restore(self.camera_frame))
+ self.wait()
+
+.. manim:: Example6
+
+ class Example6(GraphScene, MovingCameraScene):
+ def setup(self):
+ GraphScene.setup(self)
+ MovingCameraScene.setup(self)
+ def construct(self):
+ self.camera_frame.save_state()
+ self.setup_axes(animate=False)
+ graph = self.get_graph(lambda x: np.sin(x),
+ color=BLUE,
+ x_min=0,
+ x_max=3 * PI
+ )
+ moving_dot = Dot().move_to(graph.points[0]).set_color(ORANGE)
+
+ dot_at_start_graph = Dot().move_to(graph.points[0])
+ dot_at_end_grap = Dot().move_to(graph.points[-1])
+ self.add(graph, dot_at_end_grap, dot_at_start_graph, moving_dot)
+ self.play( self.camera_frame.scale,0.5,self.camera_frame.move_to,moving_dot)
+
+ def update_curve(mob):
+ mob.move_to(moving_dot.get_center())
+
+ self.camera_frame.add_updater(update_curve)
+ self.play(MoveAlongPath(moving_dot, graph, rate_func=linear))
+ self.camera_frame.remove_updater(update_curve)
+
+ self.play(Restore(self.camera_frame))
+
+
+Note: ZoomedScene is derived class of MovingCameraScene,
+so one can use all functionality that were used before in the MovingCameraScene examples.
+
+.. manim:: ExampleZoom1
+
+ class ExampleZoom1(ZoomedScene):
+ def construct(self):
+ dot = Dot().set_color(GREEN)
+ self.add(dot)
+ self.wait(1)
+ self.activate_zooming(animate=False)
+ self.wait(1)
+ self.play(dot.shift, LEFT)
+
+.. manim:: ExampleZoom2
+
+ class ExampleZoom2(ZoomedScene):
CONFIG = {
- "zoomed_camera_frame_starting_position": [0, 0, 0],
- "zoomed_display_corner": [0, 0, 0],
- "zoomed_display_height": config['frame_height'],
- "zoomed_display_width": config['frame_width'],
- "zoom_factor": 0.1,
+ "zoom_factor": 0.3,
+ "zoomed_display_height": 1,
+ "zoomed_display_width": 3,
+ "image_frame_stroke_width": 20,
+ "zoomed_camera_config": {
+ "default_frame_stroke_width": 3,
+ },
}
def construct(self):
- self.activate_zooming(animate=True)
- d = Dot()
- self.add(d)
+ dot = Dot().set_color(GREEN)
+ sq = Circle(fill_opacity=1, radius=0.2).next_to(dot, RIGHT)
+ self.add(dot, sq)
+ self.wait(1)
+ self.activate_zooming(animate=False)
+ self.wait(1)
+ self.play(dot.shift, LEFT * 0.3)
+
+ self.play(self.zoomed_camera.frame.scale, 4)
+ self.play(self.zoomed_camera.frame.shift, 0.5 * DOWN)
+
+
+.. manim:: ExampleZoom3
+
+ class ExampleZoom3(ZoomedScene):
+ # contributed by TheoremofBeethoven, www.youtube.com/c/TheoremofBeethoven
+ CONFIG = {
+ "zoom_factor": 0.3,
+ "zoomed_display_height": 1,
+ "zoomed_display_width": 6,
+ "image_frame_stroke_width": 20,
+ "zoomed_camera_config": {
+ "default_frame_stroke_width": 3,
+ },
+ }
+
+ def construct(self):
+ dot = Dot().shift(UL * 2)
+ image = ImageMobject(np.uint8([[0, 100, 30, 200],
+ [255, 0, 5, 33]]))
+ image.set_height(7)
+ frame_text = TextMobject("Frame", color=PURPLE).scale(1.4)
+ zoomed_camera_text = TextMobject("Zoomed camera", color=RED).scale(1.4)
+
+ self.add(image, dot)
+ zoomed_camera = self.zoomed_camera
+ zoomed_display = self.zoomed_display
+ frame = zoomed_camera.frame
+ zoomed_display_frame = zoomed_display.display_frame
+
+ frame.move_to(dot)
+ frame.set_color(PURPLE)
+ zoomed_display_frame.set_color(RED)
+ zoomed_display.shift(DOWN)
+
+ zd_rect = BackgroundRectangle(zoomed_display, fill_opacity=0, buff=MED_SMALL_BUFF)
+ self.add_foreground_mobject(zd_rect)
+
+ unfold_camera = UpdateFromFunc(zd_rect, lambda rect: rect.replace(zoomed_display))
+
+ frame_text.next_to(frame, DOWN)
+
+ self.play(ShowCreation(frame), FadeInFromDown(frame_text))
+ self.activate_zooming()
+
+ self.play(self.get_zoomed_display_pop_out_animation(), unfold_camera)
+ zoomed_camera_text.next_to(zoomed_display_frame, DOWN)
+ self.play(FadeInFromDown(zoomed_camera_text))
+ # Scale in x y z
+ scale_factor = [0.5, 1.5, 0]
+ self.play(
+ frame.scale, scale_factor,
+ zoomed_display.scale, scale_factor,
+ FadeOut(zoomed_camera_text),
+ FadeOut(frame_text)
+ )
+ self.wait()
+ self.play(ScaleInPlace(zoomed_display, 2))
+ self.wait()
+ self.play(frame.shift, 2.5 * DOWN)
+ self.wait()
+ self.play(self.get_zoomed_display_pop_out_animation(), unfold_camera, rate_func=lambda t: smooth(1 - t))
+ self.play(Uncreate(zoomed_display_frame), FadeOut(frame))
+ self.wait()
diff --git a/docs/source/examples/formulas.rst b/docs/source/examples/formulas.rst
index be99a83fd..c28eefca0 100644
--- a/docs/source/examples/formulas.rst
+++ b/docs/source/examples/formulas.rst
@@ -2,7 +2,6 @@ Formulas
=================================
.. manim:: Formula1
- :quality: medium
:save_last_frame:
class Formula1(Scene):
@@ -10,3 +9,50 @@ Formulas
t = MathTex(r"\int_a^b f'(x) dx = f(b)- f(a)")
self.add(t)
self.wait(1)
+
+
+.. manim:: MoveFrameBox
+
+ class MoveFrameBox(Scene):
+ def construct(self):
+ text=TexMobject(
+ "\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
+ "g(x)\\frac{d}{dx}f(x)"
+ )
+ self.play(Write(text))
+ framebox1 = SurroundingRectangle(text[1], buff = .1)
+ framebox2 = SurroundingRectangle(text[3], buff = .1)
+ self.play(
+ ShowCreation(framebox1),
+ )
+ self.wait()
+ self.play(
+ ReplacementTransform(framebox1,framebox2),
+ )
+ self.wait()
+
+.. manim:: MoveBraces
+
+ class MoveBraces(Scene):
+ def construct(self):
+ text=TexMobject(
+ "\\frac{d}{dx}f(x)g(x)=", #0
+ "f(x)\\frac{d}{dx}g(x)", #1
+ "+", #2
+ "g(x)\\frac{d}{dx}f(x)" #3
+ )
+ self.play(Write(text))
+ brace1 = Brace(text[1], UP, buff=SMALL_BUFF)
+ brace2 = Brace(text[3], UP, buff=SMALL_BUFF)
+ t1 = brace1.get_text("$g'f$")
+ t2 = brace2.get_text("$f'g$")
+ self.play(
+ GrowFromCenter(brace1),
+ FadeIn(t1),
+ )
+ self.wait()
+ self.play(
+ ReplacementTransform(brace1,brace2),
+ ReplacementTransform(t1,t2)
+ )
+ self.wait()
diff --git a/docs/source/examples/plots.rst b/docs/source/examples/plots.rst
index 35428a414..2d5dc4ea7 100644
--- a/docs/source/examples/plots.rst
+++ b/docs/source/examples/plots.rst
@@ -5,7 +5,6 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
.. manim:: Plot1
- :quality: medium
:save_last_frame:
class Plot1(GraphScene):
@@ -14,11 +13,10 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
func_graph=self.get_graph(lambda x: np.sin(x))
self.add(func_graph)
-.. manim:: Plot2yLabel
- :quality: medium
+.. manim:: Plot2yLabelNumbers
:save_last_frame:
- class Plot2yLabel(GraphScene):
+ class Plot2yLabelNumbers(GraphScene):
CONFIG = {
"y_min": 0,
"y_max": 100,
@@ -27,31 +25,28 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
}
def construct(self):
- self.setup_axes(animate=True)
+ self.setup_axes()
dot = Dot().move_to(self.coords_to_point(PI / 2, 20))
func_graph = self.get_graph(lambda x: 20 * np.sin(x))
- self.add(func_graph)
- self.add(dot)
+ self.add(dot,func_graph)
.. manim:: Plot3DataPoints
- :quality: medium
:save_last_frame:
class Plot3DataPoints(GraphScene):
CONFIG = {
- "y_axis_label": r"Concentration[\%]",
+ "y_axis_label": r"Concentration [\%]",
"x_axis_label": "Time [s]",
}
def construct(self):
data = [1, 2, 2, 4, 4, 1, 3]
- self.setup_axes(animate=True)
+ self.setup_axes()
for time, dat in enumerate(data):
dot = Dot().move_to(self.coords_to_point(time, dat))
self.add(dot)
.. manim:: Plot3bGaussian
- :quality: medium
:save_last_frame:
amp = 5
@@ -68,7 +63,6 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
self.add(graph)
.. manim:: Plot3cGaussian
- :quality: medium
:save_last_frame:
class Plot3cGaussian(GraphScene):
@@ -79,12 +73,12 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
sig = 1
return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))
self.setup_axes()
- graph = self.get_graph(gaussian, x_min=-1, x_max=10).set_style(stroke_width=5, stroke_color=GREEN)
+ graph = self.get_graph(gaussian, x_min=-1, x_max=10)
+ graph.set_style(stroke_width=5, stroke_color=GREEN)
self.add(graph)
.. manim:: Plot4SinCos
- :quality: medium
:save_last_frame:
class Plot4SinCos(GraphScene):
@@ -102,25 +96,18 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
def construct(self):
self.setup_axes(animate=False)
-
- def func_cos(x):
- return np.cos(x)
-
- def func_sin(x):
- return np.sin(x)
-
- func_graph = self.get_graph(func_cos, self.function_color)
- func_graph2 = self.get_graph(func_sin)
+ func_graph = self.get_graph(np.cos, self.function_color)
+ func_graph2 = self.get_graph(np.sin)
vert_line = self.get_vertical_line_to_graph(TAU, func_graph, color=YELLOW)
graph_lab = self.get_graph_label(func_graph, label="\\cos(x)")
- graph_lab2 = self.get_graph_label(func_graph2, label="\\sin(x)", x_val=-10, direction=UP / 2)
+ graph_lab2 = self.get_graph_label(func_graph2, label="\\sin(x)",
+ x_val=-10, direction=UP / 2)
two_pi = MathTex(r"x = 2 \pi")
label_coord = self.input_to_graph_point(TAU, func_graph)
two_pi.next_to(label_coord, RIGHT + UP)
self.add(func_graph, func_graph2, vert_line, graph_lab, graph_lab2, two_pi)
.. manim:: Plot5Area
- :quality: medium
:save_last_frame:
class Plot5Area(GraphScene):
@@ -134,9 +121,9 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
"x_labeled_nums" : [0,2,3]
}
def construct(self):
- self.setup_axes(animate=False)
- curve1 = self.get_graph(lambda x : 4*x-x**2, x_min=0,x_max=4)
- curve2 = self.get_graph(lambda x : 0.8*x**2-3*x+4, x_min=0,x_max=4)
+ self.setup_axes()
+ curve1 = self.get_graph(lambda x: 4 * x - x ** 2, x_min=0, x_max=4)
+ curve2 = self.get_graph(lambda x: 0.8 * x ** 2 - 3 * x + 4, x_min=0, x_max=4)
line1 = self.get_vertical_line_to_graph(2, curve1, DashedLine, color=YELLOW)
line2 = self.get_vertical_line_to_graph(3, curve1, DashedLine, color=YELLOW)
area1 = self.get_area(curve1, 0.3, 0.6, dx_scaling=10, area_color=BLUE)
@@ -144,7 +131,6 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
self.add(curve1, curve2, line1, line2, area1, area2)
.. manim:: Plot6HeatDiagram
- :quality: medium
:save_last_frame:
class Plot6HeatDiagram(GraphScene):
@@ -157,13 +143,12 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
"x_max": 40,
"y_labeled_nums": np.arange(-5, 34, 5),
"x_labeled_nums": np.arange(0, 40, 5),
-
}
def construct(self):
data = [20, 0, 0, -5]
x = [0, 8, 38, 39]
- self.setup_axes(animate=True)
+ self.setup_axes()
dot_collection = VGroup()
for time, val in enumerate(data):
dot = Dot().move_to(self.coords_to_point(x[time], val))
@@ -175,15 +160,13 @@ Examples to illustrate the use of :class:`.GraphScene` in manim.
self.add(l1, l2, l3)
-The following example illustrates how to draw parametric function plots.
-
-.. manim:: ParamFunc1
- :quality: medium
+.. manim:: ParametricFunctionWithoutGraphScene
:save_last_frame:
- class ParamFunc1(Scene):
- def func(self,t):
- return np.array((np.sin(2*t), np.sin(3*t),0))
- def construct(self):
- func=ParametricFunction(self.func, t_max=TAU, fill_opacity=0).set_color(RED)
- self.add(func.scale(3))
+ class ParametricFunctionWithoutGraphScene(Scene):
+ def func(self, t):
+ return np.array((np.sin(2 * t), np.sin(3 * t), 0))
+
+ def construct(self):
+ func = ParametricFunction(self.func, t_max = TAU, fill_opacity=0).set_color(RED)
+ self.add(func.scale(3))
diff --git a/docs/source/examples/shapes.rst b/docs/source/examples/shapes.rst
index 88888e107..d7057b41c 100644
--- a/docs/source/examples/shapes.rst
+++ b/docs/source/examples/shapes.rst
@@ -1,11 +1,10 @@
-Shapes
+Shapes & Images
=================================
-.. manim:: Shape1
- :quality: medium
+.. manim:: Example1Shape
:save_last_frame:
- class Shape1(Scene):
+ class Example1Shape(Scene):
def construct(self):
d = Dot()
c = Circle()
@@ -16,3 +15,29 @@ Shapes
t.next_to(c, DOWN)
self.add(d, c, s, t)
self.wait(1)
+
+.. manim:: Example1ImageFromArray
+ :save_last_frame:
+
+ class Example1ImageFromArray(Scene):
+ def construct(self):
+ image = ImageMobject(np.uint8([[0, 100, 30, 200],
+ [255, 0, 5, 33]]))
+ image.set_height(7)
+ self.add(image)
+
+.. manim:: Example2ImageFromFile
+ :save_last_frame:
+
+ class Example2ImageFromFile(Scene):
+ def construct(self):
+ # Use PIL when you want to import an image from the web
+ import requests
+ from PIL import Image
+ img = Image.open(requests.get("https://raw.githubusercontent.com/ManimCommunity/manim/master/logo/cropped.png",
+ stream=True).raw)
+ img_mobject = ImageMobject(img)
+ # this line, when you want to import your Image on your machine
+ # img_mobject = ImageMobject("<your image address>")
+ img_mobject.scale(3)
+ self.add(img_mobject)
diff --git a/docs/source/examples/text.rst b/docs/source/examples/text.rst
index f9813a57c..724dea445 100644
--- a/docs/source/examples/text.rst
+++ b/docs/source/examples/text.rst
@@ -1,12 +1,116 @@
Text
=================================
-.. manim:: Text1
- :quality: medium
+.. manim:: Example1Text
:save_last_frame:
- class Text1(Scene):
+ class Example1Text(Scene):
def construct(self):
- t = TextMobject("Hello World")
- self.add(t)
+ text = Text('Hello world').scale(3)
+ self.add(text)
+
+.. manim:: Example2Text
+ :save_last_frame:
+
+ class Example2Text(Scene):
+ def construct(self):
+ text = Text('Hello world', color=BLUE).scale(3)
+ self.add(text)
+
+
+.. manim:: Example3Text
+ :save_last_frame:
+
+ class Example3Text(Scene):
+ def construct(self):
+ text = Text('Hello world', gradient=(BLUE, GREEN)).scale(3)
+ self.add(text)
+
+
+.. manim:: Example4Text
+ :save_last_frame:
+
+ class Example4Text(Scene):
+ def construct(self):
+ text = Text('Hello world', t2g={'world':(BLUE, GREEN)}).scale(3)
+ self.add(text)
+
+.. manim:: Example5Text
+ :save_last_frame:
+
+ class Example5Text(Scene):
+ def construct(self):
+ text = Text('Hello world', font='Source Han Sans').scale(3)
+ self.add(text)
+
+.. manim:: Example5bText
+ :save_last_frame:
+
+ class Example5bText(Scene):
+ def construct(self):
+ text = Text('Hello world', t2f={'world':'Forte'}).scale(3)
+ self.add(text)
+
+.. manim:: Example6Text
+ :save_last_frame:
+
+ class Example6Text(Scene):
+ def construct(self):
+ text = Text('Hello world', slant=ITALIC).scale(3)
+ self.add(text)
+
+.. manim:: Example7Text
+ :save_last_frame:
+
+ class Example7Text(Scene):
+ def construct(self):
+ text = Text('Hello world!', t2s={'world':ITALIC}).scale(3)
+ self.add(text)
+
+.. manim:: Example8Text
+ :save_last_frame:
+
+ class Example8Text(Scene):
+ def construct(self):
+ text = Text('Hello world', weight=BOLD).scale(3)
+ self.add(text)
+
+.. manim:: Example9Text
+ :save_last_frame:
+
+ class Example9Text(Scene):
+ def construct(self):
+ text = Text('Hello world', t2w={'world':BOLD}).scale(3)
+ self.add(text)
+
+.. manim:: Example10Text
+ :save_last_frame:
+
+ class Example10Text(Scene):
+ def construct(self):
+ text = Text('Hello', size=0.3).scale(3)
+ self.add(text)
+
+.. manim:: Example11Text
+ :save_last_frame:
+
+ class Example11Text(Scene):
+ def construct(self):
+ text = Text('Hello\nWorld', lsh=1.5).scale(3)
+ self.add(text)
+
+.. manim:: Example12Text
+ :save_last_frame:
+
+ class Example12Text(Scene):
+ def construct(self):
+ text = Text(
+ 'Google',
+ t2c={'[:1]':'#3174f0', '[1:2]':'#e53125',
+ '[2:3]':'#fbb003', '[3:4]':'#3174f0',
+ '[4:5]':'#269a43', '[5:]':'#e53125', }).scale(3)
+ self.add(text)
+
+`Text` works also with other languages like `你好` or `こんにちは` or `안녕하세요` or `مرحبا بالعالم`.
+Be sure you have the font that supports those languages!
diff --git a/docs/source/manim_directive.py b/docs/source/manim_directive.py
index cf92b4c0d..882512b3c 100644
--- a/docs/source/manim_directive.py
+++ b/docs/source/manim_directive.py
@@ -106,9 +106,9 @@ class ManimDirective(Directive):
save_last_frame = "save_last_frame" in self.options
assert not (save_as_gif and save_last_frame)
- frame_rate = config["frame_rate"]
- pixel_height = config["pixel_height"]
- pixel_width = config["pixel_width"]
+ frame_rate = 30
+ pixel_height = 480
+ pixel_width = 854
if "quality" in self.options:
quality = self.options["quality"]
diff --git a/docs/source/tutorials/building_blocks.rst b/docs/source/tutorials/building_blocks.rst
index 96a4f8a27..41f4ad5a5 100644
--- a/docs/source/tutorials/building_blocks.rst
+++ b/docs/source/tutorials/building_blocks.rst
@@ -61,7 +61,6 @@ screen, simply call the :meth:`~.Scene.remove` method from the containing
:class:`.Scene`.
.. manim:: CreatingMobjects
- :quality: medium
class CreatingMobjects(Scene):
def construct(self):
@@ -80,7 +79,6 @@ some mobjects to it. This script generates a static picture that displays a
circle, a square, and a triangle:
.. manim:: Shapes
- :quality: medium
class Shapes(Scene):
def construct(self):
@@ -112,7 +110,6 @@ There are many other possible ways to place mobjects on the screen, for example
``MobjectPlacement`` uses all three.
.. manim:: MobjectPlacement
- :quality: medium
class MobjectPlacement(Scene):
def construct(self):
@@ -160,7 +157,6 @@ Styling mobjects
The following scene changes the default aesthetics of the mobjects.
.. manim:: MobjectStyling
- :quality: medium
class MobjectStyling(Scene):
def construct(self):
@@ -196,7 +192,6 @@ The next scene is exactly the same as the ``MobjectStyling`` scene from the
previous section, except for exactly one line.
.. manim:: MobjectZOrder
- :quality: medium
class MobjectZOrder(Scene):
def construct(self):
@@ -229,7 +224,6 @@ At the heart of manim is animation. Generally, you can add an animation to
your scene by calling the :meth:`~.Scene.play` method.
.. manim:: SomeAnimations
- :quality: medium
class SomeAnimations(Scene):
def construct(self):
@@ -265,7 +259,6 @@ method that changes a mobject's property can be used as an animation, through
the use of :class:`.ApplyMethod`.
.. manim:: ApplyMethodExample
- :quality: medium
class ApplyMethodExample(Scene):
def construct(self):
@@ -293,7 +286,6 @@ By default, any animation passed to :meth:`play` lasts for exactly one second.
Use the :code:`run_time` argument to control the duration.
.. manim:: RunTime
- :quality: medium
class RunTime(Scene):
def construct(self):
diff --git a/docs/source/tutorials/quickstart.rst b/docs/source/tutorials/quickstart.rst
index 5f1614597..79a834100 100644
--- a/docs/source/tutorials/quickstart.rst
+++ b/docs/source/tutorials/quickstart.rst
@@ -59,7 +59,6 @@ video playing the following animation.
.. manim:: SquareToCircle
:hide_source:
- :quality: low
class SquareToCircle(Scene):
def construct(self):
@@ -155,7 +154,6 @@ The output should look as follows.
.. manim:: SquareToCircle2
:hide_source:
- :quality: low
class SquareToCircle2(Scene):
def construct(self):
diff --git a/manim/mobject/changing.py b/manim/mobject/changing.py
index 38eae65ba..b84e2d99f 100644
--- a/manim/mobject/changing.py
+++ b/manim/mobject/changing.py
@@ -16,7 +16,6 @@ class AnimatedBoundary(VGroup):
Examples
--------
.. manim:: AnimatedBoundaryExample
- :quality: low
class AnimatedBoundaryExample(Scene):
def construct(self):
@@ -89,7 +88,6 @@ class TracedPath(VMobject):
Examples
--------
.. manim:: TracedPathExample
- :quality: low
class TracedPathExample(Scene):
def construct(self):
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py
index 36e2f7a9d..bc06db8b5 100644
--- a/manim/mobject/geometry.py
+++ b/manim/mobject/geometry.py
@@ -903,7 +903,6 @@ class ArrowTip(VMobject):
a custom one like this:
.. manim:: CustomTipExample
- :quality: low
>>> class MyCustomArrowTip(ArrowTip, RegularPolygon):
... def __init__(self, **kwargs):
diff --git a/manim/mobject/value_tracker.py b/manim/mobject/value_tracker.py
index aeeac1478..13ae1d758 100644
--- a/manim/mobject/value_tracker.py
+++ b/manim/mobject/value_tracker.py
@@ -21,7 +21,6 @@ class ValueTracker(Mobject):
Examples
--------
.. manim:: ValueTrackerExample
- :quality: low
class ValueTrackerExample(Scene):
def construct(self):