Mukul Sharma
Mukul Sharma

Reputation: 21

I am using manim version v0.17.03 and trying to animate scene by focusing camera on a specific shape, but am unable to use camera help me

I am trying this code :-

class CameraFocusing(Scene):
    def construct(self):
        s = Square(color=YELLOW).move_to(np.array([-4,0,0]))
        c = Circle().move_to(np.array([4,0,0]))
        self.add(s,c)
        self.wait(3)
        
        self.camera.frame_center = s.get_center()
        self.wait(3)
        
        self.play(self.camera.frame.animate.shift(8 * RIGHT))
        self.wait(2)

type here


        
        if __name__ == "__main__":
            config.pixel_height = 720
            config.pixel_width = 1280
            config.frame_height = 7.0
            config.frame_width = 7.0
            config.frame_center = [-4, 0, 0]
            config.background_color = BLACK
            config.pixel_height = 720
            config.pixel_width = 1280
            config.save_as_gif = True
            config.quality = "medium"
            config.media_height = 7.0
            config.media_width = 7.0

            scene = CameraFocusing()
            scene.render()

but whenever i am trying to execute this, i get this Attribute error:-

AttributeError: 'Camera' object has no attribute 'frame'

Upvotes: 2

Views: 215

Answers (1)

herdek550
herdek550

Reputation: 695

Your class should be inhereting from MovingCameraScene class instead of Scene.

Following code works in Manim Community v0.19.0

from manim import *

class CameraFocusing(MovingCameraScene):
    def construct(self):
        
        # add a circle
        self.add(Circle(radius=0.5, color=RED).move_to((0, 0.5, 0)))
        
        # wait
        self.wait(1)

        # move the camera for example
        self.play(self.camera.frame.animate.move_to((0, 1, 0)))

        # wait
        self.wait(2)

By the way, I have been using manim for less than a day so I am not sure if my solution is perfect. But it worked for me.

Upvotes: 0

Related Questions