Resolution and Camera#

[1]:
from manim import *
config.media_embed = True
Manim Community v0.17.3

Scene Coordinates#

First, let’s learn a bit about how manim coordinates work.
There is the config.frame_width, config.frame_height which is unrelated to the pixelsize.
Their default values are 14.222 and 8.
These values are chosen, because it gives and width/height ratio of 16/9, which is a common screen resolution.
The coordinate center of scenes is in the center, which is at (0,0).
The most left point is (-7.1,0), right is (7.1,0), top is (0,4), and button is (0,-4).
[2]:
config.frame_width/config.frame_height
[2]:
1.7777777777777777
[3]:
config.pixel_width/config.pixel_height
[3]:
1.7777777777777777
[4]:
16/9
[4]:
1.7777777777777777
[5]:
# for setup only
def yellow_frame_annotation(framew, frameh):
    d1 = DoubleArrow(framew * LEFT / 2, framew * RIGHT / 2, buff=0).to_edge(DOWN)
    t1 = Text(str(framew)[:6]).next_to(d1, UP)
    d2 = DoubleArrow(frameh * UP / 2, frameh * DOWN / 2, buff=0).to_edge(LEFT)
    t2= Text(str(frameh)).next_to(d2, RIGHT)
    x=Group(d1,d2,t1,t2).set_color(YELLOW)
    return x

def blue_pixel_annotation(framew, frameh,pixelw, pixelh):
    d1 = DoubleArrow(framew * LEFT / 2, framew * RIGHT / 2, buff=0).to_edge(UP)
    t1 = Text(str(pixelw) + " pixel").next_to(d1, DOWN)
    d2 = DoubleArrow(frameh * UP / 2, frameh * DOWN / 2, buff=0).to_edge(RIGHT)
    t2= Text(str(pixelh) + " pixel").next_to(d2, LEFT)
    x=Group(d1,d2,t1,t2).set_color(BLUE)
    return x

annulus = Annulus(inner_radius =1,outer_radius=2,color=WHITE,  stroke_width=10)

Pixel Ratio of 16/9#

See a table of commen 16/9 resolutions here: https://en.wikipedia.org/wiki/16:9_aspect_ratio#Common_resolutions

[6]:
%%manim -v WARNING  -s -r 160,90 --disable_caching Example
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_8_0.png
[7]:
%%manim -v WARNING  -s -r 256,144 --disable_caching Example
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_9_0.png
[8]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_10_0.png
[9]:
%%manim -v WARNING  -s -qm --disable_caching Example
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_11_0.png

Note

The borders of this website are narrow.
To see the changes in high resolution, open this image in a new tab.
[10]:
%%manim -v WARNING  -s -qh --disable_caching Example
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_13_0.png

Pixel Ratio Unequal to 16/9#

  • When the pixel ratio is heigher then 16/9 frame_height cropped.

  • When the pixel ratio is lower then 16/9 frame_height padded.

[11]:
%%manim -v WARNING  -s -r 1000,500 --disable_caching Example
#ratio of 2/1
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_15_0.png
[12]:
%%manim -v WARNING  -s -r 1000,50 --disable_caching Example
#ratio of 20/1
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_16_0.png
[13]:
%%manim -v WARNING  -s -r 500,1000 --disable_caching Example
#ratio of 1/2
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_17_0.png

Changing the frame_width#

  • Increasing the value config.frame_width will zoom out the Mobject

  • Decreasing the value config.frame_width will zoom in the Mobject

Note: The frame_height is adjusted accordingly. Note 2: I do not recommend to change the frame width with config.frame_width, better use the self.camera.frame.set(...) syntax shown in the next section.

[14]:
%%manim -v WARNING  -s -ql --disable_caching Example
config.frame_width =30
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_20_0.png
[15]:
%%manim -v WARNING  -s -ql --disable_caching Example
config.frame_width =13
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_21_0.png
[16]:
%%manim -v WARNING  -s -ql --disable_caching Example
config.frame_width =14.22222
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_22_0.png

Note

Changing config.frame_height has no effect on the Mobjects displaied on the screen.

[17]:
%%manim -v WARNING  -s -ql --disable_caching Example
config.frame_height =42
class Example(Scene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)
        self.add(frame_annotation, pixel_annotation, annulus)
_images/ch5_24_0.png
[18]:
config.frame_height =8 # resetting the frame_height value to default

Camera Scene#

[19]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        s= Star()
        self.camera.frame.set(height=s.get_height()+4*SMALL_BUFF)
        self.add(s)
<string>:4: DeprecationWarning: This method is not guaranteed to stay around. Please prefer getting the attribute normally.
_images/ch5_27_1.png
[20]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        s= Star()
        self.camera.frame.height=s.height+4*SMALL_BUFF # even better
        self.add(s)
_images/ch5_28_0.png
[21]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        mob = DashedLine(color= YELLOW)
        self.camera.frame.width=mob.width +4*SMALL_BUFF
        self.add(mob)
_images/ch5_29_0.png
[22]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        self.camera.frame.set(width=20)
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        self.add(FullScreenRectangle(color=RED, stroke_width=40))
        self.add(frame_annotation, annulus)
_images/ch5_30_0.png
[23]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        self.camera.frame.set(width=40)
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        self.add(FullScreenRectangle(color=RED, stroke_width=40))
        self.add(frame_annotation, annulus)
_images/ch5_31_0.png
[24]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        self.camera.frame.shift(2*DOWN+2*LEFT)
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        self.add(FullScreenRectangle(color=RED, stroke_width=40))
        self.add(frame_annotation, annulus)
_images/ch5_32_0.png
[25]:
%%manim -v WARNING  -s -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        self.camera.frame.shift(4*DOWN+4*LEFT)
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        self.add(FullScreenRectangle(color=RED, stroke_width=40))
        self.add(frame_annotation, annulus)
_images/ch5_33_0.png
[26]:
%%manim -v WARNING   -ql --disable_caching Example
class Example(MovingCameraScene):
    def construct(self):
        frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)
        self.add(FullScreenRectangle(color=RED, stroke_width=40))
        self.add(frame_annotation, annulus)

        self.play(self.camera.frame.animate.shift(UP+2*LEFT).set(width=20))
        self.play(self.camera.frame.animate.shift(2*DOWN+4*RIGHT))

        self.play(self.camera.frame.animate.move_to(ORIGIN).set(width=14.222))