manim/docs/source/tutorials/quickstart.rst
Jason Villanueva a87bb28484
Refactored the Command Line Interface to use Click + Cloup instead of Argparse (#1013)
* Added click dependency and command structure

* Refactored code for separation of concerns

* Shortened plugins command to plugin, added render options

* first draft for render -h

* First successful render using click

* Cleaned main

* Moved flush_cache to option, ran black

* Removed argparse logic, scattered print statements

* corrected tests, all passing

* merge upstream

* fixed test with click's clirunner

* Fixed doctest configuration.rst

* Temporarily add in main_utils

* Removed main_utils.parse_args, used ManimConfig.digest_args

* fixed progress bar

* Fix jupyter

* black

* Fixed incorrectly merged merge conflict

* updated README command.png image

* updated configuration.rst expected output

* Fixed test_plugins and config_file expected type

* Refixed the jupyter fix

* Apply 3/5 suggestions

Remove stray print

Improve readability of test code

Added module docs for the subcommands

* Updated `main` to `manim` for tests

* Forced `file` positional argument to be Path type

* Fixed main -> manim

* Added libpango to linux dependency

* Updated poetry.lock

* Changed configuration.rst test

* Fixed test_a_flag test

minor space issue

added media_width to configuration.rst

* Fixed fps flag in Cairo rendering

* Fixed more outdated rst in sphinx docs

Removed default for fps option, always overwrote quality

Fixed doctest control_data

* Fixed more incorrect rst orderings

* Update tests/test_commands.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Added suggestions

* Removed unused imports

* Reverted entry point back to main

* Update manim/_config/default.cfg

Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>

* Adjusted ipython_magic's call to the entry_point

* Converted frame_rate to int if integer

* run black

* Fixed doctest

* Fixed issue with command name from CliRunner

* Fixed multiple video windows opening from upstream merge

* to black or not to black

* Added deprecation warning to render subcommand

* warning instead of warn

* Applied Naveen's suggestions

* Made `manim render` show the help page

* Update manim/cli/render/commands.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Update manim/cli/cfg/commands.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Update manim/cli/cfg/commands.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Update manim/cli/plugins/commands.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Addressed some style changes

* add back in write_to_movie temporarily for OpenGL support

* Removed sound flag, deprecated use_opengl_renderer, added renderer option

* revert webgl_renderer_path removal

* Fixed cfg export

Fixed readme usage of CLI

* Flake8/black

* Fixed bug in setting renderer choice

* Removed log message due to default option

Removed default option of background color

Fixed write_to_movie flag default

* Fix log_to_file tests

* Make '-c' option for config_file, not background_color

* print colored version always

* Remove -v = --version shorthand, conflicts with verbosity

* Use subprocess.run instead of Click's CliRunner for stdout

* Refactor cli/render to use Cloup instead of click-option-group

1) There's a new file for each option group
2) render is now a cloup.Command, not a Group

Fixed issue when an animation is cached, manim can't merge the partial movie files. (#1192)

* fixed issue

* fixed tests

* Update manim/renderer/cairo_renderer.py

Co-authored-by: Darylgolden <darylgolden@gmail.com>

* added tests

* imrpoved test

* fixed logic

* added new test

* check if the file has been outputed

* added test when caching is enabled

* fixed tests on windows

* black

* Update manim/renderer/cairo_renderer.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Update tests/assert_utils.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

Co-authored-by: KingWampy <9156604+WampyCakes@users.noreply.github.com>
Co-authored-by: Darylgolden <darylgolden@gmail.com>
Co-authored-by: Naveen M K <naveen@syrusdark.website>

Added :ref_methods: to the manim directive (#1209)

* fix manim_directive for methods

* added ref_methods to Angle example

* black

* added new ref_methods references

* sort out ref_functions vs ref_methods in examples.rst

Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>

Fixed issue when an animation is cached, manim can't merge the partial movie files. (#1192)

* fixed issue

* fixed tests

* Update manim/renderer/cairo_renderer.py

Co-authored-by: Darylgolden <darylgolden@gmail.com>

* added tests

* imrpoved test

* fixed logic

* added new test

* check if the file has been outputed

* added test when caching is enabled

* fixed tests on windows

* black

* Update manim/renderer/cairo_renderer.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Update tests/assert_utils.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

Co-authored-by: KingWampy <9156604+WampyCakes@users.noreply.github.com>
Co-authored-by: Darylgolden <darylgolden@gmail.com>
Co-authored-by: Naveen M K <naveen@syrusdark.website>

Added :ref_methods: to the manim directive (#1209)

* fix manim_directive for methods

* added ref_methods to Angle example

* black

* added new ref_methods references

* sort out ref_functions vs ref_methods in examples.rst

Co-authored-by: Jason Villanueva <a@jsonvillanueva.com>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>

Fixed unnecessary args dict

* Fixed bug that changed caching hashing result

* Revert doctest logic for fps filename output

Co-authored-by: Naveen M K <naveen@syrusdark.website>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
Co-authored-by: Gianluca Gippetto <gianluca.gippetto@gmail.com>
2021-04-01 23:53:07 -07:00

193 lines
6.5 KiB
ReStructuredText

==========
Quickstart
==========
This document will lead you step by step through the necessary procedure to get
started with manim for the first time as soon as possible. This tutorial
assumes you have already installed manim following the steps in
:doc:`../installation`.
Start a new project
*******************
To start a new manim video project, all you need to do is choose a single
folder where all of the files related to the video will reside. For this
example, this folder will be called ``project``,
.. code-block:: bash
project/
Every file containing code that produces a video with manim will be stored
here, as well as any output files that manim produces and configuration files
that manim needs.
.. note::
In case you like to work with Jupyterlab / Jupyter notebooks, there is good news:
Manim ships with a ``%%manim`` IPython magic command which makes it easy to use
in such a setting as well. Find out more in the
:meth:`corresponding documentation <manim.utils.ipython_magic.ManimMagic.manim>`.
Your first Scene
****************
To produce your first scene, create a new file in your project folder called
``scene.py``,
.. code-block:: bash
project/
└─scene.py
and copy the following code in it.
.. code-block:: python
from manim import *
class SquareToCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set the color and transparency
self.play(Create(circle)) # show the circle on screen
Then open your command line, navigate to your project directory, and execute
the following command:
.. code-block:: bash
$ manim -pql scene.py SquareToCircle
After showing some output, manim should render the scene into a .mp4 file,
and open that file with the default movie player application. You should see a
video playing the following animation.
.. manim:: SquareToCircle
:hide_source:
class SquareToCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set the color and transparency
self.play(Create(circle)) # show the circle on screen
If you see the video and it looks correct, congrats! You just wrote your first
manim scene from scratch. If you get an error message instead, or if do not
see a video, or if the video output does not look like this, it is likely that
manim has not been installed correctly. Please refer to the
:doc:`../installation/troubleshooting` page for more information.
***********
Explanation
***********
Let's go line by line over the script we just executed to see how manim was
able to generate the video.
The first line
.. code-block:: python
from manim import *
imports all of the contents of the library. This is the recommended way of
using manim, as usually in a single script you will be using quite a few names
from the manim namespace. In particular, this line includes all of the names
used in the script: ``Scene``, ``Circle``, ``PINK`` and ``Create``.
Now let's look at the next two lines.
.. code-block:: python
class SquareToCircle(Scene):
def construct(self):
Most of the time, the code for scripting an animation with manim will go inside
the :meth:`~.Scene.construct` method of a class that derives from :class:`.Scene`. Inside this
method, you will create objects, display them on screen, and animate them.
The next two lines create a circle and set its color and opacity.
.. code-block:: python
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set the color and transparency
Finally, the last line uses the animation :class:`.Create` to display the
circle on screen.
.. code-block:: python
self.play(Create(circle)) # show the circle on screen
.. tip:: Every animation must be contained within the :meth:`~.Scene.construct` method of a
class that derives from :class:`.Scene`. Other code, for example auxiliary
or mathematical functions, may reside outside the class.
Some bells and whistles
***********************
Our scene is a little basic, so let's add some bells and whistles. Modify the
``scene.py`` file to contain the following:
.. code-block:: python
from manim import *
class SquareToCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set color and transparency
square = Square() # create a square
square.flip(RIGHT) # flip horizontally
square.rotate(-3 * TAU / 8) # rotate a certain amount
self.play(Create(square)) # animate the creation of the square
self.play(Transform(square, circle)) # interpolate the square into the circle
self.play(FadeOut(square)) # fade out animation
And render it using the following command:
.. code-block:: bash
$ manim -pql scene.py SquareToCircle
The output should look as follows.
.. manim:: SquareToCircle2
:hide_source:
class SquareToCircle2(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set color and transparency
square = Square() # create a square
square.flip(RIGHT) # flip horizontally
square.rotate(-3 * TAU / 8) # rotate a certain amount
self.play(Create(square)) # animate the creation of the square
self.play(Transform(square, circle)) # interpolate the square into the circle
self.play(FadeOut(square)) # fade out animation
This example shows one of the most basic features of manim: the ability to
implement complicated and mathematically-intensive animations (such as cleanly
interpolating between two geometric shapes) in very few lines of code.
************
You're done!
************
With a working installation of manim, and the bare basics under your belt, it
is now time to start creating awesome mathematical animations. For a look
under the hood at what manim is doing when rendering the ``SquareToCircle``
scene, see the next tutorial :doc:`a_deeper_look`. For an extensive review of
manim's features, as well as its configuration and other settings, see the
other :doc:`../tutorials`. For a list of all available features, see the
:doc:`../reference` page.