Merge branch 'package-improve' of https://github.com/TonyCrane/manim into TonyCrane-package-improve

This commit is contained in:
Grant Sanderson 2021-02-07 20:05:20 -08:00
commit b374a07d76
13 changed files with 209 additions and 211 deletions

3
.gitignore vendored
View file

@ -147,5 +147,4 @@ dmypy.json
# For manim
/videos
/custom_config.yml
/manimlib/default_config.yml
/custom_config.yml

View file

@ -16,7 +16,7 @@ Note, there are two versions of manim. This repository began as a personal proj
Since the fork, this version has evolved to work on top of OpenGL, and allows real-time rendering to an interactive window before scenes are finalized and written to a file.
## Installation
Manim runs on Python 3.8.
Manim runs on Python 3.6 or higher (Python 3.8 is recommended).
System requirements are [FFmpeg](https://ffmpeg.org/), [OpenGL](https://www.opengl.org//), [LaTeX](https://www.latex-project.org) (optional, if you want to use LaTeX)
and [cairo](https://www.cairographics.org/) (optional, if you want to use Text).
@ -28,7 +28,7 @@ For more options, take a look at the [Using manim](#using-manim) sections furthe
If you want to hack on manimlib itself, clone this repository and in that directory execute:
```sh
# Install python requirements
# Install manimgl
pip install -e .
# Try it out
@ -61,20 +61,12 @@ manim-render example_scenes.py OpeningManimExample
manimgl example_scenes.py OpeningManimExample
```
## Anaconda Install
* Install latex as above.
* Create a conda environment using `conda env create -f environment.yml`
### Using `virtualenv` and `virtualenvwrapper`
After installing `virtualenv` and `virtualenvwrapper`
```sh
git clone https://github.com/3b1b/manim.git
mkvirtualenv -a manim -r requirements.txt manim
python -m manim example_scenes.py OpeningManimExample
```
* Install LaTeX as above.
* Create a conda environment using `conda create -n manim python=3.8`.
* Activate the environment using `conda activate manim`.
* Install manimgl using `pip install -e .`.
## Using manim

View file

@ -1,4 +1,4 @@
custom_default
custom_config
==============
``directories``
@ -18,12 +18,13 @@ custom_default
file and saved the last frame, then the final directory structure will be like:
.. code-block:: text
:emphasize-lines: 8, 10
:emphasize-lines: 9, 11
manim/
├── manimlib/
│ ├── animation/
│ ├── ...
│ ├── default_config.yml
│ └── window.py
├── output/
│ ├── images
@ -31,18 +32,18 @@ custom_default
│ └── videos
│ └── Scene1.mp4
├── code.py
├── custom_default.yml
└── manim.py
└── custom_config.yml
But if you set ``mirror_module_path`` to ``True``, the directory structure will be:
.. code-block:: text
:emphasize-lines: 7
:emphasize-lines: 8
manim/
├── manimlib/
│ ├── animation/
│ ├── ...
│ ├── default_config.yml
│ └── window.py
├── output/
│ └── code/
@ -51,8 +52,7 @@ custom_default
│ └── videos
│ └── Scene1.mp4
├── code.py
├── custom_default.yml
└── manim.py
└── custom_config.yml
- ``raster_images``
The directory for storing raster images to be used in the code (including

View file

@ -4,14 +4,16 @@ CLI flags and configuration
Command Line Interface
----------------------
To run manim, you need to enter the directory at the same level as ``manim.py``
To run manim, you need to enter the directory at the same level as ``manimlib/``
and enter the command in the following format into terminal:
.. code-block:: sh
python manim.py <code>.py <Scene> <flags>
manimgl <code>.py <Scene> <flags>
# or
manim-render <code>.py <Scene> <flags>
- ``<code>.py`` : The python file you wrote. Needs to be at the same level as ``manim.py``, otherwise you need to use an absolute path or a relative path.
- ``<code>.py`` : The python file you wrote. Needs to be at the same level as ``manimlib/``, otherwise you need to use an absolute path or a relative path.
- ``<Scene>`` : The scene you want to render here. If it is not written or written incorrectly, it will list all for you to choose. And if there is only one ``Scene`` in the file, this class will be rendered directly.
- ``<flags>`` : CLI flags.
@ -48,6 +50,7 @@ flag abbr function
``--write_all`` ``-a`` Write all the scenes from a file
``--open`` ``-o`` Automatically open the saved file once its done
``--finder`` Show the output file in finder
``--config`` Guide for automatic configuration
``--file_name FILE_NAME`` Name for the movie or image file
``--start_at_animation_number START_AT_ANIMATION_NUMBER`` ``-n`` Start rendering not from the first animation, but from another, specified by its index. If you passin two comma separated values, e.g. "3,6", it will end the rendering at the second value.
``--resolution RESOLUTION`` ``-r`` Resolution, passed as "WxH", e.g. "1920x1080"
@ -57,15 +60,15 @@ flag abbr function
``--video_dir VIDEO_DIR`` directory to write video
========================================================== ====== =================================================================================================================================================================================================
custom_default
custom_config
--------------
In order to perform more configuration (about directories, etc.) and permanently
change the default value (you don't have to add flags to the command every time),
you can modify ``custom_default.yml``. The meaning of each option is in
page :doc:`../documentation/custom_default`.
you can modify ``custom_config.yml``. The meaning of each option is in
page :doc:`../documentation/custom_config`.
You can also use different ``custom_default.yml`` for different directories, such as
You can also use different ``custom_config.yml`` for different directories, such as
following the directory structure:
.. code-block:: text
@ -74,13 +77,13 @@ following the directory structure:
├── manimlib/
│ ├── animation/
│ ├── ...
│ ├── default_config.yml
│ └── window.py
├── project/
│ ├── code.py
│ └── custom_default.yml
├── custom_default.yml
└── manim.py
│ └── custom_config.yml
└── custom_config.yml
When you enter the ``project/`` folder and run ``python ../manim.py code.py <Scene>``,
it will overwrite ``manim/custom_default.yml`` with ``custom_default.yml``
When you enter the ``project/`` folder and run ``manimgl code.py <Scene>``,
it will overwrite ``manim/custom_config.yml`` with ``custom_config.yml``
in the ``project`` folder.

View file

@ -11,7 +11,7 @@ SquareToCircle
.. manim-example:: SquareToCircle
:media: ../_static/example_scenes/SquareToCircle.mp4
from manimlib.imports import *
from manimlib import *
class SquareToCircle(Scene):
def construct(self):

View file

@ -55,15 +55,6 @@ For Anaconda
git clone https://github.com/3b1b/manim.git
cd manim
conda env create -f environment.yml
Using virtualenv and virtualenvwrapper
--------------------------------------
After installing ``virtualenv`` and ``virtualenvwrapper``
.. code-block:: sh
git clone https://github.com/3b1b/manim.git
mkvirtualenv -a manim -r requirements.txt manim
python -m manim example_scenes.py OpeningManimExample
conda create -n manim python=3.8
conda activate manim
pip install -e .

View file

@ -14,9 +14,9 @@ directory structure:
├── manimlib/
│ ├── animation/
│ ├── ...
│ ├── default_config.yml
│ └── window.py
├── custom_default.yml
├── manim.py
├── custom_config.yml
└── start.py
And paste the following code (I will explain the function of each line in detail later):
@ -24,7 +24,7 @@ And paste the following code (I will explain the function of each line in detail
.. code-block:: python
:linenos:
from manimlib.imports import *
from manimlib import *
class SquareToCircle(Scene):
def construct(self):
@ -38,7 +38,7 @@ And run this command:
.. code-block:: sh
python manim.py start.py SquareToCircle
manimgl start.py SquareToCircle
A window will pop up on the screen. And then you can :
@ -53,7 +53,7 @@ Run this command again:
.. code-block:: sh
python manim.py start.py SquareToCircle -os
manimgl 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
@ -71,7 +71,7 @@ Next, let's take a detailed look at what each row does.
.. code-block:: python
from manimlib.imports import *
from manimlib import *
This will import all the classes that may be used when using manim.
@ -129,7 +129,7 @@ Let's change some codes and add some animations to make videos instead of just p
.. code-block:: python
:linenos:
from manimlib.imports import *
from manimlib import *
class SquareToCircle(Scene):
def construct(self):
@ -147,14 +147,14 @@ Run this command this time:
.. code-block:: sh
python manim.py start.py SquareToCircle
manimgl 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
manimgl 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
@ -209,7 +209,7 @@ at the end of the code to enable interaction:
self.embed()
Then run ``python manim.py start.py SquareToCircle``.
Then run ``manimgl 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
@ -245,7 +245,7 @@ empty scene containing only ``self.embed()``, you can directly run the following
.. code-block:: sh
python manim.py
manimgl
You succeeded!
--------------

View file

@ -12,107 +12,105 @@ Below is the directory structure of manim:
.. code-block:: text
├── manim.py # Manim command entry
├── custom_default.yml # Default configuration
└── manimlib/ # manim library
├── __init__.py # run from here
├── config.py # Process CLI flags
├── constants.py # Defined some constants
├── extract_scene.py # Extract and run the scene
├── imports.py # Import all required files in manimlib
├── shader_wrapper.py # Shaders' Wrapper for convenient control
├── window.py # Playback window
├── tex_templates/ # Templates preset for LaTeX
│ ├── tex_templates.tex # Tex template (will be compiled with latex, default)
│ └── ctex_templates.tex # Tex template that support Chinese (will be compiled with xelatex)
├── camera/
│ └── camera.py # Including Camera and CameraFrame
├── scene/
│ ├── scene_file_writer.py # Used to write scene to video file
│ ├── scene.py # The basic Scene class
│ ├── three_d_scene.py # Three-dimensional scene
│ ├── graph_scene.py # GraphScene (with coordinate axis)
│ ├── reconfigurable_scene.py
│ ├── sample_space_scene.py # Probability related sample space scene
│ └── vector_space_scene.py # Vector field scene
├── animation/
│ ├── animation.py # The basic class of animation
│ ├── composition.py # Animation group
│ ├── creation.py # Animation related to Create
│ ├── fading.py # Fade related animation
│ ├── growing.py # Animation related to Grow
│ ├── indication.py # Some animations for emphasis
│ ├── movement.py # Animation related to movement
│ ├── numbers.py # Realize changes to DecimalNumber
│ ├── rotation.py # Animation related to rotation
│ ├── specialized.py # Some uncommon animations for special projects
│ ├── transform_matching_parts.py # Transform which can automatically match parts
│ ├── transform.py # Some Transforms
│ └── update.py # Realize update from function
├── mobject/
│ ├── mobject.py # The basic class of all math object
│ ├── types/ # 4 types of mobject
│ │ ├── dot_cloud.py # Dot cloud (an subclass of PMobject)
│ │ ├── image_mobject.py # Insert pictures
│ │ ├── point_cloud_mobject.py # PMobject (mobject composed of points)
│ │ ├── surface.py # ParametricSurface
│ │ └── vectorized_mobject.py # VMobject (vectorized mobject)
│ ├── svg/ # mobject related to svg
│ │ ├── svg_mobject.py # SVGMobject
│ │ ├── brace.py # Brace
│ │ ├── drawings.py # Some special mobject of svg image
│ │ ├── tex_mobject.py # Tex and TexText implemented by LaTeX
│ │ └── text_mobject.py # Text implemented by cairo
│ ├── changing.py # Dynamically changing mobject
│ ├── coordinate_systems.py # coordinate system
│ ├── frame.py # mobject related to frame
│ ├── functions.py # ParametricFunction
│ ├── geometry.py # geometry mobjects
│ ├── matrix.py # matrix
│ ├── mobject_update_utils.py # some defined updater
│ ├── number_line.py # Number line
│ ├── numbers.py # Numbers that can be changed
│ ├── probability.py # mobject related to probability
│ ├── shape_matchers.py # mobject adapted to the size of other objects
│ ├── three_dimensions.py # Three-dimensional objects
│ ├── value_tracker.py # ValueTracker which storage number
│ └── vector_field.py # VectorField
├── once_useful_constructs/ # 3b1b's Common scenes written for some videos
│ └── ...
├── shaders/ # GLSL scripts for rendering
│ ├── simple_vert.glsl # a simple glsl script for position
│ ├── insert/ # glsl scripts to be inserted in other glsl scripts
│ │ ├── NOTE.md # explain how to insert glsl scripts
│ │ └── ... # useful scripts
│ ├── image/ # glsl for images
│ │ └── ... # containing shaders for vertex and fragment
│ ├── quadratic_bezier_fill/ # glsl for the fill of quadratic bezier curve
│ │ └── ... # containing shaders for vertex, fragment and geometry
│ ├── quadratic_bezier_stroke/ # glsl for the stroke of quadratic bezier curve
│ │ └── ... # containing shaders for vertex, fragment and geometry
│ ├── surface/ # glsl for surfaces
│ │ └── ... # containing shaders for vertex and fragment
│ ├── textured_surface/ # glsl for textured_surface
│ │ └── ... # containing shaders for vertex and fragment
│ └── true_dot/ # glsl for a dot
│ └── ... # containing shaders for vertex, fragment and geometry
└── utils/ # Some useful utility functions
├── bezier.py # For bezier curve
├── color.py # For color
├── config_ops.py # Process CONFIG
├── customization.py # Read from custom_default.yml
├── debug.py # Utilities for debugging in program
├── family_ops.py # Process family members
├── file_ops.py # Process files and directories
├── images.py # Read image
├── iterables.py # Functions related to list/dictionary processing
├── paths.py # Curve path
├── rate_functions.py # Some defined rate_functions
├── simple_functions.py # Some commonly used functions
├── sounds.py # Process sounds
├── space_ops.py # Space coordinate calculation
├── strings.py # Process strings
└── tex_file_writing.py # Use LaTeX to write strings as svg
manimlib/ # manim library
├── __init__.py
├── __main__.py
├── default_config.yml # Default configuration file
├── config.py # Process CLI flags
├── constants.py # Defined some constants
├── extract_scene.py # Extract and run the scene
├── shader_wrapper.py # Shaders' Wrapper for convenient control
├── window.py # Playback window
├── tex_templates/ # Templates preset for LaTeX
│ ├── tex_templates.tex # Tex template (will be compiled with latex, default)
│ └── ctex_templates.tex # Tex template that support Chinese (will be compiled with xelatex)
├── camera/
│ └── camera.py # Including Camera and CameraFrame
├── scene/
│ ├── scene_file_writer.py # Used to write scene to video file
│ ├── scene.py # The basic Scene class
│ ├── three_d_scene.py # Three-dimensional scene
│ ├── sample_space_scene.py # Probability related sample space scene
│ └── vector_space_scene.py # Vector field scene
├── animation/
│ ├── animation.py # The basic class of animation
│ ├── composition.py # Animation group
│ ├── creation.py # Animation related to Create
│ ├── fading.py # Fade related animation
│ ├── growing.py # Animation related to Grow
│ ├── indication.py # Some animations for emphasis
│ ├── movement.py # Animation related to movement
│ ├── numbers.py # Realize changes to DecimalNumber
│ ├── rotation.py # Animation related to rotation
│ ├── specialized.py # Some uncommon animations for special projects
│ ├── transform_matching_parts.py # Transform which can automatically match parts
│ ├── transform.py # Some Transforms
│ └── update.py # Realize update from function
├── mobject/
│ ├── mobject.py # The basic class of all math object
│ ├── types/ # 4 types of mobject
│ │ ├── dot_cloud.py # Dot cloud (an subclass of PMobject)
│ │ ├── image_mobject.py # Insert pictures
│ │ ├── point_cloud_mobject.py # PMobject (mobject composed of points)
│ │ ├── surface.py # ParametricSurface
│ │ └── vectorized_mobject.py # VMobject (vectorized mobject)
│ ├── svg/ # mobject related to svg
│ │ ├── svg_mobject.py # SVGMobject
│ │ ├── brace.py # Brace
│ │ ├── drawings.py # Some special mobject of svg image
│ │ ├── tex_mobject.py # Tex and TexText implemented by LaTeX
│ │ └── text_mobject.py # Text implemented by cairo
│ ├── changing.py # Dynamically changing mobject
│ ├── coordinate_systems.py # coordinate system
│ ├── frame.py # mobject related to frame
│ ├── functions.py # ParametricFunction
│ ├── geometry.py # geometry mobjects
│ ├── matrix.py # matrix
│ ├── mobject_update_utils.py # some defined updater
│ ├── number_line.py # Number line
│ ├── numbers.py # Numbers that can be changed
│ ├── probability.py # mobject related to probability
│ ├── shape_matchers.py # mobject adapted to the size of other objects
│ ├── three_dimensions.py # Three-dimensional objects
│ ├── value_tracker.py # ValueTracker which storage number
│ └── vector_field.py # VectorField
├── once_useful_constructs/ # 3b1b's Common scenes written for some videos
│ └── ...
├── shaders/ # GLSL scripts for rendering
│ ├── simple_vert.glsl # a simple glsl script for position
│ ├── insert/ # glsl scripts to be inserted in other glsl scripts
│ │ ├── NOTE.md # explain how to insert glsl scripts
│ │ └── ... # useful scripts
│ ├── image/ # glsl for images
│ │ └── ... # containing shaders for vertex and fragment
│ ├── quadratic_bezier_fill/ # glsl for the fill of quadratic bezier curve
│ │ └── ... # containing shaders for vertex, fragment and geometry
│ ├── quadratic_bezier_stroke/ # glsl for the stroke of quadratic bezier curve
│ │ └── ... # containing shaders for vertex, fragment and geometry
│ ├── surface/ # glsl for surfaces
│ │ └── ... # containing shaders for vertex and fragment
│ ├── textured_surface/ # glsl for textured_surface
│ │ └── ... # containing shaders for vertex and fragment
│ └── true_dot/ # glsl for a dot
│ └── ... # containing shaders for vertex, fragment and geometry
└── utils/ # Some useful utility functions
├── bezier.py # For bezier curve
├── color.py # For color
├── config_ops.py # Process CONFIG
├── customization.py # Read from custom_config.yml
├── debug.py # Utilities for debugging in program
├── family_ops.py # Process family members
├── file_ops.py # Process files and directories
├── images.py # Read image
├── init_config.py # Configuration guide
├── iterables.py # Functions related to list/dictionary processing
├── paths.py # Curve path
├── rate_functions.py # Some defined rate_functions
├── simple_functions.py # Some commonly used functions
├── sounds.py # Process sounds
├── space_ops.py # Space coordinate calculation
├── strings.py # Process strings
└── tex_file_writing.py # Use LaTeX to write strings as svg
Inheritance structure of manim's classes
----------------------------------------

View file

@ -24,7 +24,7 @@ And here is a Chinese version of this documentation: https://manim.ml/shaders
:caption: Documentation
documentation/constants
documentation/custom_default
documentation/custom_config
.. toctree::
:maxdepth: 2

View file

@ -1,29 +0,0 @@
name: manim_shaders
channels:
- defaults
- conda-forge
dependencies:
- python=3.7
- pip
- pip:
- pyreadline
- matplotlib
- mapbox-earcut
- moderngl_window
- screeninfo
- argparse
- colour
- numpy
- Pillow
- progressbar
- scipy
- sympy
- tqdm
- moderngl
- pydub
- pyyaml
- validators
- ipython
- PyOpenGL
- pycairo

View file

@ -71,20 +71,3 @@ from manimlib.utils.simple_functions import *
from manimlib.utils.sounds import *
from manimlib.utils.space_ops import *
from manimlib.utils.strings import *
# Non manim libraries that are also nice to have without thinking
import inspect
import itertools as it
import numpy as np
import operator as op
import os
import random
import re
import string
import sys
import math
import sympy
from PIL import Image
from colour import Color

View file

@ -160,10 +160,6 @@ def get_custom_config():
filename = "custom_config.yml"
global_defaults_file = os.path.join(get_manim_dir(), "manimlib", "default_config.yml")
if not (os.path.exists(global_defaults_file) or os.path.exists(filename)):
print("There is no configuration file detected. Initial configuration:\n")
init_customization()
if os.path.exists(global_defaults_file):
with open(global_defaults_file, "r") as file:
config = yaml.safe_load(file)
@ -188,6 +184,15 @@ def get_custom_config():
def get_configuration(args):
local_config_file = "custom_config.yml"
global_defaults_file = os.path.join(get_manim_dir(), "manimlib", "default_config.yml")
if not (os.path.exists(global_defaults_file) or os.path.exists(local_config_file)):
print("There is no configuration file detected. Initial configuration:\n")
init_customization()
elif not os.path.exists(local_config_file):
print(f"""Warning: Using the default configuration file, which you can modify in {global_defaults_file}
If you want to create a local configuration file, you can create a file named {local_config_file}, or run manimgl --config
""")
custom_config = get_custom_config()
write_file = any([args.write_file, args.open, args.finder])

View file

@ -0,0 +1,56 @@
directories:
# Set this to true if you want the path to video files
# to match the directory structure of the path to the
# sourcecode generating that video
mirror_module_path: False
# Where should manim output video and image files?
output: ""
# If you want to use images, manim will look to these folders to find them
raster_images: ""
vector_images: ""
# If you want to use sounds, manim will look here to find it.
sounds: ""
# Manim often generates tex_files or other kinds of serialized data
# to keep from having to generate the same thing too many times. By
# default, these will be stored at tempfile.gettempdir(), e.g. this might
# return whatever is at to the TMPDIR environment variable. If you want to
# specify them elsewhere,
temporary_storage: ""
tex:
executable: "latex"
template_file: "tex_template.tex"
intermediate_filetype: "dvi"
text_to_replace: "[tex_expression]"
# For ctex, use the following configuration
# executable: "xelatex -no-pdf"
# template_file: "ctex_template.tex"
# intermediate_filetype: "xdv"
universal_import_line: "from manimlib.imports import *"
style:
font: "Consolas"
background_color: "#333333"
# Set the position of preview window, you can use directions, e.g. UL/DR/OL/OO/...
# also, you can also specify the position(pixel) of the upper left corner of
# the window on the monitor, e.g. "960,540"
window_position: UR
# If break_into_partial_movies is set to True, then many small
# files will be written corresponding to each Scene.play and
# Scene.wait call, and these files will then be combined
# to form the full scene. Sometimes video-editing is made
# easier when working with the broken up scene, which
# effectively has cuts at all the places you might want.
break_into_partial_movies: False
camera_qualities:
low:
resolution: "854x480"
frame_rate: 15
medium:
resolution: "1280x720"
frame_rate: 30
high:
resolution: "1920x1080"
frame_rate: 30
ultra_high:
resolution: "3840x2160"
frame_rate: 60
default_quality: "high"