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