Search code examples
pythonmanim

Why is my manim scene being converted into a png instead of an mp4


I have a python file that I am using to program a few scenes in manim. I looked over the Quick Start documentation, and everything works fine. But when I made another scene, called ThreeSquares, it converts the file into a black png. I have no idea what's going wrong, what should I do?

Code for the function:

from manim import *    

class ThreeSquares(Scene):
    def constructor(self):
        left_square = Square(color=BLUE, fill_opacity=0.7).shift(4 * LEFT)
        middle_square = Square(color=RED, fill_opacity=0.7)
        right_square = Square(color=GREEN, fill_opacity=0.7).shift(4 * RIGHT)
        self.play(Create(left_square), Create(middle_square), Create(right_square))
        self.play(Rotate(left_square, angle=PI), Rotate(right_square, angle=-1*PI), run_time=1)
        self.wait

I've tried running the command manim -pql scene.py ThreeSquares (scene.py is the file name), and that produced a black png.

I've also tried python -m manim scene.py ThreeSquares -p -ql, and that yielded the same result.

I've also tried to look in the documentation for any reason as to why this is happening, and I came up with nothing. I've also looked around on StackOverflow for this and there doesn't seem to be problems pertaining to this specific result.


Solution

  • the solution is very simple, you have written you logic in a function named constructor instead of construct in the 4rd line which is what manim looks for to render the video. Please correct the function name and it should work.

    class DifferentRotations(Scene):
    def construct(self):
        left_square = Square(color=BLUE, fill_opacity=0.7).shift(2 * LEFT)
        right_square = Square(color=GREEN, fill_opacity=0.7).shift(2 * RIGHT)
        self.play(
            left_square.animate.rotate(PI), Rotate(right_square, angle=PI), run_time=2
        )
        self.wait()
    

    Also add parentheses to like so self.wait() in the last line (this does not cause an error though). Hope this helps thankyou!