diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 037b230e9d..5f5fff964d 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -1,5 +1,5 @@ Example Gallery -============ +=============== .. toctree:: diff --git a/docs/source/examples/3d.rst b/docs/source/examples/3d.rst index 5ffddca167..9c25ab6642 100644 --- a/docs/source/examples/3d.rst +++ b/docs/source/examples/3d.rst @@ -1,10 +1,10 @@ 3D Scenes ================================= -.. manim:: Example3DNo1 +.. manim:: ThreeDSphere :save_last_frame: - class Example3DNo1(ThreeDScene): + class ThreeDSphere(ThreeDScene): def construct(self): axes = ThreeDAxes() sphere = ParametricSurface( @@ -18,10 +18,10 @@ self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) self.add(axes, sphere) -.. manim:: Example3DLightSourcePosition +.. manim:: ThreeDLightSourcePosition :save_last_frame: - class Example3DLightSourcePosition(ThreeDScene): + class ThreeDLightSourcePosition(ThreeDScene): def construct(self): axes = ThreeDAxes() sphere = ParametricSurface( @@ -36,9 +36,9 @@ self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) self.add(axes, sphere) -.. manim:: Example3DNo3 +.. manim:: ThreeDCameraRotation - class Example3DNo3(ThreeDScene): + class ThreeDCameraRotation(ThreeDScene): def construct(self): axes = ThreeDAxes() circle=Circle() @@ -50,9 +50,9 @@ self.move_camera(phi=75 * DEGREES, theta=30 * DEGREES) self.wait() -.. manim:: Example3DNo4 +.. manim:: ThreeDCameraIllusionRotation - class Example3DNo4(ThreeDScene): + class ThreeDCameraIllusionRotation(ThreeDScene): def construct(self): axes = ThreeDAxes() circle=Circle() @@ -62,10 +62,10 @@ self.wait(PI) self.stop_3dillusion_camera_rotation() -.. manim:: Example3DNo5 +.. manim:: ThreeDParametricSpring :save_last_frame: - class Example3DNo5(ThreeDScene): + class ThreeDParametricSpring(ThreeDScene): def construct(self): curve1 = ParametricFunction( lambda u: np.array([ @@ -79,3 +79,54 @@ 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.rst index b37b158ab4..9e4552571d 100644 --- a/docs/source/examples/advanced_projects.rst +++ b/docs/source/examples/advanced_projects.rst @@ -1,10 +1,10 @@ Advanced Projects ================================= -.. manim:: OpeningManimExample +.. manim:: OpeningManim :ref_classes: Tex MathTex NumberPlane - class OpeningManimExample(Scene): + 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}") @@ -19,7 +19,7 @@ Advanced Projects transform_title.to_corner(UP + LEFT) self.play( Transform(title, transform_title), - LaggedStart(*map(FadeOutAndShiftDown, basel)), + LaggedStart(*map(lambda obj: FadeOutAndShift(obj, direction=DOWN), basel)), ) self.wait() @@ -31,7 +31,7 @@ Advanced Projects self.add(grid, grid_title) # Make sure title is on top of grid self.play( FadeOut(title), - FadeInFromDown(grid_title), + FadeInFrom(grid_title, direction=DOWN), ShowCreation(grid, run_time=3, lag_ratio=0.1), ) self.wait() @@ -104,10 +104,10 @@ Advanced Projects self.play(Write(example_tex)) self.wait() -.. manim:: UpdatersExample +.. manim:: SquareMovingWithUpdaters :quality: low - class UpdatersExample(Scene): + class SquareMovingWithUpdaters(Scene): def construct(self): decimal = DecimalNumber( 0, @@ -129,10 +129,10 @@ Advanced Projects self.wait() -.. manim:: VDictExample +.. manim:: ShapesWithVDics :quality: low - class VDictExample(Scene): + class ShapesWithVDics(Scene): def construct(self): square = Square().set_color(RED) circle = Circle().set_color(YELLOW).next_to(square, UP) @@ -196,10 +196,10 @@ Advanced Projects self.wait() -.. manim:: VariableExample +.. manim:: VariablesWithValueTracker :quality: low - class VariableExample(Scene): + class VariablesWithValueTracker(Scene): def construct(self): var = 0.5 on_screen_var = Variable(var, Text("var"), num_decimal_places=3) @@ -242,9 +242,9 @@ Advanced Projects self.play(Write(on_screen_subscript_var)) self.wait() -.. manim:: ExampleSineCurve +.. manim:: SineCurvePlot - class ExampleSineCurve(Scene): + class SineCurvePlot(Scene): # contributed by heejin_park, https://infograph.tistory.com/230 def construct(self): self.show_axis() diff --git a/docs/source/examples/animations.rst b/docs/source/examples/animations.rst index 33eab8e9ca..8aeae55677 100644 --- a/docs/source/examples/animations.rst +++ b/docs/source/examples/animations.rst @@ -10,9 +10,9 @@ Some more examples will come soon here! Updaters ########## -.. manim:: Updater1Example +.. manim:: RotationUpdater - class Updater1Example(Scene): + class RotationUpdater(Scene): def construct(self): def my_rotation_updater(mobj,dt): mobj.rotate_about_origin(dt) @@ -22,9 +22,9 @@ Updaters self.add(line_reference, line_moving) self.wait(PI) -.. manim:: Updater2Example +.. manim:: RotationUpdater2 - class Updater2Example(Scene): + class RotationUpdater2(Scene): def construct(self): def updater_forth(mobj, dt): mobj.rotate_about_origin(dt) @@ -41,9 +41,9 @@ Updaters line_moving.remove_updater(updater_back) self.wait(0.5) -.. manim:: Example3 +.. manim:: NumberLinePointer - class Example3(Scene): + class NumberLinePointer(Scene): def construct(self): number_line = NumberLine() ##with all your parameters and stuff pointer = Vector(DOWN) @@ -57,10 +57,11 @@ Updaters self.play(pointer_value.set_value, 5) self.wait() self.play(pointer_value.set_value, 3) + self.wait() -.. manim:: Example4 +.. manim:: PointWithTrace - class Example4(Scene): + class PointWithTrace(Scene): def construct(self): path = VMobject() dot = Dot() @@ -77,9 +78,9 @@ Updaters self.play(dot.shift, LEFT) self.wait() -.. manim:: Example1ValTracker +.. manim:: PointMovingWithValTracker - class Example1ValTracker(Scene): + class PointMovingWithValTracker(Scene): def construct(self): dot_disp = Dot().set_color(RED) self.add(dot_disp) @@ -92,9 +93,9 @@ Updaters self.play(val_tracker.set_value, tick_end, rate_func=linear) self.wait() -.. manim:: Example2ValTracker +.. manim:: RotationValTracker - class Example2ValTracker(Scene): + class RotationValTracker(Scene): def construct(self): tick_start = 0 tick_end = 2 * PI @@ -105,4 +106,38 @@ Updaters 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 + 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.rst index 33a331bd95..746d53166d 100644 --- a/docs/source/examples/annotations.rst +++ b/docs/source/examples/annotations.rst @@ -1,10 +1,10 @@ Annotations ================================= -.. manim:: AnnotateBrace +.. manim:: BraceAnnotation :save_last_frame: - class AnnotateBrace(Scene): + class BraceAnnotation(Scene): def construct(self): dot = Dot([0, 0, 0]) dot2 = Dot([2, 1, 0]) @@ -15,26 +15,26 @@ Annotations b2text = b2.get_tex("x-x_1") self.add(dot, dot2, line, b1, b2, b1text, b2text) -.. manim:: ExampleArrow +.. manim:: VectorArrow :quality: medium :save_last_frame: - class ExampleArrow(Scene): + class VectorArrow(Scene): def construct(self): dot = Dot(ORIGIN) arrow = Arrow(ORIGIN, [2, 2, 0], buff=0) numberplane = NumberPlane() - origin_text = TextMobject('(0, 0)').next_to(dot, DOWN) - tip_text = TextMobject('(2, 2)').next_to(arrow.get_end(), RIGHT) + 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:: ExampleArrowTips +.. manim:: ArrowTipsShowcase :quality: medium :save_last_frame: from manim.mobject.geometry import ArrowTriangleTip, ArrowSquareTip, ArrowSquareFilledTip,\ ArrowCircleTip, ArrowCircleFilledTip - class ExampleArrowTips(Scene): + 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) diff --git a/docs/source/examples/camera_settings.rst b/docs/source/examples/camera_settings.rst index 5b28addf02..c41fb2f776 100644 --- a/docs/source/examples/camera_settings.rst +++ b/docs/source/examples/camera_settings.rst @@ -1,18 +1,18 @@ Camera Settings ================================= -.. manim:: Example1 +.. manim:: ChangingCameraWidth - class Example1(MovingCameraScene): + 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:: Example2a +.. manim:: ChangingCameraWidthAndRestore - class Example2a(MovingCameraScene): + class ChangingCameraWidthAndRestore(MovingCameraScene): def construct(self): text = Text("Hello World").set_color(BLUE) self.add(text) @@ -21,9 +21,9 @@ Camera Settings self.wait(0.3) self.play(Restore(self.camera_frame)) -.. manim:: Example2b +.. manim:: ChangingCameraWidthAndRevert - class Example2b(MovingCameraScene): + class ChangingCameraWidthAndRevert(MovingCameraScene): def construct(self): text = Text("Hello World").set_color(BLUE) self.add(text) @@ -32,20 +32,21 @@ Camera Settings self.play(self.camera_frame.set_width, 14) -.. manim:: Example3 +.. manim:: MovingCameraCenter - class Example3(MovingCameraScene): + 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:: Example4 +.. manim:: MovingAndZoomingCamera - class Example4(MovingCameraScene): + 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) @@ -59,9 +60,9 @@ Camera Settings self.play(self.camera_frame.move_to, ORIGIN, self.camera_frame.set_width,14) -.. manim:: Example5 +.. manim:: MovingCameraOnGraph - class Example5(GraphScene, MovingCameraScene): + class MovingCameraOnGraph(GraphScene, MovingCameraScene): def setup(self): GraphScene.setup(self) MovingCameraScene.setup(self) @@ -81,9 +82,9 @@ Camera Settings self.play(Restore(self.camera_frame)) self.wait() -.. manim:: Example6 +.. manim:: FollowingGraphCamera - class Example6(GraphScene, MovingCameraScene): + class FollowingGraphCamera(GraphScene, MovingCameraScene): def setup(self): GraphScene.setup(self) MovingCameraScene.setup(self) @@ -115,9 +116,9 @@ Camera Settings Note: ZoomedScene is derived class of MovingCameraScene, so one can use all functionality that were used before in the MovingCameraScene examples. -.. manim:: ExampleZoom1 +.. manim:: UseZoomedScene - class ExampleZoom1(ZoomedScene): + class UseZoomedScene(ZoomedScene): def construct(self): dot = Dot().set_color(GREEN) self.add(dot) @@ -126,9 +127,9 @@ so one can use all functionality that were used before in the MovingCameraScene self.wait(1) self.play(dot.shift, LEFT) -.. manim:: ExampleZoom2 +.. manim:: ChangingZoomScale - class ExampleZoom2(ZoomedScene): + class ChangingZoomScale(ZoomedScene): CONFIG = { "zoom_factor": 0.3, "zoomed_display_height": 1, @@ -151,9 +152,9 @@ so one can use all functionality that were used before in the MovingCameraScene self.play(self.zoomed_camera.frame.shift, 0.5 * DOWN) -.. manim:: ExampleZoom3 +.. manim:: MovingZoomedSceneAround - class ExampleZoom3(ZoomedScene): + class MovingZoomedSceneAround(ZoomedScene): # contributed by TheoremofBeethoven, www.youtube.com/c/TheoremofBeethoven CONFIG = { "zoom_factor": 0.3, @@ -170,8 +171,8 @@ so one can use all functionality that were used before in the MovingCameraScene 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) + 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 @@ -191,12 +192,12 @@ so one can use all functionality that were used before in the MovingCameraScene frame_text.next_to(frame, DOWN) - self.play(ShowCreation(frame), FadeInFromDown(frame_text)) + 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(FadeInFromDown(zoomed_camera_text)) + self.play(FadeInFrom(zoomed_camera_text, direction=DOWN)) # Scale in x y z scale_factor = [0.5, 1.5, 0] self.play( diff --git a/docs/source/examples/formulas.rst b/docs/source/examples/formulas.rst index 5f615f9638..9642fa4a1f 100644 --- a/docs/source/examples/formulas.rst +++ b/docs/source/examples/formulas.rst @@ -4,9 +4,9 @@ Formulas -.. manim:: MoveFrameBox +.. manim:: MovingFrameBox - class MoveFrameBox(Scene): + class MovingFrameBox(Scene): def construct(self): text=MathTex( "\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+", @@ -24,9 +24,9 @@ Formulas ) self.wait() -.. manim:: MoveBraces +.. manim:: MovingBraces - class MoveBraces(Scene): + class MovingBraces(Scene): def construct(self): text=MathTex( "\\frac{d}{dx}f(x)g(x)=", #0 diff --git a/docs/source/examples/plots.rst b/docs/source/examples/plots.rst index 2d5dc4ea7c..0e1de60b26 100644 --- a/docs/source/examples/plots.rst +++ b/docs/source/examples/plots.rst @@ -4,19 +4,19 @@ Plotting with manim Examples to illustrate the use of :class:`.GraphScene` in manim. -.. manim:: Plot1 +.. manim:: FunctionPlot :save_last_frame: - class Plot1(GraphScene): + class FunctionPlot(GraphScene): def construct(self): self.setup_axes() func_graph=self.get_graph(lambda x: np.sin(x)) self.add(func_graph) -.. manim:: Plot2yLabelNumbers +.. manim:: FunctionPlotWithLabbeledYAxe :save_last_frame: - class Plot2yLabelNumbers(GraphScene): + class FunctionPlotWithLabbeledYAxe(GraphScene): CONFIG = { "y_min": 0, "y_max": 100, @@ -30,10 +30,10 @@ Examples to illustrate the use of :class:`.GraphScene` in manim. func_graph = self.get_graph(lambda x: 20 * np.sin(x)) self.add(dot,func_graph) -.. manim:: Plot3DataPoints +.. manim:: SequencePlot :save_last_frame: - class Plot3DataPoints(GraphScene): + class SequencePlot(GraphScene): CONFIG = { "y_axis_label": r"Concentration [\%]", "x_axis_label": "Time [s]", @@ -46,7 +46,7 @@ Examples to illustrate the use of :class:`.GraphScene` in manim. dot = Dot().move_to(self.coords_to_point(time, dat)) self.add(dot) -.. manim:: Plot3bGaussian +.. manim:: GaussianFunctionPlot1 :save_last_frame: amp = 5 @@ -56,16 +56,17 @@ Examples to illustrate the use of :class:`.GraphScene` in manim. def gaussian(x): return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2)) - class Plot3bGaussian(GraphScene): + class GaussianFunctionPlot1(GraphScene): def construct(self): self.setup_axes() - graph = self.get_graph(gaussian, x_min=-1, x_max=10).set_stroke(width=5) + graph = self.get_graph(gaussian, x_min=-1, x_max=10) + graph.set_stroke(width=5) self.add(graph) -.. manim:: Plot3cGaussian +.. manim:: GaussianFunctionPlot2 :save_last_frame: - class Plot3cGaussian(GraphScene): + class GaussianFunctionPlot2(GraphScene): def construct(self): def gaussian(x): amp = 5 @@ -78,10 +79,10 @@ Examples to illustrate the use of :class:`.GraphScene` in manim. self.add(graph) -.. manim:: Plot4SinCos +.. manim:: SinAndCosFunctionPlot :save_last_frame: - class Plot4SinCos(GraphScene): + class SinAndCosFunctionPlot(GraphScene): CONFIG = { "x_min": -10, "x_max": 10.3, @@ -107,10 +108,10 @@ Examples to illustrate the use of :class:`.GraphScene` in manim. two_pi.next_to(label_coord, RIGHT + UP) self.add(func_graph, func_graph2, vert_line, graph_lab, graph_lab2, two_pi) -.. manim:: Plot5Area +.. manim:: GraphAreaPlot :save_last_frame: - class Plot5Area(GraphScene): + class GraphAreaPlot(GraphScene): CONFIG = { "x_min" : 0, "x_max" : 5, @@ -130,10 +131,10 @@ Examples to illustrate the use of :class:`.GraphScene` in manim. area2 = self.get_area(curve2, 2, 3, bounded=curve1) self.add(curve1, curve2, line1, line2, area1, area2) -.. manim:: Plot6HeatDiagram +.. manim:: HeatDiagramPlot :save_last_frame: - class Plot6HeatDiagram(GraphScene): + class HeatDiagramPlot(GraphScene): CONFIG = { "y_axis_label": r"T[$^\circ C$]", "x_axis_label": r"$\Delta Q$", diff --git a/docs/source/examples/shapes_images_positions.rst b/docs/source/examples/shapes_images_positions.rst index 00e08b1dda..c02bdc73ef 100644 --- a/docs/source/examples/shapes_images_positions.rst +++ b/docs/source/examples/shapes_images_positions.rst @@ -1,10 +1,10 @@ Shapes, Images and Positions ================================= -.. manim:: Example1Shape +.. manim:: GeometricShapes :save_last_frame: - class Example1Shape(Scene): + class GeometricShapes(Scene): def construct(self): d = Dot() c = Circle() @@ -15,31 +15,185 @@ Shapes, Images and Positions t.next_to(c, DOWN) self.add(d, c, s, t) -.. manim:: Example1ImageFromArray - :save_last_frame: +.. 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() + - class Example1ImageFromArray(Scene): +.. manim:: GradientImageFromArray + :save_last_frame: + + class GradientImageFromArray(Scene): def construct(self): - image = ImageMobject(np.uint8([[0, 100, 30, 200], - [255, 0, 5, 33]])) - image.set_height(7) + 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:: Example2ImageFromFile + +.. 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 = PangoText("K-means clustering and Logistic Regression", color=WHITE) + title.scale_in_place(0.75) + self.add(title.to_edge(UP)) + + t1 = PangoText("1. Measuring").set_color(WHITE) + t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP) + + t2 = PangoText("2. Clustering").set_color(WHITE) + t2.next_to(t1, direction=DOWN, aligned_edge=LEFT) + + t3 = PangoText("3. Regression").set_color(WHITE) + t3.next_to(t2, direction=DOWN, aligned_edge=LEFT) - class Example2ImageFromFile(Scene): + t4 = PangoText("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): - # 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("") - img_mobject.scale(3) - self.add(img_mobject) + 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) -Note: Here can come the UnitDot Example. \ No newline at end of file diff --git a/docs/source/examples/tex.rst b/docs/source/examples/tex.rst index a64505931a..57a00e06ea 100644 --- a/docs/source/examples/tex.rst +++ b/docs/source/examples/tex.rst @@ -10,10 +10,10 @@ A newer addition to manim is the :class:`~.PangoText` class, which uses the Pang The Text() mobject +++++++++++++++++++ -.. manim:: Example1Text +.. manim:: HelloWorld :save_last_frame: - class Example1Text(Scene): + class HelloWorld(Scene): def construct(self): text = Text('Hello world').scale(3) self.add(text) @@ -33,10 +33,10 @@ 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:: ExampleLaTeX +.. manim:: HelloLaTeX :save_last_frame: - class ExampleLaTeX(Scene): + class HelloLaTeX(Scene): def construct(self): tex = Tex(r'\LaTeX').scale(3) self.add(tex) @@ -50,10 +50,10 @@ The MathTex() mobject ++++++++++++++++++++++ Anything enclosed in ``$`` signs is interpreted as maths-mode: -.. manim:: Example1LaTeX +.. manim:: HelloTex :save_last_frame: - class Example1LaTeX(Scene): + class HelloTex(Scene): def construct(self): tex = Tex(r'$\xrightarrow{Hello}$ \LaTeX').scale(3) self.add(tex) @@ -61,10 +61,10 @@ Anything enclosed in ``$`` signs is interpreted as maths-mode: Whereas in a :class:`~.MathTex` mobject everything is math-mode by default and you would use ``\text{}`` to insert regular text: -.. manim:: Example1bLaTeX +.. manim:: HelloMathTex :save_last_frame: - class Example1bLaTeX(Scene): + class HelloMathTex(Scene): def construct(self): tex = MathTex(r'\xrightarrow{Hello}\text{ \LaTeX}').scale(3) self.add(tex) @@ -73,10 +73,10 @@ LaTeX commands and keyword arguments +++++++++++++++++++++++++++++++++++++ We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` text type. -.. manim:: Example2LaTeX +.. manim:: AMSLaTeX :save_last_frame: - class Example2LaTeX(Scene): + class AMSLaTeX(Scene): def construct(self): tex = Tex(r'$\mathtt{Hello}$ \LaTeX').scale(3) self.add(tex) @@ -84,10 +84,10 @@ We can use any standard LaTeX commands in the AMS maths packages. For example th 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:: Example2bLaTeX +.. manim:: LaTeXAttributes :save_last_frame: - class Example2bLaTeX(Scene): + class LaTeXAttributes(Scene): def construct(self): tex = Tex(r'Hello \LaTeX', color=BLUE).scale(3) self.add(tex) @@ -98,10 +98,10 @@ Some commands require special packages to be loaded into the TeX template. For e 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:: Example3LaTeX +.. manim:: AddPackageLatex :save_last_frame: - class Example3LaTeX(Scene): + class AddPackageLatex(Scene): def construct(self): myTemplate = TexTemplate() myTemplate.add_to_preamble(r"\usepackage{mathrsfs}") @@ -114,10 +114,10 @@ The TeX mobject can accept multiple strings as arguments. Afterwards you can ref 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:: Example4LaTeX +.. manim:: LaTeXSubstrings :save_last_frame: - class Example4LaTeX(Scene): + class LaTeXSubstrings(Scene): def construct(self): tex = Tex('Hello', r'$\bigstar$', r'\LaTeX').scale(3) tex.set_color_by_tex('igsta', RED) @@ -130,10 +130,10 @@ with regular text. It requires changing the template that is used to compile the Manim comes with a collection of :class:`~.TexFontTemplates` ready for you to use. These templates will all work in maths mode: -.. manim:: Example5LaTeX +.. manim:: LaTeXMathFonts :save_last_frame: - class Example5LaTeX(Scene): + class LaTeXMathFonts(Scene): def construct(self): tex = Tex(r'$f: A \rightarrow B$', tex_template=TexFontTemplates.french_cursive).scale(3) self.add(tex) @@ -143,10 +143,10 @@ is the ctex template, used for typesetting Chinese. For this to work, the ctex L 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:: Example6LaTeX +.. manim:: LaTeXTemplateLibrary :save_last_frame: - class Example6LaTeX(Scene): + class LaTeXTemplateLibrary(Scene): def construct(self): tex = Tex('Hello 你好 \\LaTeX', tex_template=TexTemplateLibrary.ctex).scale(3) self.add(tex) @@ -157,10 +157,10 @@ 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:: Example7LaTeX +.. manim:: LaTeXAlignEnvironment :save_last_frame: - class Example7LaTeX(Scene): + 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/installation/linux.rst b/docs/source/installation/linux.rst index e9a87ff04f..44c52d15be 100644 --- a/docs/source/installation/linux.rst +++ b/docs/source/installation/linux.rst @@ -11,7 +11,7 @@ The two necessary dependencies are cairo and ffmpeg. LaTeX is strongly recommended, as it is necessary to have access to the ``Tex`` and ``MathTex`` classes. Ubuntu/Mint/Debian -************* +****************** Before installing anything, make sure that your system is up to date. @@ -50,7 +50,7 @@ If you don't have python3-pip installed, install it: Fedora/CentOS/RHEL -************* +****************** To install cairo: diff --git a/docs/source/installation/troubleshooting.rst b/docs/source/installation/troubleshooting.rst index ba2889875c..4839e3422b 100644 --- a/docs/source/installation/troubleshooting.rst +++ b/docs/source/installation/troubleshooting.rst @@ -56,7 +56,7 @@ As soon as you have found the library, try (on Mac OS or Linux) or (on Windows) -.. code-block:: cmd +.. code-block:: bat set LIBS= dvisvgm -l diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py index e0bb9c94fe..1158872c55 100644 --- a/manim/mobject/types/image_mobject.py +++ b/manim/mobject/types/image_mobject.py @@ -49,6 +49,22 @@ def reset_points(self): class ImageMobject(AbstractImageMobject): + """Displays an Image from a numpy array or a file. + + Example + ------- + .. manim:: ImageFromArray + :save_last_frame: + + class ImageFromArray(Scene): + def construct(self): + image = ImageMobject(np.uint8([[0, 100, 30, 200], + [255, 0, 5, 33]])) + image.set_height(7) + self.add(image) + + """ + CONFIG = { "invert": False, "image_mode": "RGBA", diff --git a/manim/scene/scene.py b/manim/scene/scene.py index adb3cef023..cd07925218 100644 --- a/manim/scene/scene.py +++ b/manim/scene/scene.py @@ -734,9 +734,10 @@ def play_internal(self, *args, **kwargs): Parameters ---------- - *args : Animation or mobject with mobject method and params - **kwargs : named parameters affecting what was passed in *args e.g - run_time, lag_ratio etc. + args + Animation or mobject with mobject method and params + kwargs + named parameters affecting what was passed in ``args`` e.g. ``run_time``, ``lag_ratio`` etc. """ if len(args) == 0: warnings.warn("Called Scene.play with no animations")