<metaname="viewport"content="width=device-width,initial-scale=1"/><linkrel="index"title="Index"href="../genindex.html"/><linkrel="search"title="Search"href="../search.html"/><linkrel="next"title="CLI flags and configuration"href="configuration.html"/><linkrel="prev"title="Installation"href="installation.html"/>
<h1>Quick Start<aclass="headerlink"href="#quick-start"title="Permalink to this headline">¶</a></h1>
<p>After installing the manim environment according to the instructions on the
<aclass="reference internal"href="installation.html"><spanclass="doc">Installation</span></a> page, you can try to make a scene yourself from scratch.</p>
<p>First, create a new <codeclass="docutils literal notranslate"><spanclass="pre">.py</span></code> file (such as <codeclass="docutils literal notranslate"><spanclass="pre">start.py</span></code>) according to the following
<p>A window will pop up on the screen. And then you can :</p>
<ulclass="simple">
<li><p>scroll the middle mouse button to move the screen up and down</p></li>
<li><p>hold down the <kbdclass="kbd docutils literal notranslate">z</kbd> on the keyboard while scrolling the middle mouse button to zoom the screen</p></li>
<li><p>hold down the <kbdclass="kbd docutils literal notranslate">s</kbd> key on the keyboard and move the mouse to pan the screen</p></li>
<li><p>hold down the <kbdclass="kbd docutils literal notranslate">d</kbd> key on the keyboard and move the mouse to change the three-dimensional perspective.</p></li>
</ul>
<p>Finally, you can close the window and exit the program by pressing <kbdclass="kbd docutils literal notranslate">q</kbd>.</p>
<p>At this time, no window will pop up. When the program is finished, this rendered
image will be automatically opened (saved in the subdirectory <codeclass="docutils literal notranslate"><spanclass="pre">images/</span></code> of the same
level directory of <codeclass="docutils literal notranslate"><spanclass="pre">start.py</span></code> by default):</p>
<p>Create a <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Scene</span></code> subclass <codeclass="docutils literal notranslate"><spanclass="pre">SquareToCircle</span></code>, which will be
<p>Create a circle (an instance of the <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Circle</span></code> class), called <codeclass="docutils literal notranslate"><spanclass="pre">circle</span></code></p>
<p>Set the circle style by calling the circle’s method.</p>
<ulclass="simple">
<li><p>The <codeclass="docutils literal notranslate"><spanclass="pre">.set_fill()</span></code> method sets the fill color of this circle to blue (<codeclass="docutils literal notranslate"><spanclass="pre">BLUE</span></code>, defined in <aclass="reference internal"href="../documentation/constants.html"><spanclass="doc">constants</span></a>), and the fill transparency to 0.5.</p></li>
<li><p>The <codeclass="docutils literal notranslate"><spanclass="pre">.set_stroke()</span></code> method sets the stroke color of this circle to dark blue (<codeclass="docutils literal notranslate"><spanclass="pre">BLUE_E</span></code>, defined in <aclass="reference internal"href="../documentation/constants.html"><spanclass="doc">constants</span></a>), and the stroke width to 4.</p></li>
<p>Add this circle to the screen through the <codeclass="docutils literal notranslate"><spanclass="pre">.add()</span></code> method of <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Scene</span></code>.</p>
</div>
<divclass="section"id="add-animations">
<h2>Add animations<aclass="headerlink"href="#add-animations"title="Permalink to this headline">¶</a></h2>
<p>Let’s change some codes and add some animations to make videos instead of just pictures.</p>
<p>This time there will be no pop-up window, but the video file (saved in the subdirectory
<codeclass="docutils literal notranslate"><spanclass="pre">videos/</span></code> of the same level directory of <codeclass="docutils literal notranslate"><spanclass="pre">start.py</span></code> by default) will be automatically
opened after the operation is over:</p>
<videoautoplay=""class="manim-video"controls=""loop=""src="../_static/quickstart/SquareToCircle.mp4"></video><p>Let’s take a look at the code this time. The first 7 lines are the same as the previous
ones, and the 8th line is similar to the 5th line, which creates an instance of the
<codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Square</span></code> class and named it <codeclass="docutils literal notranslate"><spanclass="pre">square</span></code>.</p>
<p>An animation is played through <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Scene</span></code>’s <codeclass="docutils literal notranslate"><spanclass="pre">.play()</span></code> method. <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">ShowCreation</span></code>
is an animation that shows the process of creating a given mobject.
<codeclass="docutils literal notranslate"><spanclass="pre">self.play(ShowCreation(square))</span></code> is to play the animation of creating <codeclass="docutils literal notranslate"><spanclass="pre">square</span></code>.</p>
<p>Use <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Scene</span></code>’s <codeclass="docutils literal notranslate"><spanclass="pre">.wait()</span></code> method to pause (default 1s), you can pass in
parameters to indicate the pause time (for example, <codeclass="docutils literal notranslate"><spanclass="pre">self.wait(3)</span></code> means pause for 3s).</p>
<p>Play the animation that transforms <codeclass="docutils literal notranslate"><spanclass="pre">square</span></code> into <codeclass="docutils literal notranslate"><spanclass="pre">circle</span></code>.
<codeclass="docutils literal notranslate"><spanclass="pre">ReplacementTransform(A,</span><spanclass="pre">B)</span></code> means to transform A into B’s pattern and replace A with B.</p>
<p><strong>Line 13</strong>: Same as line 11, pause for 1s.</p>
</div>
<divclass="section"id="enable-interaction">
<h2>Enable interaction<aclass="headerlink"href="#enable-interaction"title="Permalink to this headline">¶</a></h2>
<p>Interaction is a new feature of the new version. You can add the following line
<p>Then run <codeclass="docutils literal notranslate"><spanclass="pre">manimgl</span><spanclass="pre">start.py</span><spanclass="pre">SquareToCircle</span></code>.</p>
<p>After the previous animation is executed, the ipython terminal will be opened on
the command line. After that, you can continue to write code in it, and the statement
you entered will be executed immediately after pressing <kbdclass="kbd docutils literal notranslate">Enter</kbd>.</p>
<p>For example: input the following lines (without comment lines) into it respectively
(<codeclass="docutils literal notranslate"><spanclass="pre">self.play</span></code> can be abbreviated as <codeclass="docutils literal notranslate"><spanclass="pre">play</span></code> in this mode):</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># Stretched 4 times in the vertical direction</span>
<p>You will get an animation similar to the following:</p>
<videoautoplay=""class="manim-video"controls=""loop=""src="../_static/quickstart/SquareToCircleEmbed.mp4"></video><p>If you want to enter the interactive mode directly, you don’t have to write an
empty scene containing only <codeclass="docutils literal notranslate"><spanclass="pre">self.embed()</span></code>, you can directly run the following command
(this will enter the ipython terminal while the window pops up):</p>
<h2>You succeeded!<aclass="headerlink"href="#you-succeeded"title="Permalink to this headline">¶</a></h2>
<p>After reading the above content, you already know how to use manim.
Below you can see some examples, in the <aclass="reference internal"href="example_scenes.html"><spanclass="doc">Example Scenes</span></a> page.
But before that, you’d better have a look at the <aclass="reference internal"href="configuration.html"><spanclass="doc">CLI flags and configuration</span></a> of manim.</p>
</div>
</div>
</article>
<footer>
<divclass="related-pages">
<aclass="next-page"href="configuration.html">
<divclass="page-info">
<divclass="context">
<span>Next</span>
</div>
<divclass="title">CLI flags and configuration</div>