A community-maintained Python framework for creating mathematical animations.
Render image automatically if no animation is played in a scene (#1261)
sparshg08e06e156c4b
diff --git a/docs/source/manim_directive.py b/docs/source/manim_directive.pyindex 7374e028d..2079ea7ea 100644--- a/docs/source/manim_directive.py+++ b/docs/source/manim_directive.py@@ -221,6 +221,7 @@ class ManimDirective(Directive):f'config["pixel_width"] = {pixel_width}',f'config["save_last_frame"] = {save_last_frame}',f'config["save_as_gif"] = {save_as_gif}',+ f'config["write_to_movie"] = {not save_last_frame}',f'config["output_file"] = r"{output_file}"',]diff --git a/manim/renderer/cairo_renderer.py b/manim/renderer/cairo_renderer.pyindex 03f5e8e01..599238078 100644--- a/manim/renderer/cairo_renderer.py+++ b/manim/renderer/cairo_renderer.py@@ -266,7 +266,15 @@ class CairoRenderer:raise EndSceneEarlyException()def scene_finished(self, scene):- self.file_writer.finish()+ # If no animations in scene, render an image instead+ if self.num_plays:+ self.file_writer.finish()+ elif config.write_to_movie:+ config.save_last_frame = True+ config.write_to_movie = False+ else:+ self.update_frame(scene)+if config["save_last_frame"]:- self.update_frame(scene, ignore_skipping=False)+ self.update_frame(scene)self.file_writer.save_final_image(self.camera.get_image())diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex 238a5e0e8..059f80745 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -187,9 +187,11 @@ class Scene(Container):# We have to reset these settings in case of multiple renders.self.renderer.scene_finished(self)- logger.info(- f"Rendered {str(self)}\nPlayed {self.renderer.num_plays} animations"- )+ # Show info only if animations are rendered or to get image+ if self.renderer.num_plays or config["save_last_frame"] or config["save_pngs"]:+ logger.info(+ f"Rendered {str(self)}\nPlayed {self.renderer.num_plays} animations"+ )# If preview open up the render after rendering.if preview:diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.pyindex 803b7b804..1e092d078 100644--- a/manim/scene/scene_file_writer.py+++ b/manim/scene/scene_file_writer.py@@ -78,14 +78,13 @@ class SceneFileWriter(object):else:default_name = Path(scene_name)- if config["save_last_frame"] or config["save_pngs"]:- if config["media_dir"]:- image_dir = guarantee_existence(- config.get_dir("images_dir", module_name=module_name)- )- self.image_file_path = os.path.join(- image_dir, add_extension_if_not_present(default_name, ".png")+ if config["media_dir"]:+ image_dir = guarantee_existence(+ config.get_dir("images_dir", module_name=module_name))+ self.image_file_path = os.path.join(+ image_dir, add_extension_if_not_present(default_name, ".png")+ )if config["write_to_movie"]:movie_dir = guarantee_existence(diff --git a/tests/control_data/graphical_units_data/updaters/ValueTrackerTest.npz b/tests/control_data/graphical_units_data/updaters/ValueTrackerTest.npzindex f8eb0c53b..f7bed0705 100644Binary files a/tests/control_data/graphical_units_data/updaters/ValueTrackerTest.npz and b/tests/control_data/graphical_units_data/updaters/ValueTrackerTest.npz differdiff --git a/tests/test_graphical_units/test_coordinate_systems.py b/tests/test_graphical_units/test_coordinate_systems.pyindex e4fb80b9f..43bedd652 100644--- a/tests/test_graphical_units/test_coordinate_systems.py+++ b/tests/test_graphical_units/test_coordinate_systems.py@@ -17,7 +17,7 @@ class NumberPlaneTest(Scene):y_axis_config={"x_max": 5, "width": 6, "label_direction": UL},center_point=2 * DL,)- self.play(Animation(plane))+ self.add(plane)MODULE_NAME = "coordinate_systems"diff --git a/tests/test_graphical_units/test_functions.py b/tests/test_graphical_units/test_functions.pyindex 1b77a61bf..1231f3361 100644--- a/tests/test_graphical_units/test_functions.py+++ b/tests/test_graphical_units/test_functions.py@@ -13,7 +13,6 @@ class FunctionGraphTest(Scene):lambda x: 2 * np.cos(0.5 * x), x_min=-PI, x_max=PI, color=BLUE)self.add(graph)- self.wait()MODULE_NAME = "functions"diff --git a/tests/test_graphical_units/test_geometry.py b/tests/test_graphical_units/test_geometry.pyindex 6f9afa58d..a655e675a 100644--- a/tests/test_graphical_units/test_geometry.py+++ b/tests/test_graphical_units/test_geometry.py@@ -9,25 +9,25 @@ from ..utils.testing_utils import get_scenes_to_testclass CoordinatesTest(Scene):def construct(self):dots = [Dot(np.array([x, y, 0])) for x in range(-7, 8) for y in range(-4, 5)]- self.play(Animation(VGroup(*dots)))+ self.add(VGroup(*dots))class ArcTest(Scene):def construct(self):a = Arc(PI)- self.play(Animation(a))+ self.add(a)class ArcBetweenPointsTest(Scene):def construct(self):a = ArcBetweenPoints(np.array([1, 1, 0]), np.array([2, 2, 0]))- self.play(Animation(a))+ self.add(a)class CurvedArrowTest(Scene):def construct(self):a = CurvedArrow(np.array([1, 1, 0]), np.array([2, 2, 0]))- self.play(Animation(a))+ self.add(a)class CustomDoubleArrowTest(Scene):@@ -40,91 +40,91 @@ class CustomDoubleArrowTest(Scene):tip_shape_start=ArrowCircleTip,tip_shape_end=ArrowSquareFilledTip,)- self.play(Animation(a))+ self.add(a)class CircleTest(Scene):def construct(self):circle = Circle()- self.play(Animation(circle))+ self.add(circle)class DotTest(Scene):def construct(self):dot = Dot()- self.play(Animation(dot))+ self.add(dot)class AnnotationDotTest(Scene):def construct(self):adot = AnnotationDot()- self.play(Animation(adot))+ self.add(adot)class EllipseTest(Scene):def construct(self):e = Ellipse()- self.play(Animation(e))+ self.add(e)class SectorTest(Scene):def construct(self):e = Sector()- self.play(Animation(e))+ self.add(e)class AnnulusTest(Scene):def construct(self):a = Annulus()- self.play(Animation(a))+ self.add(a)class AnnularSectorTest(Scene):def construct(self):a = AnnularSector()- self.play(Animation(a))+ self.add(a)class LineTest(Scene):def construct(self):a = Line(np.array([1, 1, 0]), np.array([2, 2, 0]))- self.play(Animation(a))+ self.add(a)class ElbowTest(Scene):def construct(self):a = Elbow()- self.play(Animation(a))+ self.add(a)class DoubleArrowTest(Scene):def construct(self):a = DoubleArrow()- self.play(Animation(a))+ self.add(a)class VectorTest(Scene):def construct(self):a = Vector(UP)- self.play(Animation(a))+ self.add(a)class PolygonTest(Scene):def construct(self):a = Polygon(*[np.array([1, 1, 0]), np.array([2, 2, 0]), np.array([2, 3, 0])])- self.play(Animation(a))+ self.add(a)class RectangleTest(Scene):def construct(self):a = Rectangle()- self.play(Animation(a))+ self.add(a)class RoundedRectangleTest(Scene):def construct(self):a = RoundedRectangle()- self.play(Animation(a))+ self.add(a)class ArrangeTest(Scene):@@ -133,7 +133,6 @@ class ArrangeTest(Scene):s2 = Square()x = VGroup(s1, s2).set_x(0).arrange(buff=1.4)self.add(x)- self.wait()class ZIndexTest(Scene):@@ -148,7 +147,6 @@ class ZIndexTest(Scene):self.play(FadeIn(VGroup(circle, square, triangle)))self.play(ApplyMethod(circle.shift, UP))self.play(ApplyMethod(triangle.shift, 2 * UP))- self.wait(1)class AngleTest(Scene):@@ -156,7 +154,7 @@ class AngleTest(Scene):l1 = Line(ORIGIN, RIGHT)l2 = Line(ORIGIN, UP)a = Angle(l1, l2)- self.play(Animation(a))+ self.add(a)class RightAngleTest(Scene):@@ -164,7 +162,7 @@ class RightAngleTest(Scene):l1 = Line(ORIGIN, RIGHT)l2 = Line(ORIGIN, UP)a = RightAngle(l1, l2)- self.play(Animation(a))+ self.add(a)MODULE_NAME = "geometry"diff --git a/tests/test_graphical_units/test_graphscene.py b/tests/test_graphical_units/test_graphscene.pyindex 9fab06082..e34d14bdd 100644--- a/tests/test_graphical_units/test_graphscene.py+++ b/tests/test_graphical_units/test_graphscene.py@@ -27,7 +27,7 @@ class PlotFunctions(GraphScene):self.setup_axes()f = self.get_graph(lambda x: x ** 2)- self.play(Animation(f))+ self.add(f)MODULE_NAME = "plot"diff --git a/tests/test_graphical_units/test_mobjects.py b/tests/test_graphical_units/test_mobjects.pyindex 5d7137cfd..e855d9faa 100644--- a/tests/test_graphical_units/test_mobjects.py+++ b/tests/test_graphical_units/test_mobjects.py@@ -9,7 +9,7 @@ from ..utils.testing_utils import get_scenes_to_testclass PointCloudDotTest(ThreeDScene):def construct(self):p = PointCloudDot()- self.play(Animation(p))+ self.add(p)MODULE_NAME = "mobjects"diff --git a/tests/test_graphical_units/test_modifier_methods.py b/tests/test_graphical_units/test_modifier_methods.pyindex f212af374..29c2ee8a7 100644--- a/tests/test_graphical_units/test_modifier_methods.py+++ b/tests/test_graphical_units/test_modifier_methods.py@@ -9,7 +9,7 @@ from ..utils.testing_utils import get_scenes_to_testclass GradientTest(Scene):def construct(self):c = Circle(fill_opacity=1).set_color(color=[YELLOW, GREEN])- self.play(Animation(c))+ self.add(c)MODULE_NAME = "modifier_methods"diff --git a/tests/test_graphical_units/test_threed.py b/tests/test_graphical_units/test_threed.pyindex c1ebb68db..2dfdab9e3 100644--- a/tests/test_graphical_units/test_threed.py+++ b/tests/test_graphical_units/test_threed.py@@ -8,53 +8,53 @@ from ..utils.testing_utils import get_scenes_to_testclass CubeTest(ThreeDScene):def construct(self):- self.play(Animation(Cube()))+ self.add(Cube())class SphereTest(ThreeDScene):def construct(self):- self.play(Animation(Sphere()))+ self.add(Sphere())class Dot3DTest(ThreeDScene):def construct(self):- self.play(Animation(Dot3D()))+ self.add(Dot3D())class ConeTest(ThreeDScene):def construct(self):- self.play(Animation(Cone()))+ self.add(Cone())class CylinderTest(ThreeDScene):def construct(self):- self.play(Animation(Cylinder()))+ self.add(Cylinder())class Line3DTest(ThreeDScene):def construct(self):- self.play(Animation(Line3D()))+ self.add(Line3D())class Arrow3DTest(ThreeDScene):def construct(self):- self.play(Animation(Arrow3D()))+ self.add(Arrow3D())class TorusTest(ThreeDScene):def construct(self):- self.play(Animation(Torus()))+ self.add(Torus())class AxesTest(ThreeDScene):def construct(self):- self.play(Animation(ThreeDAxes()))+ self.add(ThreeDAxes())class CameraMoveTest(ThreeDScene):def construct(self):cube = Cube()- self.play(Animation(cube))+ self.add(cube)self.move_camera(phi=PI / 4, theta=PI / 4, frame_center=[0, 0, -1])@@ -62,7 +62,8 @@ class AmbientCameraMoveTest(ThreeDScene):def construct(self):cube = Cube()self.begin_ambient_camera_rotation(rate=0.5)- self.play(Animation(cube))+ self.add(cube)+ self.wait()class FixedInFrameMObjectTest(ThreeDScene):@@ -73,7 +74,6 @@ class FixedInFrameMObjectTest(ThreeDScene):self.add_fixed_in_frame_mobjects(circ)circ.to_corner(UL)self.add(axes)- self.wait()MODULE_NAME = "threed"diff --git a/tests/test_graphical_units/test_updaters.py b/tests/test_graphical_units/test_updaters.pyindex 57e46c24d..336c0cb3f 100644--- a/tests/test_graphical_units/test_updaters.py+++ b/tests/test_graphical_units/test_updaters.py@@ -20,9 +20,9 @@ class UpdaterTest(Scene):class ValueTrackerTest(Scene):def construct(self):theta = ValueTracker(PI / 2)- line_1 = Line(ORIGIN, RIGHT * 3, color=RED)- line_2 = Line(ORIGIN, RIGHT * 3, color=GREEN)- line_2.rotate(theta.get_value(), about_point=ORIGIN)+ line = Line(ORIGIN, RIGHT)+ line.rotate(theta.get_value(), about_point=ORIGIN)+ self.add(line)class UpdateSceneDuringAnimationTest(Scene):