A community-maintained Python framework for creating mathematical animations.
Reorganize example gallery (#687)
Benjamin Hackle51d7740783a
diff --git a/docs/source/examples.rst b/docs/source/examples.rstindex 5f5fff964..5b2032e94 100644--- a/docs/source/examples.rst+++ b/docs/source/examples.rst@@ -1,14 +1,742 @@+###############Example Gallery-===============--.. toctree::-- examples/shapes_images_positions- examples/annotations- examples/plots- examples/tex- examples/formulas- examples/3d- examples/camera_settings- examples/animations- examples/advanced_projects+###############++This gallery contains a collection of best practice code snippets+together with their corresponding video/image output, illustrating+different functionalities all across the library. Enjoy this taste of Manim!++.. tip::++ This gallery is not the only place in our documentation where you can see explicit+ code and video examples: there are many more in our+ :doc:`reference manual </reference>` -- see, for example, our documentation for+ the modules :mod:`~.tex_mobject`, :mod:`~.geometry`, :mod:`~.moving_camera_scene`,+ and many more.++ Also, visit our `Twitter <https://twitter.com/manim_community/>`_ for more+ *manimations*!+++.. contents:: Overview of thematic video categories+ :backlinks: none+ :local:+++Basic Concepts+==============++.. manim:: ManimCELogo+ :save_last_frame:+ :ref_classes: MathTex Circle Square Triangle++ class ManimCELogo(Scene):+ def construct(self):+ logo_green = "#87c2a5"+ logo_blue = "#525893"+ logo_red = "#e07a5f"+ ds_m = MathTex(r"\mathbb{M}", z_index=20).scale(7)+ ds_m.shift(2.25*LEFT + 1.5*UP)+ circle = Circle(color=logo_green,+ fill_opacity=1,+ z_index=7)+ square = Square(color=logo_blue,+ fill_opacity=1,+ z_index=5)+ triangle = Triangle(color=logo_red,+ fill_opacity=1,+ z_index=3)+ circle.shift(LEFT)+ square.shift(UP)+ triangle.shift(RIGHT)+ logo = VGroup(triangle, square, circle, ds_m) # order matters+ logo.move_to(ORIGIN)+ self.add(logo)+ self.wait()++.. manim:: GradientImageFromArray+ :save_last_frame:+ :ref_classes: ImageMobject++ class GradientImageFromArray(Scene):+ def construct(self):+ n = 256+ imageArray = np.uint8(+ [[i * 256 / n for i in range(0, n)] for _ in range(0, n)]+ )+ image = ImageMobject(imageArray).scale(2)+ self.add(image)++.. manim:: BraceAnnotation+ :save_last_frame:+ :ref_classes: Brace+ :ref_functions: Brace.get_text Brace.get_tex++ class BraceAnnotation(Scene):+ def construct(self):+ dot = Dot([-2, -1, 0])+ dot2 = Dot([2, 1, 0])+ line = Line(dot.get_center(), dot2.get_center()).set_color(ORANGE)+ b1 = Brace(line)+ b1text = b1.get_text("Horizontal distance")+ b2 = Brace(line, direction=line.copy().rotate(PI / 2).get_unit_vector())+ b2text = b2.get_tex("x-x_1")+ self.add(line, dot, dot2, b1, b2, b1text, b2text)++.. manim:: VectorArrow+ :save_last_frame:+ :ref_classes: Dot Arrow NumberPlane Text++ class VectorArrow(Scene):+ def construct(self):+ dot = Dot(ORIGIN)+ arrow = Arrow(ORIGIN, [2, 2, 0], buff=0)+ numberplane = NumberPlane()+ origin_text = Text('(0, 0)').next_to(dot, DOWN)+ tip_text = Text('(2, 2)').next_to(arrow.get_end(), RIGHT)+ self.add(numberplane, dot, arrow, origin_text, tip_text)++.. manim:: BezierSpline+ :save_last_frame:+ :ref_classes: Line VGroup+ :ref_functions: VMobject.add_cubic_bezier_curve++ class BezierSpline(Scene):+ def construct(self):+ np.random.seed(42)+ area = 4++ x1 = np.random.randint(-area, area)+ y1 = np.random.randint(-area, area)+ p1 = np.array([x1, y1, 0])+ destination_dot1 = Dot(point=p1).set_color(BLUE)++ x2 = np.random.randint(-area, area)+ y2 = np.random.randint(-area, area)+ p2 = np.array([x2, y2, 0])+ destination_dot2 = Dot(p2).set_color(RED)++ deltaP = p1 - p2+ deltaPNormalized = deltaP / get_norm(deltaP)++ theta = np.radians(90)+ r = np.array(+ (+ (np.cos(theta), -np.sin(theta), 0),+ (np.sin(theta), np.cos(theta), 0),+ (0, 0, 0),+ )+ )+ senk = r.dot(deltaPNormalized)+ offset = 0.1+ offset_along = 0.5+ offset_connect = 0.25++ dest_line1_point1 = p1 + senk * offset - deltaPNormalized * offset_along+ dest_line1_point2 = p2 + senk * offset + deltaPNormalized * offset_along+ dest_line2_point1 = p1 - senk * offset - deltaPNormalized * offset_along+ dest_line2_point2 = p2 - senk * offset + deltaPNormalized * offset_along+ s1 = p1 - offset_connect * deltaPNormalized+ s2 = p2 + offset_connect * deltaPNormalized+ dest_line1 = Line(dest_line1_point1, dest_line1_point2)+ dest_line2 = Line(dest_line2_point1, dest_line2_point2)++ Lp1s1 = Line(p1, s1)++ Lp1s1.add_cubic_bezier_curve(+ s1,+ s1 - deltaPNormalized * 0.1,+ dest_line2_point1 + deltaPNormalized * 0.1,+ dest_line2_point1 - deltaPNormalized * 0.01,+ )+ Lp1s1.add_cubic_bezier_curve(+ s1,+ s1 - deltaPNormalized * 0.1,+ dest_line1_point1 + deltaPNormalized * 0.1,+ dest_line1_point1,+ )++ Lp2s2 = Line(p2, s2)++ Lp2s2.add_cubic_bezier_curve(+ s2,+ s2 + deltaPNormalized * 0.1,+ dest_line2_point2 - deltaPNormalized * 0.1,+ dest_line2_point2,+ )+ Lp2s2.add_cubic_bezier_curve(+ s2,+ s2 + deltaPNormalized * 0.1,+ dest_line1_point2 - deltaPNormalized * 0.1,+ dest_line1_point2,+ )++ mobjects = VGroup(+ Lp1s1, Lp2s2, dest_line1, dest_line2, destination_dot1, destination_dot2+ )++ mobjects.scale(2)+ self.add(mobjects)+++Animations+==========++.. manim:: PointMovingOnShapes+ :ref_classes: Circle Dot Line GrowFromCenter Transform MoveAlongPath Rotating++ class PointMovingOnShapes(Scene):+ def construct(self):+ circle = Circle(radius=1, color=BLUE)+ dot = Dot()+ dot2 = dot.copy().shift(RIGHT)+ self.add(dot)++ line = Line([3, 0, 0], [5, 0, 0])+ self.add(line)++ self.play(GrowFromCenter(circle))+ self.play(Transform(dot, dot2))+ self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)+ self.play(Rotating(dot, about_point=[2, 0, 0]), run_time=1.5)+ self.wait()++.. manim:: MovingAround+ :ref_functions: Mobject.shift VMobject.set_fill Mobject.scale Mobject.rotate++ class MovingAround(Scene):+ def construct(self):+ square = Square(color=BLUE, fill_opacity=1)++ self.play(square.shift, LEFT)+ self.play(square.set_fill, ORANGE)+ self.play(square.scale, 0.3)+ self.play(square.rotate, 0.4)++.. manim:: MovingFrameBox+ :ref_modules: manim.mobject.svg.tex_mobject+ :ref_classes: MathTex SurroundingRectangle++ class MovingFrameBox(Scene):+ def construct(self):+ text=MathTex(+ "\\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:: RotationUpdater+ :ref_functions: Mobject.add_updater Mobject.remove_updater++ class RotationUpdater(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:: PointWithTrace+ :ref_classes: Rotating+ :ref_functions: VMobject.set_points_as_corners Mobject.add_updater++ class PointWithTrace(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()+++Plotting with Manim+===================++.. manim:: SinAndCosFunctionPlot+ :save_last_frame:+ :ref_modules: manim.scene.graph_scene+ :ref_classes: MathTex+ :ref_functions: GraphScene.setup_axes GraphScene.get_graph GraphScene.get_vertical_line_to_graph GraphScene.input_to_graph_point++ class SinAndCosFunctionPlot(GraphScene):+ CONFIG = {+ "x_min": -10,+ "x_max": 10.3,+ "num_graph_anchor_points": 100,+ "y_min": -1.5,+ "y_max": 1.5,+ "graph_origin": ORIGIN,+ "function_color": RED,+ "axes_color": GREEN,+ "x_labeled_nums": range(-10, 12, 2),+ }++ def construct(self):+ self.setup_axes(animate=False)+ 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)+ 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:: GraphAreaPlot+ :save_last_frame:+ :ref_modules: manim.scenes.graph_scene+ :ref_functions: GraphScene.setup_axes GraphScene.get_graph GraphScene.get_vertical_line_to_graph GraphScene.get_area++ class GraphAreaPlot(GraphScene):+ CONFIG = {+ "x_min" : 0,+ "x_max" : 5,+ "y_min" : 0,+ "y_max" : 6,+ "y_tick_frequency" : 1,+ "x_tick_frequency" : 1,+ "x_labeled_nums" : [0,2,3]+ }+ def construct(self):+ 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)+ area2 = self.get_area(curve2, 2, 3, bounded=curve1)+ self.add(curve1, curve2, line1, line2, area1, area2)++.. manim:: HeatDiagramPlot+ :save_last_frame:+ :ref_modules: manim.scenes.graph_scene+ :ref_functions: GraphScene.setup_axes GraphScene.coords_to_point++ class HeatDiagramPlot(GraphScene):+ CONFIG = {+ "y_axis_label": r"T[$^\circ C$]",+ "x_axis_label": r"$\Delta Q$",+ "y_min": -8,+ "y_max": 30,+ "x_min": 0,+ "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()+ dot_collection = VGroup()+ for time, val in enumerate(data):+ dot = Dot().move_to(self.coords_to_point(x[time], val))+ self.add(dot)+ dot_collection.add(dot)+ l1 = Line(dot_collection[0].get_center(), dot_collection[1].get_center())+ l2 = Line(dot_collection[1].get_center(), dot_collection[2].get_center())+ l3 = Line(dot_collection[2].get_center(), dot_collection[3].get_center())+ self.add(l1, l2, l3)+++Special Camera Settings+=======================++.. manim:: FollowingGraphCamera+ :ref_modules: manim.scene.moving_camera_scene+ :ref_classes: GraphScene MovingCameraScene MoveAlongPath Restore+ :ref_functions: Mobject.add_updater++ class FollowingGraphCamera(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))++.. manim:: MovingZoomedSceneAround+ :ref_modules: manim.scene.zoomed_scene+ :ref_classes: ZoomedScene BackgroundRectangle UpdateFromFunc+ :ref_functions: Mobject.add_updater ZoomedScene.get_zoomed_display_pop_out_animation++ class MovingZoomedSceneAround(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 = Text("Frame", color=PURPLE).scale(1.4)+ zoomed_camera_text = Text("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), FadeInFrom(frame_text, direction=DOWN))+ 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(FadeInFrom(zoomed_camera_text, direction=DOWN))+ # 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()++.. manim:: FixedInFrameMObjectTest+ :save_last_frame:+ :ref_classes: ThreeDScene+ :ref_functions: ThreeDScene.set_camera_orientation ThreeDScene.add_fixed_in_frame_mobjects++ class FixedInFrameMObjectTest(ThreeDScene):+ def construct(self):+ axes = ThreeDAxes()+ self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)+ text3d = Text("This is a 3D text")+ self.add_fixed_in_frame_mobjects(text3d)+ text3d.to_corner(UL)+ self.add(axes)+ self.wait()++.. manim:: ThreeDLightSourcePosition+ :save_last_frame:+ :ref_classes: ThreeDScene ThreeDAxes ParametricSurface+ :ref_functions: ThreeDScene.set_camera_orientation++ class ThreeDLightSourcePosition(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.renderer.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:: ThreeDCameraRotation+ :ref_classes: ThreeDScene ThreeDAxes+ :ref_functions: ThreeDScene.begin_ambient_camera_rotation ThreeDScene.stop_ambient_camera_rotation++ class ThreeDCameraRotation(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:: ThreeDCameraIllusionRotation+ :ref_classes: ThreeDScene ThreeDAxes+ :ref_functions: ThreeDScene.begin_3dillusion_camera_rotation ThreeDScene.stop_3dillusion_camera_rotation++ class ThreeDCameraIllusionRotation(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:: ThreeDFunctionPlot+ :ref_classes: ThreeDScene ParametricSurface++ class ThreeDFunctionPlot(ThreeDScene):+ def construct(self):+ resolution_fa = 22+ self.set_camera_orientation(phi=75 * DEGREES, theta=-30 * DEGREES)++ def param_plane(u, v):+ x = u+ y = v+ z = 0+ return np.array([x, y, z])++ plane = ParametricSurface(+ param_plane,+ resolution=(resolution_fa, resolution_fa),+ v_min=-2,+ v_max=+2,+ u_min=-2,+ u_max=+2,+ )+ plane.scale_about_point(2, ORIGIN)++ def param_gauss(u, v):+ x = u+ y = v+ d = np.sqrt(x * x + y * y)+ sigma, mu = 0.4, 0.0+ z = np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))+ return np.array([x, y, z])++ gauss_plane = ParametricSurface(+ param_gauss,+ resolution=(resolution_fa, resolution_fa),+ v_min=-2,+ v_max=+2,+ u_min=-2,+ u_max=+2,+ )++ gauss_plane.scale_about_point(2, ORIGIN)+ gauss_plane.set_style(fill_opacity=1)+ gauss_plane.set_style(stroke_color=GREEN)+ gauss_plane.set_fill_by_checkerboard(GREEN, BLUE, opacity=0.1)++ axes = ThreeDAxes()++ self.add(axes)+ self.play(Write(plane))+ self.play(Transform(plane, gauss_plane))+ self.wait()+++Advanced Projects+=================++.. manim:: OpeningManim+ :ref_classes: Tex MathTex Write FadeInFrom LaggedStart NumberPlane ShowCreation+ :ref_functions: NumberPlane.prepare_for_nonlinear_transform++ class OpeningManim(Scene):+ def construct(self):+ title = Tex("This is some \\LaTeX")+ basel = MathTex("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")+ VGroup(title, basel).arrange(DOWN)+ self.play(+ Write(title),+ FadeInFrom(basel, UP),+ )+ self.wait()++ transform_title = Tex("That was a transform")+ transform_title.to_corner(UP + LEFT)+ self.play(+ Transform(title, transform_title),+ LaggedStart(*map(lambda obj: FadeOutAndShift(obj, direction=DOWN), basel)),+ )+ self.wait()++ grid = NumberPlane()+ grid_title = Tex("This is a grid")+ grid_title.scale(1.5)+ grid_title.move_to(transform_title)++ self.add(grid, grid_title) # Make sure title is on top of grid+ self.play(+ FadeOut(title),+ FadeInFrom(grid_title, direction=DOWN),+ ShowCreation(grid, run_time=3, lag_ratio=0.1),+ )+ self.wait()++ grid_transform_title = Tex(+ "That was a non-linear function \\\\" "applied to the grid"+ )+ grid_transform_title.move_to(grid_title, UL)+ grid.prepare_for_nonlinear_transform()+ self.play(+ grid.apply_function,+ lambda p: p+ + np.array(+ [+ np.sin(p[1]),+ np.sin(p[0]),+ 0,+ ]+ ),+ run_time=3,+ )+ self.wait()+ self.play(Transform(grid_title, grid_transform_title))+ self.wait()++.. manim:: SineCurveUnitCircle+ :ref_classes: MathTex Circle Dot Line VGroup+ :ref_functions: Mobject.add_updater Mobject.remove_updater always_redraw++ class SineCurveUnitCircle(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 = [+ MathTex("\pi"), MathTex("2 \pi"),+ MathTex("3 \pi"), MathTex("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/3d.rst b/docs/source/examples/3d.rstdeleted file mode 100644index 02e98539b..000000000--- a/docs/source/examples/3d.rst+++ /dev/null@@ -1,147 +0,0 @@--3D Scenes-=================================--.. manim:: FixedInFrameMObjectTest- :save_last_frame:-- class FixedInFrameMObjectTest(ThreeDScene):- def construct(self):- axes = ThreeDAxes()- self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)- text3d = Text("This is a 3D text")- self.add_fixed_in_frame_mobjects(text3d)- text3d.to_corner(UL)- self.add(axes)- self.wait()---.. manim:: ThreeDSphere- :save_last_frame:-- class ThreeDSphere(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.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)- self.add(axes, sphere)--.. manim:: ThreeDLightSourcePosition- :save_last_frame:-- class ThreeDLightSourcePosition(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.renderer.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:: ThreeDCameraRotation-- class ThreeDCameraRotation(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:: ThreeDCameraIllusionRotation-- class ThreeDCameraIllusionRotation(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:: ThreeDParametricSpring- :save_last_frame:-- class ThreeDParametricSpring(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()--.. manim:: ThreeDFunctionPlot-- class ThreeDFunctionPlot(ThreeDScene):- def construct(self):- resolution_fa = 22- self.set_camera_orientation(phi=75 * DEGREES, theta=-30 * DEGREES)-- def param_plane(u, v):- x = u- y = v- z = 0- return np.array([x, y, z])-- plane = ParametricSurface(- param_plane,- resolution=(resolution_fa, resolution_fa),- v_min=-2,- v_max=+2,- u_min=-2,- u_max=+2,- )- plane.scale_about_point(2, ORIGIN)-- def param_gauss(u, v):- x = u- y = v- d = np.sqrt(x * x + y * y)- sigma, mu = 0.4, 0.0- z = np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))- return np.array([x, y, z])-- gauss_plane = ParametricSurface(- param_gauss,- resolution=(resolution_fa, resolution_fa),- v_min=-2,- v_max=+2,- u_min=-2,- u_max=+2,- )-- gauss_plane.scale_about_point(2, ORIGIN)- gauss_plane.set_style(fill_opacity=1)- gauss_plane.set_style(stroke_color=GREEN)- gauss_plane.set_fill_by_checkerboard(GREEN, BLUE, opacity=0.1)-- axes = ThreeDAxes()-- self.add(axes)- self.play(Write(plane))- self.play(Transform(plane, gauss_plane))- self.wait()diff --git a/docs/source/examples/advanced_projects.rst b/docs/source/examples/advanced_projects.rstdeleted file mode 100644index 9e4552571..000000000--- a/docs/source/examples/advanced_projects.rst+++ /dev/null@@ -1,332 +0,0 @@-Advanced Projects-=================================--.. manim:: OpeningManim- :ref_classes: Tex MathTex NumberPlane-- class OpeningManim(Scene):- def construct(self):- title = Tex("This is some \\LaTeX")- basel = MathTex("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")- VGroup(title, basel).arrange(DOWN)- self.play(- Write(title),- FadeInFrom(basel, UP),- )- self.wait()-- transform_title = Tex("That was a transform")- transform_title.to_corner(UP + LEFT)- self.play(- Transform(title, transform_title),- LaggedStart(*map(lambda obj: FadeOutAndShift(obj, direction=DOWN), basel)),- )- self.wait()-- grid = NumberPlane()- grid_title = Tex("This is a grid")- grid_title.scale(1.5)- grid_title.move_to(transform_title)-- self.add(grid, grid_title) # Make sure title is on top of grid- self.play(- FadeOut(title),- FadeInFrom(grid_title, direction=DOWN),- ShowCreation(grid, run_time=3, lag_ratio=0.1),- )- self.wait()-- grid_transform_title = Tex(- "That was a non-linear function \\\\" "applied to the grid"- )- grid_transform_title.move_to(grid_title, UL)- grid.prepare_for_nonlinear_transform()- self.play(- grid.apply_function,- lambda p: p- + np.array(- [- np.sin(p[1]),- np.sin(p[0]),- 0,- ]- ),- run_time=3,- )- self.wait()- self.play(Transform(grid_title, grid_transform_title))- self.wait()---.. manim:: SquareToCircle- :quality: low-- class SquareToCircle(Scene):- def construct(self):- circle = Circle()- square = Square()- square.flip(RIGHT)- square.rotate(-3 * TAU / 8)- circle.set_fill(PINK, opacity=0.5)-- self.play(ShowCreation(square))- self.play(Transform(square, circle))- self.play(FadeOut(square))---.. manim:: WarpSquare- :quality: low-- class WarpSquare(Scene):- def construct(self):- square = Square()- self.play(- ApplyPointwiseFunction(- lambda point: complex_to_R3(np.exp(R3_to_complex(point))), square- )- )- self.wait()--.. manim:: WriteStuff- :quality: low-- class WriteStuff(Scene):- def construct(self):- example_text = Tex("This is a some text", tex_to_color_map={"text": YELLOW})- example_tex = MathTex(- "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",- )- group = VGroup(example_text, example_tex)- group.arrange(DOWN)- group.set_width(config["frame_width"] - 2 * LARGE_BUFF)-- self.play(Write(example_text))- self.play(Write(example_tex))- self.wait()--.. manim:: SquareMovingWithUpdaters- :quality: low-- class SquareMovingWithUpdaters(Scene):- def construct(self):- decimal = DecimalNumber(- 0,- show_ellipsis=True,- num_decimal_places=3,- include_sign=True,- )- square = Square().to_edge(UP)-- decimal.add_updater(lambda d: d.next_to(square, RIGHT))- decimal.add_updater(lambda d: d.set_value(square.get_center()[1]))- self.add(square, decimal)- self.play(- square.to_edge,- DOWN,- rate_func=there_and_back,- run_time=5,- )- self.wait()---.. manim:: ShapesWithVDics- :quality: low-- class ShapesWithVDics(Scene):- def construct(self):- square = Square().set_color(RED)- circle = Circle().set_color(YELLOW).next_to(square, UP)-- # create dict from list of tuples each having key-mobject pair- pairs = [("s", square), ("c", circle)]- my_dict = VDict(pairs, show_keys=True)-- # display it just like a VGroup- self.play(ShowCreation(my_dict))- self.wait()-- text = Tex("Some text").set_color(GREEN).next_to(square, DOWN)-- # add a key-value pair by wrapping it in a single-element list of tuple- # after attrs branch is merged, it will be easier like `.add(t=text)`- my_dict.add([("t", text)])- self.wait()-- rect = Rectangle().next_to(text, DOWN)- # can also do key assignment like a python dict- my_dict["r"] = rect-- # access submobjects like a python dict- my_dict["t"].set_color(PURPLE)- self.play(my_dict["t"].scale, 3)- self.wait()-- # also supports python dict styled reassignment- my_dict["t"] = Tex("Some other text").set_color(BLUE)- self.wait()-- # remove submoject by key- my_dict.remove("t")- self.wait()-- self.play(Uncreate(my_dict["s"]))- self.wait()-- self.play(FadeOut(my_dict["c"]))- self.wait()-- self.play(FadeOutAndShift(my_dict["r"], DOWN))- self.wait()-- # you can also make a VDict from an existing dict of mobjects- plain_dict = {- 1: Integer(1).shift(DOWN),- 2: Integer(2).shift(2 * DOWN),- 3: Integer(3).shift(3 * DOWN),- }-- vdict_from_plain_dict = VDict(plain_dict)- vdict_from_plain_dict.shift(1.5 * (UP + LEFT))- self.play(ShowCreation(vdict_from_plain_dict))-- # you can even use zip- vdict_using_zip = VDict(zip(["s", "c", "r"], [Square(), Circle(), Rectangle()]))- vdict_using_zip.shift(1.5 * RIGHT)- self.play(ShowCreation(vdict_using_zip))- self.wait()---.. manim:: VariablesWithValueTracker- :quality: low-- class VariablesWithValueTracker(Scene):- def construct(self):- var = 0.5- on_screen_var = Variable(var, Text("var"), num_decimal_places=3)-- # You can also change the colours for the label and value- on_screen_var.label.set_color(RED)- on_screen_var.value.set_color(GREEN)-- self.play(Write(on_screen_var))- # The above line will just display the variable with- # its initial value on the screen. If you also wish to- # update it, you can do so by accessing the `tracker` attribute- self.wait()- var_tracker = on_screen_var.tracker- var = 10.5- self.play(var_tracker.set_value, var)- self.wait()-- int_var = 0- on_screen_int_var = Variable(- int_var, Text("int_var"), var_type=Integer- ).next_to(on_screen_var, DOWN)- on_screen_int_var.label.set_color(RED)- on_screen_int_var.value.set_color(GREEN)-- self.play(Write(on_screen_int_var))- self.wait()- var_tracker = on_screen_int_var.tracker- var = 10.5- self.play(var_tracker.set_value, var)- self.wait()-- # If you wish to have a somewhat more complicated label for your- # variable with subscripts, superscripts, etc. the default class- # for the label is MathTex- subscript_label_var = 10- on_screen_subscript_var = Variable(subscript_label_var, "{a}_{i}").next_to(- on_screen_int_var, DOWN- )- self.play(Write(on_screen_subscript_var))- self.wait()--.. manim:: SineCurvePlot-- class SineCurvePlot(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 = [- MathTex("\pi"), MathTex("2 \pi"),- MathTex("3 \pi"), MathTex("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.rstdeleted file mode 100644index 8aeae5567..000000000--- a/docs/source/examples/animations.rst+++ /dev/null@@ -1,143 +0,0 @@-Animations-============---Transformations-#################--Some more examples will come soon here!--Updaters-##########--.. manim:: RotationUpdater-- class RotationUpdater(Scene):- def construct(self):- 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)--.. manim:: RotationUpdater2-- class RotationUpdater2(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:: NumberLinePointer-- class NumberLinePointer(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)- self.wait()--.. manim:: PointWithTrace-- class PointWithTrace(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:: PointMovingWithValTracker-- class PointMovingWithValTracker(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:: RotationValTracker-- class RotationValTracker(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)--.. manim:: PlaneFadeOut-- class PlaneFadeOut(Scene):- def construct(self):- sq2 = Square()-- sq1 = Square()- sq1.next_to(sq2, LEFT)-- sq3 = Square()- sq3.next_to(sq2, RIGHT)-- circ = Circle()- circ.next_to(sq2, DOWN)-- self.add(sq1, sq2, sq3, circ)- self.wait()-- self.play(FadeOut(sq1), FadeOut(sq2), FadeOut(sq3))- self.wait()--.. manim:: FadeInAndOut-- class FadeInAndOut(Scene):- def construct(self):- square = Square(color=BLUE).shift(2 * UP)- annotation = Text("Fade In", height=0.8)- self.add(annotation)- self.play(FadeIn(square))-- annotation.become(Text("Fade Out", height=0.8))- self.add(annotation)- self.play(FadeOut(square))diff --git a/docs/source/examples/annotations.rst b/docs/source/examples/annotations.rstdeleted file mode 100644index b731b02b7..000000000--- a/docs/source/examples/annotations.rst+++ /dev/null@@ -1,63 +0,0 @@-Annotations-=================================--.. manim:: BraceAnnotation- :save_last_frame:-- class BraceAnnotation(Scene):- def construct(self):- dot = Dot([0, 0, 0])- dot2 = Dot([2, 1, 0])- line = Line(dot.get_center(), dot2.get_center()).set_color(ORANGE)- b1 = Brace(line)- b1text = b1.get_text("Distance")- b2 = Brace(line, direction=line.copy().rotate(PI / 2).get_unit_vector())- b2text = b2.get_tex("x-x_1")- self.add(dot, dot2, line, b1, b2, b1text, b2text)--.. manim:: VectorArrow- :save_last_frame:-- class VectorArrow(Scene):- def construct(self):- dot = Dot(ORIGIN)- arrow = Arrow(ORIGIN, [2, 2, 0], buff=0)- numberplane = NumberPlane()- origin_text = Text('(0, 0)').next_to(dot, DOWN)- tip_text = Text('(2, 2)').next_to(arrow.get_end(), RIGHT)- self.add(numberplane, dot, arrow, origin_text, tip_text)--.. manim:: UsefulAnnotations- :save_last_frame:-- class UsefulAnnotations(Scene):- def construct(self):- m0 = SmallDot()- m1 = AnnotationDot()- m2 = LabeledDot("ii")- m3 = LabeledDot(MathTex(r"\alpha").set_color(ORANGE))- m4 = CurvedArrow(ORIGIN, 2*LEFT)- m5 = CurvedDoubleArrow(ORIGIN, 2*RIGHT)-- self.add(m0, m1, m2, m3, m4, m5)- for i, mobj in enumerate(self.mobjects):- mobj.shift(DOWN * (i-3))--.. manim:: ArrowTipsShowcase- :save_last_frame:-- from manim.mobject.geometry import ArrowTriangleTip, ArrowSquareTip, ArrowSquareFilledTip,\- ArrowCircleTip, ArrowCircleFilledTip- class ArrowTipsShowcase(Scene):- def construct(self):- a00 = Arrow(start=[-2, 3, 0], end=[2, 3, 0], color=YELLOW)- a11 = Arrow(start=[-2, 2, 0], end=[2, 2, 0], tip_shape=ArrowTriangleTip)- a12 = Arrow(start=[-2, 1, 0], end=[2, 1, 0])- a21 = Arrow(start=[-2, 0, 0], end=[2, 0, 0], tip_shape=ArrowSquareTip)- a22 = Arrow([-2, -1, 0], [2, -1, 0], tip_shape=ArrowSquareFilledTip)- a31 = Arrow([-2, -2, 0], [2, -2, 0], tip_shape=ArrowCircleTip)- a32 = Arrow([-2, -3, 0], [2, -3, 0], tip_shape=ArrowCircleFilledTip)- b11 = a11.copy().scale(0.5, scale_tips=True).next_to(a11, RIGHT)- b12 = a12.copy().scale(0.5, scale_tips=True).next_to(a12, RIGHT)- b21 = a21.copy().scale(0.5, scale_tips=True).next_to(a21, RIGHT)- self.add(a00, a11, a12, a21, a22, a31, a32, b11, b12, b21)diff --git a/docs/source/examples/camera_settings.rst b/docs/source/examples/camera_settings.rstdeleted file mode 100644index c41fb2f77..000000000--- a/docs/source/examples/camera_settings.rst+++ /dev/null@@ -1,216 +0,0 @@-Camera Settings-=================================--.. manim:: ChangingCameraWidth-- class ChangingCameraWidth(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:: ChangingCameraWidthAndRestore-- class ChangingCameraWidthAndRestore(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:: ChangingCameraWidthAndRevert-- class ChangingCameraWidthAndRevert(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:: MovingCameraCenter-- class MovingCameraCenter(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.wait(0.3)- 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:: MovingAndZoomingCamera-- class MovingAndZoomingCamera(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:: MovingCameraOnGraph-- class MovingCameraOnGraph(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:: FollowingGraphCamera-- class FollowingGraphCamera(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:: UseZoomedScene-- class UseZoomedScene(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:: ChangingZoomScale-- class ChangingZoomScale(ZoomedScene):- CONFIG = {- "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):- 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:: MovingZoomedSceneAround-- class MovingZoomedSceneAround(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 = Text("Frame", color=PURPLE).scale(1.4)- zoomed_camera_text = Text("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), FadeInFrom(frame_text, direction=DOWN))- 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(FadeInFrom(zoomed_camera_text, direction=DOWN))- # 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.rstdeleted file mode 100644index 9642fa4a1..000000000--- a/docs/source/examples/formulas.rst+++ /dev/null@@ -1,51 +0,0 @@-Formulas-=================================-----.. manim:: MovingFrameBox-- class MovingFrameBox(Scene):- def construct(self):- text=MathTex(- "\\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:: MovingBraces-- class MovingBraces(Scene):- def construct(self):- text=MathTex(- "\\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.rstdeleted file mode 100644index 0e1de60b2..000000000--- a/docs/source/examples/plots.rst+++ /dev/null@@ -1,173 +0,0 @@-Plotting with manim-=================================--Examples to illustrate the use of :class:`.GraphScene` in manim.---.. manim:: FunctionPlot- :save_last_frame:-- class FunctionPlot(GraphScene):- def construct(self):- self.setup_axes()- func_graph=self.get_graph(lambda x: np.sin(x))- self.add(func_graph)--.. manim:: FunctionPlotWithLabbeledYAxe- :save_last_frame:-- class FunctionPlotWithLabbeledYAxe(GraphScene):- CONFIG = {- "y_min": 0,- "y_max": 100,- "y_axis_config": {"tick_frequency": 10},- "y_labeled_nums": np.arange(0, 100, 10)- }-- def construct(self):- 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(dot,func_graph)--.. manim:: SequencePlot- :save_last_frame:-- class SequencePlot(GraphScene):- CONFIG = {- "y_axis_label": r"Concentration [\%]",- "x_axis_label": "Time [s]",- }-- def construct(self):- data = [1, 2, 2, 4, 4, 1, 3]- self.setup_axes()- for time, dat in enumerate(data):- dot = Dot().move_to(self.coords_to_point(time, dat))- self.add(dot)--.. manim:: GaussianFunctionPlot1- :save_last_frame:-- amp = 5- mu = 3- sig = 1-- def gaussian(x):- return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))-- class GaussianFunctionPlot1(GraphScene):- def construct(self):- self.setup_axes()- graph = self.get_graph(gaussian, x_min=-1, x_max=10)- graph.set_stroke(width=5)- self.add(graph)--.. manim:: GaussianFunctionPlot2- :save_last_frame:-- class GaussianFunctionPlot2(GraphScene):- def construct(self):- def gaussian(x):- amp = 5- mu = 3- 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)- graph.set_style(stroke_width=5, stroke_color=GREEN)- self.add(graph)---.. manim:: SinAndCosFunctionPlot- :save_last_frame:-- class SinAndCosFunctionPlot(GraphScene):- CONFIG = {- "x_min": -10,- "x_max": 10.3,- "num_graph_anchor_points": 100,- "y_min": -1.5,- "y_max": 1.5,- "graph_origin": ORIGIN,- "function_color": RED,- "axes_color": GREEN,- "x_labeled_nums": range(-10, 12, 2),- }-- def construct(self):- self.setup_axes(animate=False)- 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)- 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:: GraphAreaPlot- :save_last_frame:-- class GraphAreaPlot(GraphScene):- CONFIG = {- "x_min" : 0,- "x_max" : 5,- "y_min" : 0,- "y_max" : 6,- "y_tick_frequency" : 1,- "x_tick_frequency" : 1,- "x_labeled_nums" : [0,2,3]- }- def construct(self):- 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)- area2 = self.get_area(curve2, 2, 3, bounded=curve1)- self.add(curve1, curve2, line1, line2, area1, area2)--.. manim:: HeatDiagramPlot- :save_last_frame:-- class HeatDiagramPlot(GraphScene):- CONFIG = {- "y_axis_label": r"T[$^\circ C$]",- "x_axis_label": r"$\Delta Q$",- "y_min": -8,- "y_max": 30,- "x_min": 0,- "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()- dot_collection = VGroup()- for time, val in enumerate(data):- dot = Dot().move_to(self.coords_to_point(x[time], val))- self.add(dot)- dot_collection.add(dot)- l1 = Line(dot_collection[0].get_center(), dot_collection[1].get_center())- l2 = Line(dot_collection[1].get_center(), dot_collection[2].get_center())- l3 = Line(dot_collection[2].get_center(), dot_collection[3].get_center())- self.add(l1, l2, l3)---.. manim:: ParametricFunctionWithoutGraphScene- :save_last_frame:-- 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_images_positions.rst b/docs/source/examples/shapes_images_positions.rstdeleted file mode 100644index e66e3b46b..000000000--- a/docs/source/examples/shapes_images_positions.rst+++ /dev/null@@ -1,278 +0,0 @@-Shapes, Images and Positions-=================================-.. manim:: ShowScreenResolution- :save_last_frame:-- class ShowScreenResolution(Scene):- def construct(self):- pixel_height = config["pixel_height"] # 1080 is default- pixel_width = config["pixel_width"] # 1920 is default- frame_width = config["frame_width"]- frame_height = config["frame_height"]- self.add(Dot())- d1 = Line(frame_width * LEFT / 2, frame_width * RIGHT / 2).to_edge(DOWN)- self.add(d1)- self.add(Tex(str(pixel_width)).next_to(d1, UP))- d2 = Line(frame_height * UP / 2, frame_height * DOWN / 2).to_edge(LEFT)- self.add(d2)- self.add(Tex(str(pixel_height)).next_to(d2, RIGHT))---.. manim:: GeometricShapes- :save_last_frame:-- class GeometricShapes(Scene):- def construct(self):- d = Dot()- c = Circle()- s = Square()- t = Triangle()- d.next_to(c, RIGHT)- s.next_to(c, LEFT)- t.next_to(c, DOWN)- self.add(d, c, s, t)--.. manim:: PointMovingOnShapes-- class PointMovingOnShapes(Scene):- def construct(self):- circle = Circle(radius=1, color=BLUE)- dot = Dot()- dot2 = dot.copy().shift(RIGHT)- self.add(dot)-- line = Line([3, 0, 0], [5, 0, 0])- self.add(line)-- self.play(GrowFromCenter(circle))- self.play(Transform(dot, dot2))- self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)- self.play(Rotating(dot, about_point=[2, 0, 0]), run_time=1.5)- self.wait()---.. manim:: ManimCELogo- :save_last_frame:-- class ManimCELogo(Scene):- def construct(self):- logo_green = "#87c2a5"- logo_blue = "#525893"- logo_red = "#e07a5f"- ds_m = MathTex(r"\mathbb{M}", z_index=20).scale(7)- ds_m.shift(2.25*LEFT + 1.5*UP)- circle = Circle(color=logo_green,- fill_opacity=1,- z_index=7)- square = Square(color=logo_blue,- fill_opacity=1,- z_index=5)- triangle = Triangle(color=logo_red,- fill_opacity=1,- z_index=3)- circle.shift(LEFT)- square.shift(UP)- triangle.shift(RIGHT)- self.add(triangle, square, circle, ds_m) # Order matters- self.wait()--Download the resource for the following example `here <https://github.com/ManimCommunity/manim/blob/master/docs/source/_static/manim-logo-sidebar.svg>`_--.. manim:: ManimCELogoFromSVG-- class ManimCELogoFromSVG(Scene):- def construct(self):- v_image = SVGMobject(file_name="manim-logo-sidebar.svg")- self.add(v_image)-- # Custom colors can be defined with hex strings- logo_blue, logo_green, logo_red = "#525893", "#87C2A5", "#E07A5F"-- # An SVG file with multiple objects can be decomposed into- # their subcomponents- triangle = v_image.submobjects[0]- square = v_image.submobjects[1]- circle = v_image.submobjects[2]- m = v_image.submobjects[3]-- self.play(- ApplyMethod(triangle.set_fill, logo_red),- ApplyMethod(square.set_fill, logo_blue),- ApplyMethod(circle.set_fill, logo_green),- ApplyMethod(m.set_fill, WHITE, opacity=1),- )- self.wait()--Download the resource for the following example `here <https://github.com/ManimCommunity/manim/blob/master/docs/source/_static/favicon.ico>`_--.. manim:: ManimCELogoFromImage- :save_last_frame:-- class ManimCELogoFromImage(Scene):- def construct(self):- image = ImageMobject(filename_or_array="favicon.ico")- self.add(image)--.. manim:: GradientImageFromArray- :save_last_frame:-- class GradientImageFromArray(Scene):- def construct(self):- n = 256- imageArray = np.uint8(- [[i * 256 / n for i in range(0, n)] for _ in range(0, n)]- )- image = ImageMobject(imageArray).scale(2)- self.add(image)---.. manim:: ArcShapeIris- :save_last_frame:-- class ArcShapeIris(Scene):- def construct(self):- colors = [DARK_BLUE, DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]- radius = [1 + rad * 0.1 for rad in range(len(colors))]-- circles_group = VGroup()-- # zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]- circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)- for rad, col in zip(radius, colors)])- self.add(circles_group)---.. manim:: DotInterpolation- :save_last_frame:-- class DotInterpolation(Scene):- def construct(self):- dotL = Dot(color=DARK_GREY)- dotL.shift(2 * RIGHT)- dotR = Dot(color=WHITE)- dotR.shift(2 * LEFT)-- dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)-- self.add(dotL, dotR, dotMiddle)---.. manim:: MovingAround-- class MovingAround(Scene):- def construct(self):- square = Square(color=BLUE, fill_opacity=1)-- self.play(square.shift, LEFT)- self.play(square.set_fill, ORANGE)- self.play(square.scale, 0.3)- self.play(square.rotate, 0.4)---.. manim:: TextAlignement- :save_last_frame:-- class TextAlignement(Scene):- def construct(self):- title = Text("K-means clustering and Logistic Regression", color=WHITE)- title.scale_in_place(0.75)- self.add(title.to_edge(UP))-- t1 = Text("1. Measuring").set_color(WHITE)- t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP)-- t2 = Text("2. Clustering").set_color(WHITE)- t2.next_to(t1, direction=DOWN, aligned_edge=LEFT)-- t3 = Text("3. Regression").set_color(WHITE)- t3.next_to(t2, direction=DOWN, aligned_edge=LEFT)-- t4 = Text("4. Prediction").set_color(WHITE)- t4.next_to(t3, direction=DOWN, aligned_edge=LEFT)-- x = VGroup(t1, t2, t3, t4).scale_in_place(0.7)- x.set_opacity(0.5)- x.submobjects[1].set_opacity(1)- self.add(x)---.. manim:: BezierSpline- :save_last_frame:-- class BezierSpline(Scene):- def construct(self):- np.random.seed(42)- area = 4-- x1 = np.random.randint(-area, area)- y1 = np.random.randint(-area, area)- p1 = np.array([x1, y1, 0])- destination_dot1 = Dot(point=p1).set_color(BLUE)-- x2 = np.random.randint(-area, area)- y2 = np.random.randint(-area, area)- p2 = np.array([x2, y2, 0])- destination_dot2 = Dot(p2).set_color(RED)-- deltaP = p1 - p2- deltaPNormalized = deltaP / get_norm(deltaP)-- theta = np.radians(90)- r = np.array(- (- (np.cos(theta), -np.sin(theta), 0),- (np.sin(theta), np.cos(theta), 0),- (0, 0, 0),- )- )- senk = r.dot(deltaPNormalized)- offset = 0.1- offset_along = 0.5- offset_connect = 0.25-- dest_line1_point1 = p1 + senk * offset - deltaPNormalized * offset_along- dest_line1_point2 = p2 + senk * offset + deltaPNormalized * offset_along- dest_line2_point1 = p1 - senk * offset - deltaPNormalized * offset_along- dest_line2_point2 = p2 - senk * offset + deltaPNormalized * offset_along- s1 = p1 - offset_connect * deltaPNormalized- s2 = p2 + offset_connect * deltaPNormalized- dest_line1 = Line(dest_line1_point1, dest_line1_point2)- dest_line2 = Line(dest_line2_point1, dest_line2_point2)-- Lp1s1 = Line(p1, s1)-- Lp1s1.add_cubic_bezier_curve(- s1,- s1 - deltaPNormalized * 0.1,- dest_line2_point1 + deltaPNormalized * 0.1,- dest_line2_point1 - deltaPNormalized * 0.01,- )- Lp1s1.add_cubic_bezier_curve(- s1,- s1 - deltaPNormalized * 0.1,- dest_line1_point1 + deltaPNormalized * 0.1,- dest_line1_point1,- )-- Lp2s2 = Line(p2, s2)-- Lp2s2.add_cubic_bezier_curve(- s2,- s2 + deltaPNormalized * 0.1,- dest_line2_point2 - deltaPNormalized * 0.1,- dest_line2_point2,- )- Lp2s2.add_cubic_bezier_curve(- s2,- s2 + deltaPNormalized * 0.1,- dest_line1_point2 - deltaPNormalized * 0.1,- dest_line1_point2,- )-- mobjects = VGroup(- Lp1s1, Lp2s2, dest_line1, dest_line2, destination_dot1, destination_dot2- )-- mobjects.scale(2)- self.add(mobjects)-diff --git a/docs/source/examples/tex.rst b/docs/source/examples/tex.rstdeleted file mode 100644index 7e793e87e..000000000--- a/docs/source/examples/tex.rst+++ /dev/null@@ -1,161 +0,0 @@-Text and LaTeX-===============---Text----------------The simplest way to add text to you animation is to use the :class:`~.Text` class. It uses the Pango library to render text.-With Pango, you are also able to render non-English alphabets like `你好` or `こんにちは` or `안녕하세요` or `مرحبا بالعالم`.--The Text() mobject-+++++++++++++++++++--.. manim:: HelloWorld- :save_last_frame:-- class HelloWorld(Scene):- def construct(self):- text = Text('Hello world').scale(3)- self.add(text)--For more examples, see: :class:`~.Text`.---LaTeX----------------------The Tex() mobject-+++++++++++++++++++-Just as you can use :class:`~.Text` to add text to your videos, you can use :class:`~.Tex` to insert LaTeX.--.. manim:: HelloLaTeX- :save_last_frame:-- class HelloLaTeX(Scene):- def construct(self):- tex = Tex(r'\LaTeX').scale(3)- self.add(tex)--Note that we are using a raw string (``r'---'``) instead of a regular string (``'---'``).-This is because TeX code uses a lot of special characters - like ``\`` for example --that have special meaning within a regular python string. An alternative would have-been to write ``\\`` as in ``Tex('\\LaTeX')``.--The MathTex() mobject-++++++++++++++++++++++-Anything enclosed in ``$`` signs is interpreted as maths-mode:--.. manim:: HelloTex- :save_last_frame:-- class HelloTex(Scene):- def construct(self):- tex = Tex(r'$\xrightarrow{Hello}$ \LaTeX').scale(3)- self.add(tex)--Whereas in a :class:`~.MathTex` mobject everything is math-mode by default and you would use ``\text{}`` to-insert regular text:--.. manim:: HelloMathTex- :save_last_frame:-- class HelloMathTex(Scene):- def construct(self):- tex = MathTex(r'\xrightarrow{Hello}\text{ \LaTeX}').scale(3)- self.add(tex)--LaTeX commands and keyword arguments-+++++++++++++++++++++++++++++++++++++-We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` text type.--.. manim:: AMSLaTeX- :save_last_frame:-- class AMSLaTeX(Scene):- def construct(self):- tex = Tex(r'$\mathtt{Hello}$ \LaTeX').scale(3)- self.add(tex)--On the manim side, the :class:`~.Tex` class also accepts attributes to change the appearance of the output.-This is very similar to the :class:`~.Text` class. For example, the ``color`` keyword changes the color of the TeX mobject:--.. manim:: LaTeXAttributes- :save_last_frame:-- class LaTeXAttributes(Scene):- def construct(self):- tex = Tex(r'Hello \LaTeX', color=BLUE).scale(3)- self.add(tex)--Extra LaTeX Packages-+++++++++++++++++++++-Some commands require special packages to be loaded into the TeX template. For example,-to use the ``mathscr`` script, we need to add the ``mathrsfs`` package. Since this package isn't loaded-into manim's tex template by default, we add it manually:--.. manim:: AddPackageLatex- :save_last_frame:-- class AddPackageLatex(Scene):- def construct(self):- myTemplate = TexTemplate()- myTemplate.add_to_preamble(r"\usepackage{mathrsfs}")- tex = Tex(r'$\mathscr{H} \rightarrow \mathbb{H}$}', tex_template=myTemplate).scale(3)- self.add(tex)--Substrings and parts-+++++++++++++++++++++-The TeX mobject can accept multiple strings as arguments. Afterwards you can refer to the individual-parts either by their index (like ``tex[1]``), or you can look them up by (parts of) the tex code like-in this example where we set the color of the ``\bigstar`` using :func:`~.set_color_by_tex`:--.. manim:: LaTeXSubstrings- :save_last_frame:-- class LaTeXSubstrings(Scene):- def construct(self):- tex = Tex('Hello', r'$\bigstar$', r'\LaTeX').scale(3)- tex.set_color_by_tex('igsta', RED)- self.add(tex)--LaTeX Maths Fonts - The Template Library-++++++++++++++++++++++++++++++++++++++++++++-Changing fonts in LaTeX when typesetting mathematical formulae is a little bit more tricky than-with regular text. It requires changing the template that is used to compile the tex code.-Manim comes with a collection of :class:`~.TexFontTemplates` ready for you to use. These templates will all work-in maths mode:--.. manim:: LaTeXMathFonts- :save_last_frame:-- class LaTeXMathFonts(Scene):- def construct(self):- tex = Tex(r'$f: A \rightarrow B$', tex_template=TexFontTemplates.french_cursive).scale(3)- self.add(tex)--Manim also has a :class:`~.TexTemplateLibrary` containing the TeX templates used by 3Blue1Brown. One example-is the ctex template, used for typesetting Chinese. For this to work, the ctex LaTeX package-must be installed on your system. Furthermore, if you are only typesetting Text, you probably do not-need :class:`~.Tex` at all, and should use :class:`~.Text` or :class:`~.PangoText` instead.--.. manim:: LaTeXTemplateLibrary- :save_last_frame:-- class LaTeXTemplateLibrary(Scene):- def construct(self):- tex = Tex('Hello 你好 \\LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3)- self.add(tex)---Aligning formulae-++++++++++++++++++-A :class:`~.MathTex` mobject is typeset in the LaTeX ``align*`` environment. This means you can use the ``&`` alignment-character when typesetting multiline formulae:--.. manim:: LaTeXAlignEnvironment- :save_last_frame:-- class LaTeXAlignEnvironment(Scene):- def construct(self):- tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6').scale(2)- self.add(tex)diff --git a/docs/source/manim_directive.py b/docs/source/manim_directive.pyindex 5ce1b1ec2..1ac1f19a6 100644--- a/docs/source/manim_directive.py+++ b/docs/source/manim_directive.py@@ -114,6 +114,7 @@ class ManimDirective(Directive):),"save_as_gif": bool,"save_last_frame": bool,+ "ref_modules": lambda arg: process_name_list(arg, "mod"),"ref_classes": lambda arg: process_name_list(arg, "class"),"ref_functions": lambda arg: process_name_list(arg, "func"),}@@ -134,10 +135,13 @@ class ManimDirective(Directive):save_as_gif = "save_as_gif" in self.optionssave_last_frame = "save_last_frame" in self.optionsassert not (save_as_gif and save_last_frame)- if "ref_classes" in self.options or "ref_functions" in self.options:- ref_classes = self.options.get("ref_classes", [])- ref_functions = self.options.get("ref_functions", [])- ref_content = ref_classes + ref_functions++ ref_content = (+ self.options.get("ref_modules", [])+ + self.options.get("ref_classes", [])+ + self.options.get("ref_functions", [])+ )+ if ref_content:ref_block = f""".. admonition:: Example References:class: example-referencediff --git a/docs/source/tutorials/configuration.rst b/docs/source/tutorials/configuration.rstindex ddfec0a69..053a0a990 100644--- a/docs/source/tutorials/configuration.rst+++ b/docs/source/tutorials/configuration.rst@@ -53,6 +53,26 @@ The global ``config`` object is mean to be the single source of truth for allconfig options. All of the other ways of setting config options ultimatelychange the values of the global ``config`` object.+The following example illustrates the video resolution chosen for examples+rendered in our documentation with a reference frame.++.. manim:: ShowScreenResolution+ :save_last_frame:++ class ShowScreenResolution(Scene):+ def construct(self):+ pixel_height = config["pixel_height"] # 1080 is default+ pixel_width = config["pixel_width"] # 1920 is default+ frame_width = config["frame_width"]+ frame_height = config["frame_height"]+ self.add(Dot())+ d1 = Line(frame_width * LEFT / 2, frame_width * RIGHT / 2).to_edge(DOWN)+ self.add(d1)+ self.add(Text(str(pixel_width)).next_to(d1, UP))+ d2 = Line(frame_height * UP / 2, frame_height * DOWN / 2).to_edge(LEFT)+ self.add(d2)+ self.add(Text(str(pixel_height)).next_to(d2, RIGHT))+Command line arguments**********************diff --git a/manim/animation/fading.py b/manim/animation/fading.pyindex 1e485435c..7d8694ed1 100644--- a/manim/animation/fading.py+++ b/manim/animation/fading.py@@ -30,6 +30,31 @@ DEFAULT_FADE_LAG_RATIO = 0class FadeOut(Transform):+ """A transform fading out the given mobject.++ Examples+ --------++ .. manim:: PlaneFadeOut++ class PlaneFadeOut(Scene):+ def construct(self):+ sq1 = Square()+ sq2 = Square()+ sq3 = Square()+ sq1.next_to(sq2, LEFT)+ sq3.next_to(sq2, RIGHT)+ circ = Circle()+ circ.next_to(sq2, DOWN)++ self.add(sq1, sq2, sq3, circ)+ self.wait()++ self.play(FadeOut(sq1), FadeOut(sq2), FadeOut(sq3))+ self.wait()++ """+CONFIG = {"remover": True,"lag_ratio": DEFAULT_FADE_LAG_RATIO,diff --git a/manim/animation/transform.py b/manim/animation/transform.pyindex e9960ff65..7fa46c56c 100644--- a/manim/animation/transform.py+++ b/manim/animation/transform.py@@ -200,6 +200,26 @@ class ApplyMethod(Transform):class ApplyPointwiseFunction(ApplyMethod):+ """Animation that applies a pointwise function to a mobject.++ Examples+ --------++ .. manim:: WarpSquare+ :quality: low++ class WarpSquare(Scene):+ def construct(self):+ square = Square()+ self.play(+ ApplyPointwiseFunction(+ lambda point: complex_to_R3(np.exp(R3_to_complex(point))), square+ )+ )+ self.wait()++ """+CONFIG = {"run_time": DEFAULT_POINTWISE_FUNCTION_RUN_TIME}def __init__(self, function, mobject, **kwargs):diff --git a/manim/mobject/functions.py b/manim/mobject/functions.pyindex 08e9fb003..f0ac9236d 100644--- a/manim/mobject/functions.py+++ b/manim/mobject/functions.py@@ -13,6 +13,40 @@ import mathclass ParametricFunction(VMobject):+ """A parametric curve.++ Examples+ --------++ .. manim:: PlotParametricFunction+ :save_last_frame:++ class PlotParametricFunction(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))++ .. manim:: ThreeDParametricSpring+ :save_last_frame:++ class ThreeDParametricSpring(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()+ """+CONFIG = {"t_min": 0,"t_max": 1,diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.pyindex 3ed68fba9..b77e2b136 100644--- a/manim/mobject/geometry.py+++ b/manim/mobject/geometry.py@@ -1,4 +1,25 @@-"""Mobjects that are simple geometric shapes."""+r"""Mobjects that are simple geometric shapes.++Examples+--------++.. manim:: UsefulAnnotations+ :save_last_frame:++ class UsefulAnnotations(Scene):+ def construct(self):+ m0 = SmallDot()+ m1 = AnnotationDot()+ m2 = LabeledDot("ii")+ m3 = LabeledDot(MathTex(r"\alpha").set_color(ORANGE))+ m4 = CurvedArrow(ORIGIN, 2*LEFT)+ m5 = CurvedDoubleArrow(ORIGIN, 2*RIGHT)++ self.add(m0, m1, m2, m3, m4, m5)+ for i, mobj in enumerate(self.mobjects):+ mobj.shift(DOWN * (i-3))++"""__all__ = ["TipableVMobject",@@ -947,6 +968,27 @@ class ArrowTip(VMobject):>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]),... tip_style={'fill_opacity': 0, 'stroke_width': 3})+ The following example illustrates the usage of all of the predefined+ arrow tips.++ .. manim:: ArrowTipsShowcase+ :save_last_frame:++ from manim.mobject.geometry import ArrowTriangleTip, ArrowSquareTip, ArrowSquareFilledTip,\+ ArrowCircleTip, ArrowCircleFilledTip+ class ArrowTipsShowcase(Scene):+ def construct(self):+ a00 = Arrow(start=[-2, 3, 0], end=[2, 3, 0], color=YELLOW)+ a11 = Arrow(start=[-2, 2, 0], end=[2, 2, 0], tip_shape=ArrowTriangleTip)+ a12 = Arrow(start=[-2, 1, 0], end=[2, 1, 0])+ a21 = Arrow(start=[-2, 0, 0], end=[2, 0, 0], tip_shape=ArrowSquareTip)+ a22 = Arrow([-2, -1, 0], [2, -1, 0], tip_shape=ArrowSquareFilledTip)+ a31 = Arrow([-2, -2, 0], [2, -2, 0], tip_shape=ArrowCircleTip)+ a32 = Arrow([-2, -3, 0], [2, -3, 0], tip_shape=ArrowCircleFilledTip)+ b11 = a11.copy().scale(0.5, scale_tips=True).next_to(a11, RIGHT)+ b12 = a12.copy().scale(0.5, scale_tips=True).next_to(a12, RIGHT)+ b21 = a21.copy().scale(0.5, scale_tips=True).next_to(a21, RIGHT)+ self.add(a00, a11, a12, a21, a22, a31, a32, b11, b12, b21)"""CONFIG = {diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex f7ed3c1f7..74c7008bb 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -245,6 +245,31 @@ class Mobject(Container):return list(it.chain(*[sm.get_updaters() for sm in self.get_family()]))def add_updater(self, update_function, index=None, call_updater=False):+ """Add an update function to this mobject.++ Examples+ --------++ .. manim:: RotationUpdater++ class RotationUpdater(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)++ """if index is None:self.updaters.append(update_function)else:@@ -473,6 +498,26 @@ class Mobject(Container):index_of_submobject_to_align=None,coor_mask=np.array([1, 1, 1]),):+ """Move this mobject next to another mobject or coordinate.++ Examples+ --------++ .. manim:: GeometricShapes+ :save_last_frame:++ class GeometricShapes(Scene):+ def construct(self):+ d = Dot()+ c = Circle()+ s = Square()+ t = Triangle()+ d.next_to(c, RIGHT)+ s.next_to(c, LEFT)+ t.next_to(c, DOWN)+ self.add(d, c, s, t)++ """if isinstance(mobject_or_point, Mobject):mob = mobject_or_pointif index_of_submobject_to_align is not None:@@ -1115,9 +1160,25 @@ class Mobject(Container):return submob.copy()def interpolate(self, mobject1, mobject2, alpha, path_func=straight_path):- """- Turns self into an interpolation between mobject1- and mobject2.+ """Turns this mobject into an interpolation between ``mobject1``+ and ``mobject2``.++ Examples+ --------++ .. manim:: DotInterpolation+ :save_last_frame:++ class DotInterpolation(Scene):+ def construct(self):+ dotL = Dot(color=DARK_GREY)+ dotL.shift(2 * RIGHT)+ dotR = Dot(color=WHITE)+ dotR.shift(2 * LEFT)++ dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)++ self.add(dotL, dotR, dotMiddle)"""self.points = path_func(mobject1.points, mobject2.points, alpha)self.interpolate_color(mobject1, mobject2, alpha)diff --git a/manim/mobject/numbers.py b/manim/mobject/numbers.pyindex 03c67dd3e..6bfb1a1d5 100644--- a/manim/mobject/numbers.py+++ b/manim/mobject/numbers.py@@ -10,6 +10,36 @@ from ..mobject.value_tracker import ValueTrackerclass DecimalNumber(VMobject):+ """An mobject representing a decimal number.++ Examples+ --------++ .. manim:: MovingSquareWithUpdaters++ class MovingSquareWithUpdaters(Scene):+ def construct(self):+ decimal = DecimalNumber(+ 0,+ show_ellipsis=True,+ num_decimal_places=3,+ include_sign=True,+ )+ square = Square().to_edge(UP)++ decimal.add_updater(lambda d: d.next_to(square, RIGHT))+ decimal.add_updater(lambda d: d.set_value(square.get_center()[1]))+ self.add(square, decimal)+ self.play(+ square.to_edge,+ DOWN,+ rate_func=there_and_back,+ run_time=5,+ )+ self.wait()++ """+CONFIG = {"num_decimal_places": 2,"include_sign": False,@@ -190,6 +220,51 @@ class Variable(VMobject):# Using math mode for the labelon_screen_int_var = Variable(int_var, "{a}_{i}", var_type=Integer)+ .. manim:: VariablesWithValueTracker++ class VariablesWithValueTracker(Scene):+ def construct(self):+ var = 0.5+ on_screen_var = Variable(var, Text("var"), num_decimal_places=3)++ # You can also change the colours for the label and value+ on_screen_var.label.set_color(RED)+ on_screen_var.value.set_color(GREEN)++ self.play(Write(on_screen_var))+ # The above line will just display the variable with+ # its initial value on the screen. If you also wish to+ # update it, you can do so by accessing the `tracker` attribute+ self.wait()+ var_tracker = on_screen_var.tracker+ var = 10.5+ self.play(var_tracker.set_value, var)+ self.wait()++ int_var = 0+ on_screen_int_var = Variable(+ int_var, Text("int_var"), var_type=Integer+ ).next_to(on_screen_var, DOWN)+ on_screen_int_var.label.set_color(RED)+ on_screen_int_var.value.set_color(GREEN)++ self.play(Write(on_screen_int_var))+ self.wait()+ var_tracker = on_screen_int_var.tracker+ var = 10.5+ self.play(var_tracker.set_value, var)+ self.wait()++ # If you wish to have a somewhat more complicated label for your+ # variable with subscripts, superscripts, etc. the default class+ # for the label is MathTex+ subscript_label_var = 10+ on_screen_subscript_var = Variable(subscript_label_var, "{a}_{i}").next_to(+ on_screen_int_var, DOWN+ )+ self.play(Write(on_screen_subscript_var))+ self.wait()+"""def __init__(diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.pyindex f661d0457..7423ae1da 100644--- a/manim/mobject/svg/tex_mobject.py+++ b/manim/mobject/svg/tex_mobject.py@@ -1,4 +1,160 @@-"""Mobjects representing text rendered using LaTeX."""+r"""Mobjects representing text rendered using LaTeX.+++The Tex mobject+++++++++++++++++Just as you can use :class:`~.Text` to add text to your videos, you can use :class:`~.Tex` to insert LaTeX.++.. manim:: HelloLaTeX+ :save_last_frame:++ class HelloLaTeX(Scene):+ def construct(self):+ tex = Tex(r'\LaTeX').scale(3)+ self.add(tex)++Note that we are using a raw string (``r'---'``) instead of a regular string (``'---'``).+This is because TeX code uses a lot of special characters - like ``\`` for example -+that have special meaning within a regular python string. An alternative would have+been to write ``\\`` as in ``Tex('\\LaTeX')``.++The MathTex mobject+++++++++++++++++++++Anything enclosed in ``$`` signs is interpreted as maths-mode:++.. manim:: HelloTex+ :save_last_frame:++ class HelloTex(Scene):+ def construct(self):+ tex = Tex(r'$\xrightarrow{Hello}$ \LaTeX').scale(3)+ self.add(tex)++Whereas in a :class:`~.MathTex` mobject everything is math-mode by default.++.. manim:: MovingBraces++ class MovingBraces(Scene):+ def construct(self):+ text=MathTex(+ "\\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()+++LaTeX commands and keyword arguments++++++++++++++++++++++++++++++++++++++We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` text type.++.. manim:: AMSLaTeX+ :save_last_frame:++ class AMSLaTeX(Scene):+ def construct(self):+ tex = Tex(r'$\mathtt{Hello}$ \LaTeX').scale(3)+ self.add(tex)++On the manim side, the :class:`~.Tex` class also accepts attributes to change the appearance of the output.+This is very similar to the :class:`~.Text` class. For example, the ``color`` keyword changes the color of the TeX mobject:++.. manim:: LaTeXAttributes+ :save_last_frame:++ class LaTeXAttributes(Scene):+ def construct(self):+ tex = Tex(r'Hello \LaTeX', color=BLUE).scale(3)+ self.add(tex)++Extra LaTeX Packages++++++++++++++++++++++Some commands require special packages to be loaded into the TeX template. For example,+to use the ``mathscr`` script, we need to add the ``mathrsfs`` package. Since this package isn't loaded+into manim's tex template by default, we add it manually:++.. manim:: AddPackageLatex+ :save_last_frame:++ class AddPackageLatex(Scene):+ def construct(self):+ myTemplate = TexTemplate()+ myTemplate.add_to_preamble(r"\usepackage{mathrsfs}")+ tex = Tex(r'$\mathscr{H} \rightarrow \mathbb{H}$}', tex_template=myTemplate).scale(3)+ self.add(tex)++Substrings and parts++++++++++++++++++++++The TeX mobject can accept multiple strings as arguments. Afterwards you can refer to the individual+parts either by their index (like ``tex[1]``), or you can look them up by (parts of) the tex code like+in this example where we set the color of the ``\bigstar`` using :func:`~.set_color_by_tex`:++.. manim:: LaTeXSubstrings+ :save_last_frame:++ class LaTeXSubstrings(Scene):+ def construct(self):+ tex = Tex('Hello', r'$\bigstar$', r'\LaTeX').scale(3)+ tex.set_color_by_tex('igsta', RED)+ self.add(tex)++LaTeX Maths Fonts - The Template Library++++++++++++++++++++++++++++++++++++++++++Changing fonts in LaTeX when typesetting mathematical formulae is a little bit more tricky than+with regular text. It requires changing the template that is used to compile the tex code.+Manim comes with a collection of :class:`~.TexFontTemplates` ready for you to use. These templates will all work+in maths mode:++.. manim:: LaTeXMathFonts+ :save_last_frame:++ class LaTeXMathFonts(Scene):+ def construct(self):+ tex = Tex(r'$f: A \rightarrow B$', tex_template=TexFontTemplates.french_cursive).scale(3)+ self.add(tex)++Manim also has a :class:`~.TexTemplateLibrary` containing the TeX templates used by 3Blue1Brown. One example+is the ctex template, used for typesetting Chinese. For this to work, the ctex LaTeX package+must be installed on your system. Furthermore, if you are only typesetting Text, you probably do not+need :class:`~.Tex` at all, and should use :class:`~.Text` or :class:`~.PangoText` instead.++.. manim:: LaTeXTemplateLibrary+ :save_last_frame:++ class LaTeXTemplateLibrary(Scene):+ def construct(self):+ tex = Tex('Hello 你好 \\LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3)+ self.add(tex)+++Aligning formulae+++++++++++++++++++A :class:`~.MathTex` mobject is typeset in the LaTeX ``align*`` environment. This means you can use the ``&`` alignment+character when typesetting multiline formulae:++.. manim:: LaTeXAlignEnvironment+ :save_last_frame:++ class LaTeXAlignEnvironment(Scene):+ def construct(self):+ tex = MathTex(r'f(x) &= 3 + 2 + 1\\ &= 5 + 1 \\ &= 6').scale(2)+ self.add(tex)+"""__all__ = ["TexSymbol",diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.pyindex 0dd0981a8..54f3dc8eb 100644--- a/manim/mobject/svg/text_mobject.py+++ b/manim/mobject/svg/text_mobject.py@@ -1,4 +1,46 @@-"""Mobjects used for displaying (non-LaTeX) text."""+"""Mobjects used for displaying (non-LaTeX) text.++The simplest way to add text to your animations is to use the :class:`~.Text` class. It uses the Pango library to render text.+With Pango, you are also able to render non-English alphabets like `你好` or `こんにちは` or `안녕하세요` or `مرحبا بالعالم`.++Examples+--------++.. manim:: HelloWorld+ :save_last_frame:++ class HelloWorld(Scene):+ def construct(self):+ text = Text('Hello world').scale(3)+ self.add(text)++.. manim:: TextAlignement+ :save_last_frame:++ class TextAlignement(Scene):+ def construct(self):+ title = Text("K-means clustering and Logistic Regression", color=WHITE)+ title.scale_in_place(0.75)+ self.add(title.to_edge(UP))++ t1 = Text("1. Measuring").set_color(WHITE)+ t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP)++ t2 = Text("2. Clustering").set_color(WHITE)+ t2.next_to(t1, direction=DOWN, aligned_edge=LEFT)++ t3 = Text("3. Regression").set_color(WHITE)+ t3.next_to(t2, direction=DOWN, aligned_edge=LEFT)++ t4 = Text("4. Prediction").set_color(WHITE)+ t4.next_to(t3, direction=DOWN, aligned_edge=LEFT)++ x = VGroup(t1, t2, t3, t4).scale_in_place(0.7)+ x.set_opacity(0.5)+ x.submobjects[1].set_opacity(1)+ self.add(x)++"""__all__ = ["Text", "Paragraph", "CairoText"]diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.pyindex ae6154f22..fb92973eb 100644--- a/manim/mobject/types/vectorized_mobject.py+++ b/manim/mobject/types/vectorized_mobject.py@@ -944,6 +944,31 @@ class VMobject(Mobject):class VGroup(VMobject):+ """A group of vectorized mobjects.++ This can be used to group multiple :class:`~.VMobject` instances together+ in order to scale, move, ... them together.++ Examples+ --------++ .. manim:: ArcShapeIris+ :save_last_frame:++ class ArcShapeIris(Scene):+ def construct(self):+ colors = [DARK_BLUE, DARK_BROWN, BLUE_E, BLUE_D, BLUE_A, TEAL_B, GREEN_B, YELLOW_E]+ radius = [1 + rad * 0.1 for rad in range(len(colors))]++ circles_group = VGroup()++ # zip(radius, color) makes the iterator [(radius[i], color[i]) for i in range(radius)]+ circles_group.add(*[Circle(radius=rad, stroke_width=10, color=col)+ for rad, col in zip(radius, colors)])+ self.add(circles_group)++ """+def __init__(self, *vmobjects, **kwargs):VMobject.__init__(self, **kwargs)self.add(*vmobjects)@@ -1006,6 +1031,74 @@ class VDict(VMobject):submob_dict : :class:`dict`Is the actual python dictionary that is used to bindthe keys to the mobjects.++ Examples+ --------++ .. manim:: ShapesWithVDict++ class ShapesWithVDict(Scene):+ def construct(self):+ square = Square().set_color(RED)+ circle = Circle().set_color(YELLOW).next_to(square, UP)++ # create dict from list of tuples each having key-mobject pair+ pairs = [("s", square), ("c", circle)]+ my_dict = VDict(pairs, show_keys=True)++ # display it just like a VGroup+ self.play(ShowCreation(my_dict))+ self.wait()++ text = Tex("Some text").set_color(GREEN).next_to(square, DOWN)++ # add a key-value pair by wrapping it in a single-element list of tuple+ # after attrs branch is merged, it will be easier like `.add(t=text)`+ my_dict.add([("t", text)])+ self.wait()++ rect = Rectangle().next_to(text, DOWN)+ # can also do key assignment like a python dict+ my_dict["r"] = rect++ # access submobjects like a python dict+ my_dict["t"].set_color(PURPLE)+ self.play(my_dict["t"].scale, 3)+ self.wait()++ # also supports python dict styled reassignment+ my_dict["t"] = Tex("Some other text").set_color(BLUE)+ self.wait()++ # remove submoject by key+ my_dict.remove("t")+ self.wait()++ self.play(Uncreate(my_dict["s"]))+ self.wait()++ self.play(FadeOut(my_dict["c"]))+ self.wait()++ self.play(FadeOutAndShift(my_dict["r"], DOWN))+ self.wait()++ # you can also make a VDict from an existing dict of mobjects+ plain_dict = {+ 1: Integer(1).shift(DOWN),+ 2: Integer(2).shift(2 * DOWN),+ 3: Integer(3).shift(3 * DOWN),+ }++ vdict_from_plain_dict = VDict(plain_dict)+ vdict_from_plain_dict.shift(1.5 * (UP + LEFT))+ self.play(ShowCreation(vdict_from_plain_dict))++ # you can even use zip+ vdict_using_zip = VDict(zip(["s", "c", "r"], [Square(), Circle(), Rectangle()]))+ vdict_using_zip.shift(1.5 * RIGHT)+ self.play(ShowCreation(vdict_using_zip))+ self.wait()"""def __init__(self, mapping_or_iterable={}, show_keys=False, **kwargs):diff --git a/manim/scene/graph_scene.py b/manim/scene/graph_scene.pyindex 3e7c3e190..0ae87a7f8 100644--- a/manim/scene/graph_scene.py+++ b/manim/scene/graph_scene.py@@ -1,4 +1,44 @@-"""A scene for plotting / graphing functions."""+"""A scene for plotting / graphing functions.++Examples+--------++.. manim:: FunctionPlotWithLabbeledYAxis+ :save_last_frame:++ class FunctionPlotWithLabbeledYAxis(GraphScene):+ CONFIG = {+ "y_min": 0,+ "y_max": 100,+ "y_axis_config": {"tick_frequency": 10},+ "y_labeled_nums": np.arange(0, 100, 10)+ }++ def construct(self):+ 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(dot,func_graph)+++.. manim:: GaussianFunctionPlot+ :save_last_frame:++ amp = 5+ mu = 3+ sig = 1++ def gaussian(x):+ return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))++ class GaussianFunctionPlot(GraphScene):+ def construct(self):+ self.setup_axes()+ graph = self.get_graph(gaussian, x_min=-1, x_max=10)+ graph.set_stroke(width=5)+ self.add(graph)++"""__all__ = ["GraphScene"]@@ -205,6 +245,26 @@ class GraphScene(Scene):-------np.ndarrayThe array of the coordinates.++ Examples+ --------++ .. manim:: SequencePlot+ :save_last_frame:++ class SequencePlot(GraphScene):+ CONFIG = {+ "y_axis_label": r"Concentration [\%]",+ "x_axis_label": "Time [s]",+ }++ def construct(self):+ data = [1, 2, 2, 4, 4, 1, 3]+ self.setup_axes()+ for time, dat in enumerate(data):+ dot = Dot().move_to(self.coords_to_point(time, dat))+ self.add(dot)+"""assert hasattr(self, "x_axis") and hasattr(self, "y_axis")result = self.x_axis.number_to_point(x)[0] * RIGHTdiff --git a/manim/scene/moving_camera_scene.py b/manim/scene/moving_camera_scene.pyindex 231df40c8..9d85e0178 100644--- a/manim/scene/moving_camera_scene.py+++ b/manim/scene/moving_camera_scene.py@@ -4,6 +4,73 @@:mod:`.moving_camera`++Examples+--------++.. manim:: ChangingCameraWidthAndRestore++ class ChangingCameraWidthAndRestore(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:: MovingCameraCenter++ class MovingCameraCenter(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.wait(0.3)+ 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:: MovingAndZoomingCamera++ class MovingAndZoomingCamera(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:: MovingCameraOnGraph++ class MovingCameraOnGraph(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()+"""__all__ = ["MovingCameraScene"]diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex 145a31022..53c668ec7 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -541,7 +541,7 @@ class Scene(Container):by a dict of kwargs for that method).This animation list is built by going through the args list,and each animation is simply added, but when a mobject method- s hit, a MoveToTarget animation is built using the args that+ is hit, a MoveToTarget animation is built using the args thatfollow up until either another animation is hit, another methodis hit, or the args list runs out.diff --git a/manim/scene/zoomed_scene.py b/manim/scene/zoomed_scene.pyindex e88bfa504..36fd37e87 100644--- a/manim/scene/zoomed_scene.py+++ b/manim/scene/zoomed_scene.py@@ -1,4 +1,45 @@-"""A scene supporting zooming in on a specified section."""+"""A scene supporting zooming in on a specified section.+++Examples+--------++.. manim:: UseZoomedScene++ class UseZoomedScene(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:: ChangingZoomScale++ class ChangingZoomScale(ZoomedScene):+ CONFIG = {+ "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):+ 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)++"""__all__ = ["ZoomedScene"]