Created
October 1, 2024 16:41
-
-
Save uwezi/65e842a78857852a4e715670acd31a97 to your computer and use it in GitHub Desktop.
[autozoomed scene] A scene which adapts the camera frame to show all mobjects. #manim #movingcamerascene #frame #zoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://discord.com/channels/581738731934056449/1290678443905650819/1290678443905650819 | |
from manim import * | |
class autozoom(MovingCameraScene): | |
def construct(self): | |
sq = Square() | |
circ = Circle() | |
self.add(sq,circ) | |
self.add(self.camera.frame) | |
def zoomUpdater(mobj): | |
self.mobjects.remove(mobj) # camera frame must not be in list | |
boundary_box = Group(*self.mobjects) | |
bb_aspect = boundary_box.width/boundary_box.height | |
camera_aspect = mobj.width/mobj.height | |
if bb_aspect >= camera_aspect: | |
mobj.scale_to_fit_width(boundary_box.width*1.05) | |
else: | |
mobj.scale_to_fit_height(boundary_box.height*1.05) | |
mobj.move_to(boundary_box.get_center()) | |
self.add(mobj) | |
self.camera.frame.add_updater(zoomUpdater, call_updater=True) | |
self.wait() | |
self.play(circ.animate.scale(3)) | |
self.wait() | |
self.play(sq.animate.shift(8*RIGHT)) | |
self.wait() | |
c2 = Circle().shift(4*LEFT) | |
self.play(Create(c2)) | |
self.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment