{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Resolution and Camera \n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from manim import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Scene Coordinates\n", "First, let's learn a bit about how manim coordinates work. \n", "There is the config.frame_width, config.frame_height which is unrelated to the pixelsize. \n", "Their default values are 14.222 and 8. \n", "These values are chosen, because it gives and width/height ratio of 16/9, which is a common screen resolution. \n", "The coordinate center of scenes is in the center, which is at **(0,0)**. \n", "The most left point is **(-7.1,0)**, right is **(7.1,0)**, top is **(0,4)**, and button is **(0,-4)**." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "config.frame_width/config.frame_height " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "config.pixel_width/config.pixel_height " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "16/9" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# for setup only\n", "def yellow_frame_annotation(framew, frameh):\n", " d1 = DoubleArrow(framew * LEFT / 2, framew * RIGHT / 2, buff=0).to_edge(DOWN)\n", " t1 = Text(str(framew)[:6]).next_to(d1, UP)\n", " d2 = DoubleArrow(frameh * UP / 2, frameh * DOWN / 2, buff=0).to_edge(LEFT)\n", " t2= Text(str(frameh)).next_to(d2, RIGHT)\n", " x=Group(d1,d2,t1,t2).set_color(YELLOW)\n", " return x\n", "\n", "def blue_pixel_annotation(framew, frameh,pixelw, pixelh):\n", " d1 = DoubleArrow(framew * LEFT / 2, framew * RIGHT / 2, buff=0).to_edge(UP)\n", " t1 = Text(str(pixelw) + \" pixel\").next_to(d1, DOWN)\n", " d2 = DoubleArrow(frameh * UP / 2, frameh * DOWN / 2, buff=0).to_edge(RIGHT)\n", " t2= Text(str(pixelh) + \" pixel\").next_to(d2, LEFT)\n", " x=Group(d1,d2,t1,t2).set_color(BLUE)\n", " return x\n", "\n", "annulus = Annulus(inner_radius =1,outer_radius=2,color=WHITE, stroke_width=10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Pixel Ratio of 16/9\n", "See a table of commen 16/9 resolutions here: https://en.wikipedia.org/wiki/16:9_aspect_ratio#Common_resolutions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -r 160,90 --disable_caching Example\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -r 256,144 --disable_caching Example\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -qm --disable_caching Example\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "Note\n", "\n", "The borders of this website are narrow. \n", "To see the changes in high resolution, open this image in a new tab.\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -qh --disable_caching Example\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Pixel Ratio Unequal to 16/9\n", "\n", "* When the pixel ratio is heigher then 16/9 frame_height cropped. \n", "* When the pixel ratio is lower then 16/9 frame_height padded. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -r 1000,500 --disable_caching Example\n", "#ratio of 2/1\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -r 1000,50 --disable_caching Example\n", "#ratio of 20/1\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -r 500,1000 --disable_caching Example\n", "#ratio of 1/2\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Changing the frame_width" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* **Increasing** the value `config.frame_width` will **zoom out** the Mobject\n", "* **Decreasing** the value `config.frame_width` will **zoom in** the Mobject\n", "\n", "Note: The frame_height is adjusted accordingly. \n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "config.frame_width =30\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "config.frame_width =13\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "config.frame_width =14.22222\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "Note\n", "\n", "Changing `config.frame_height` has no effect on the Mobjects displaied on the screen.\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "config.frame_height =42\n", "class Example(Scene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " pixel_annotation= blue_pixel_annotation(config.frame_width,config.frame_height,config.pixel_width,config.pixel_height)\n", " self.add(frame_annotation, pixel_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "config.frame_height =8 # resetting the frame_height value to default" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Camera Scene" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " s= Star()\n", " self.camera.frame.set(height=s.get_height()+4*SMALL_BUFF)\n", " self.add(s)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " s= Star()\n", " self.camera.frame.height=s.height+4*SMALL_BUFF # even better\n", " self.add(s)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " mob = DashedLine(color= YELLOW) \n", " self.camera.frame.width=mob.width +4*SMALL_BUFF\n", " self.add(mob)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " self.camera.frame.set(width=20)\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " self.add(FullScreenRectangle(color=RED, stroke_width=40))\n", " self.add(frame_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " self.camera.frame.set(width=40)\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " self.add(FullScreenRectangle(color=RED, stroke_width=40))\n", " self.add(frame_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " self.camera.frame.shift(2*DOWN+2*LEFT)\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " self.add(FullScreenRectangle(color=RED, stroke_width=40))\n", " self.add(frame_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -s -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " self.camera.frame.shift(4*DOWN+4*LEFT)\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " self.add(FullScreenRectangle(color=RED, stroke_width=40))\n", " self.add(frame_annotation, annulus)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%manim -v WARNING -ql --disable_caching Example\n", "class Example(MovingCameraScene):\n", " def construct(self):\n", " frame_annotation= yellow_frame_annotation(config.frame_width,config.frame_height)\n", " self.add(FullScreenRectangle(color=RED, stroke_width=40))\n", " self.add(frame_annotation, annulus)\n", " \n", " self.play(self.camera.frame.animate.shift(UP+2*LEFT).set(width=20))\n", " self.play(self.camera.frame.animate.shift(2*DOWN+4*RIGHT))\n", "\n", " self.play(self.camera.frame.animate.move_to(ORIGIN).set(width=14.222))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.5" } }, "nbformat": 4, "nbformat_minor": 4 }