mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
finished Quick Start
This commit is contained in:
parent
a7697095d6
commit
cd79151c10
11 changed files with 312 additions and 5 deletions
37
docs/example.py
Normal file
37
docs/example.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
from manimlib.imports import *
|
||||||
|
|
||||||
|
class SquareToCircle(Scene):
|
||||||
|
def construct(self):
|
||||||
|
circle = Circle()
|
||||||
|
circle.set_fill(BLUE, opacity=0.5)
|
||||||
|
circle.set_stroke(BLUE_E, width=4)
|
||||||
|
square = Square()
|
||||||
|
|
||||||
|
self.play(ShowCreation(square))
|
||||||
|
self.wait()
|
||||||
|
self.play(ReplacementTransform(square, circle))
|
||||||
|
self.wait()
|
||||||
|
# Try typing the following lines
|
||||||
|
# self.play(circle.stretch, 4, {"dim": 0})
|
||||||
|
# self.play(Rotate(circle, TAU / 4))
|
||||||
|
# self.play(circle.shift, 2 * RIGHT, circle.scale, 0.25)
|
||||||
|
# circle.insert_n_curves(10)
|
||||||
|
# self.play(circle.apply_complex_function, lambda z: z**2)
|
||||||
|
|
||||||
|
class SquareToCircleEmbed(Scene):
|
||||||
|
def construct(self):
|
||||||
|
circle = Circle()
|
||||||
|
circle.set_fill(BLUE, opacity=0.5)
|
||||||
|
circle.set_stroke(BLUE_E, width=4)
|
||||||
|
|
||||||
|
self.add(circle)
|
||||||
|
self.wait()
|
||||||
|
self.play(circle.stretch, 4, {"dim": 0})
|
||||||
|
self.wait(1.5)
|
||||||
|
self.play(Rotate(circle, TAU / 4))
|
||||||
|
self.wait(1.5)
|
||||||
|
self.play(circle.shift, 2 * RIGHT, circle.scale, 0.25)
|
||||||
|
self.wait(1.5)
|
||||||
|
circle.insert_n_curves(10)
|
||||||
|
self.play(circle.apply_complex_function, lambda z: z**2)
|
||||||
|
self.wait(2)
|
|
@ -1,3 +1,7 @@
|
||||||
|
p {
|
||||||
|
font-size: initial;
|
||||||
|
}
|
||||||
|
|
||||||
span.caption-text {
|
span.caption-text {
|
||||||
font-size: larger;
|
font-size: larger;
|
||||||
}
|
}
|
||||||
|
|
BIN
docs/source/_static/quickstart/SquareToCircle.mp4
Normal file
BIN
docs/source/_static/quickstart/SquareToCircle.mp4
Normal file
Binary file not shown.
BIN
docs/source/_static/quickstart/SquareToCircle.png
Normal file
BIN
docs/source/_static/quickstart/SquareToCircle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
docs/source/_static/quickstart/SquareToCircleEmbed.mp4
Normal file
BIN
docs/source/_static/quickstart/SquareToCircleEmbed.mp4
Normal file
Binary file not shown.
2
docs/source/getting_started/cli_flags.rst
Normal file
2
docs/source/getting_started/cli_flags.rst
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
CLI Flags
|
||||||
|
=========
|
2
docs/source/getting_started/configuration.rst
Normal file
2
docs/source/getting_started/configuration.rst
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Configuration
|
||||||
|
=============
|
|
@ -1,9 +1,8 @@
|
||||||
Quick Start
|
Example Scenes
|
||||||
===========
|
==============
|
||||||
|
|
||||||
|
|
||||||
.. manim-example:: WarpSquare
|
.. manim-example:: WarpSquare
|
||||||
:media: ../../_static/example_scenes/WarpSquare.mp4
|
:media: ../_static/example_scenes/WarpSquare.mp4
|
||||||
|
|
||||||
class WarpSquare(Scene):
|
class WarpSquare(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
|
@ -24,6 +24,9 @@ that directory execute:
|
||||||
# Try it out
|
# Try it out
|
||||||
python -m manim example_scenes.py OpeningManimExample
|
python -m manim example_scenes.py OpeningManimExample
|
||||||
|
|
||||||
|
If you run the above command and no error message appears,
|
||||||
|
then you have successfully installed all the environments required by manim.
|
||||||
|
|
||||||
Directly (Windows)
|
Directly (Windows)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|
257
docs/source/getting_started/quickstart.rst
Normal file
257
docs/source/getting_started/quickstart.rst
Normal file
|
@ -0,0 +1,257 @@
|
||||||
|
Quick Start
|
||||||
|
===========
|
||||||
|
|
||||||
|
After installing the manim environment according to the instructions on the
|
||||||
|
:doc:`installation` page, you can try to make a scene yourself from scratch.
|
||||||
|
|
||||||
|
First, create a new ``.py`` file (such as ``start.py``) according to the following
|
||||||
|
directory structure:
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
:emphasize-lines: 8
|
||||||
|
|
||||||
|
manim/
|
||||||
|
├── manimlib/
|
||||||
|
│ ├── animation/
|
||||||
|
│ ├── ...
|
||||||
|
│ └── window.py
|
||||||
|
├── custom_default.yml
|
||||||
|
├── manim.py
|
||||||
|
└── start.py
|
||||||
|
|
||||||
|
And paste the following code (I will explain the function of each line in detail later):
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
:linenos:
|
||||||
|
|
||||||
|
from manimlib.imports import *
|
||||||
|
|
||||||
|
class SquareToCircle(Scene):
|
||||||
|
def construct(self):
|
||||||
|
circle = Circle()
|
||||||
|
circle.set_fill(BLUE, opacity=0.5)
|
||||||
|
circle.set_stroke(BLUE_E, width=4)
|
||||||
|
|
||||||
|
self.add(circle)
|
||||||
|
|
||||||
|
And run this command:
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
python manim.py start.py SquareToCircle
|
||||||
|
|
||||||
|
A window will pop up on the screen. And then you can :
|
||||||
|
|
||||||
|
- scroll the middle mouse button to move the screen up and down
|
||||||
|
- hold down the :kbd:`z` on the keyboard while scrolling the middle mouse button to zoom the screen
|
||||||
|
- hold down the :kbd:`s` key on the keyboard and move the mouse to pan the screen
|
||||||
|
- hold down the :kbd:`d` key on the keyboard and move the mouse to change the three-dimensional perspective.
|
||||||
|
|
||||||
|
Finally, you can close the window and exit the program by pressing :kbd:`q`.
|
||||||
|
|
||||||
|
Run this command again:
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
python manim.py start.py SquareToCircle -os
|
||||||
|
|
||||||
|
At this time, no window will pop up. When the program is finished, this rendered
|
||||||
|
image will be automatically opened (saved in the subdirectory ``images/`` of the same
|
||||||
|
level directory of ``start.py`` by default):
|
||||||
|
|
||||||
|
.. image:: ../_static/quickstart/SquareToCircle.png
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
Make an image
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Next, let's take a detailed look at what each row does.
|
||||||
|
|
||||||
|
**Line 1**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from manimlib.imports import *
|
||||||
|
|
||||||
|
This will import all the classes that may be used when using manim.
|
||||||
|
|
||||||
|
**Line 2**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
class SquareToCircle(Scene):
|
||||||
|
|
||||||
|
Create a :class:`Scene` subclass ``SquareToCircle``, which will be
|
||||||
|
the scene you write and render.
|
||||||
|
|
||||||
|
**Line 4**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
def construct(self):
|
||||||
|
|
||||||
|
Write the ``construct()`` method, the content of which will determine
|
||||||
|
how to create the mobjects in the screen and what operations need to be performed.
|
||||||
|
|
||||||
|
**Line 5**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
circle = Circle()
|
||||||
|
|
||||||
|
Create a circle (an instance of the :class:`Circle` class), called ``circle``
|
||||||
|
|
||||||
|
**Line 6~7**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
circle.set_fill(BLUE, opacity=0.5)
|
||||||
|
circle.set_stroke(BLUE_E, width=4)
|
||||||
|
|
||||||
|
Set the circle style by calling the circle's method.
|
||||||
|
|
||||||
|
- The ``.set_fill()`` method sets the fill color of this circle to blue (``BLUE``, defined in :doc:`../documentation/constants`), and the fill transparency to 0.5.
|
||||||
|
- The ``.set_stroke()`` method sets the stroke color of this circle to dark blue (``BLUE_E``, defined in :doc:`../documentation/constants`), and the stroke width to 4.
|
||||||
|
|
||||||
|
**Line 9**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.add(circle)
|
||||||
|
|
||||||
|
Add this circle to the screen through the ``.add()`` method of :class:`Scene`.
|
||||||
|
|
||||||
|
Add animations
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Let's change some codes and add some animations to make videos instead of just pictures.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
:linenos:
|
||||||
|
|
||||||
|
from manimlib.imports import *
|
||||||
|
|
||||||
|
class SquareToCircle(Scene):
|
||||||
|
def construct(self):
|
||||||
|
circle = Circle()
|
||||||
|
circle.set_fill(BLUE, opacity=0.5)
|
||||||
|
circle.set_stroke(BLUE_E, width=4)
|
||||||
|
square = Square()
|
||||||
|
|
||||||
|
self.play(ShowCreation(square))
|
||||||
|
self.wait()
|
||||||
|
self.play(ReplacementTransform(square, circle))
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
Run this command this time:
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
python manim.py start.py SquareToCircle
|
||||||
|
|
||||||
|
The pop-up window will play animations of drawing a square and transforming
|
||||||
|
it into a circle. If you want to save this video, run:
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
python manim.py start.py SquareToCircle -ow
|
||||||
|
|
||||||
|
This time there will be no pop-up window, but the video file (saved in the subdirectory
|
||||||
|
``videos/`` of the same level directory of ``start.py`` by default) will be automatically
|
||||||
|
opened after the operation is over:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<video class="manim-video" controls loop autoplay src="../_static/quickstart/SquareToCircle.mp4"></video>
|
||||||
|
|
||||||
|
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
|
||||||
|
:class:`Square` class and named it ``square``.
|
||||||
|
|
||||||
|
**Line 10**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.play(ShowCreation(square))
|
||||||
|
|
||||||
|
An animation is played through :class:`Scene`'s ``.play()`` method. :class:`ShowCreation`
|
||||||
|
is an animation that shows the process of creating a given mobject.
|
||||||
|
``self.play(ShowCreation(square))`` is to play the animation of creating ``square``.
|
||||||
|
|
||||||
|
**Line 11**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
Use :class:`Scene`'s ``.wait()`` method to pause (default 1s), you can pass in
|
||||||
|
parameters to indicate the pause time (for example, ``self.wait(3)`` means pause for 3s).
|
||||||
|
|
||||||
|
**Line 12**:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.play(ReplacementTransform(square, circle))
|
||||||
|
|
||||||
|
Play the animation that transforms ``square`` into ``circle``.
|
||||||
|
``ReplacementTransform(A, B)`` means to transform A into B's pattern and replace A with B.
|
||||||
|
|
||||||
|
**Line 13**: Same as line 11, pause for 1s.
|
||||||
|
|
||||||
|
|
||||||
|
Enable interaction
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Interaction is a new feature of the new version. You can add the following line
|
||||||
|
at the end of the code to enable interaction:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.embed()
|
||||||
|
|
||||||
|
Then run ``python manim.py start.py SquareToCircle``.
|
||||||
|
|
||||||
|
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 :kbd:`Enter`.
|
||||||
|
|
||||||
|
For example: input the following lines (without comment lines) into it respectively
|
||||||
|
(``self.play`` can be abbreviated as ``play`` in this mode):
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Stretched 4 times in the vertical direction
|
||||||
|
play(circle.stretch, 4, {"dim": 0})
|
||||||
|
# Rotate the ellipse 90°
|
||||||
|
play(Rotate(circle, TAU / 4))
|
||||||
|
# Move 2 units to the right and shrink to 1/4 of the original
|
||||||
|
play(circle.shift, 2 * RIGHT, circle.scale, 0.25)
|
||||||
|
# Insert 10 curves into circle for non-linear transformation (no animation will play)
|
||||||
|
circle.insert_n_curves(10)
|
||||||
|
# Apply a complex transformation of f(z)=z^2 to all points on the circle
|
||||||
|
play(circle.apply_complex_function, lambda z: z**2)
|
||||||
|
# Close the window and exit the program
|
||||||
|
exit()
|
||||||
|
|
||||||
|
You will get an animation similar to the following:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<video class="manim-video" controls loop autoplay src="../_static/quickstart/SquareToCircleEmbed.mp4"></video>
|
||||||
|
|
||||||
|
If you want to enter the interactive mode directly, you don't have to write an
|
||||||
|
empty scene containing only ``self.embed()``, you can directly run the following command
|
||||||
|
(this will enter the ipython terminal while the window pops up):
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
python manim.py
|
||||||
|
|
||||||
|
You succeeded!
|
||||||
|
--------------
|
||||||
|
|
||||||
|
After reading the above content, you already know how to use manim.
|
||||||
|
Below you can see some examples, in the :doc:`example_scenes` page.
|
||||||
|
But before that, you'd better have a look at the :doc:`cli_flags` and the
|
||||||
|
:doc:`configuration` of manim.
|
||||||
|
|
|
@ -11,7 +11,10 @@ at `3Blue1Brown <https://www.3blue1brown.com/>`_.
|
||||||
:caption: Getting Started
|
:caption: Getting Started
|
||||||
|
|
||||||
getting_started/installation
|
getting_started/installation
|
||||||
getting_started/quickstart/index
|
getting_started/quickstart
|
||||||
|
getting_started/cli_flags
|
||||||
|
getting_started/configuration
|
||||||
|
getting_started/example_scenes
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
Loading…
Add table
Reference in a new issue