Skip to content

Commit

Permalink
Merge pull request #2266 from 3b1b/video-work
Browse files Browse the repository at this point in the history
Refactor config
  • Loading branch information
3b1b authored Dec 11, 2024
2 parents bac0c0c + e2e785d commit eeb4fdf
Show file tree
Hide file tree
Showing 28 changed files with 680 additions and 810 deletions.
48 changes: 20 additions & 28 deletions docs/source/documentation/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,35 @@ they are only used inside manim.
Frame and pixel shape
---------------------

These values will be determined based on the ``camera`` configuration in default_config.yml or custom_config.yml

.. code-block:: python
ASPECT_RATIO = 16.0 / 9.0
FRAME_HEIGHT = 8.0
FRAME_WIDTH = FRAME_HEIGHT * ASPECT_RATIO
FRAME_Y_RADIUS = FRAME_HEIGHT / 2
FRAME_X_RADIUS = FRAME_WIDTH / 2
ASPECT_RATIO
FRAME_HEIGHT
FRAME_WIDTH
FRAME_Y_RADIUS
FRAME_X_RADIUS
DEFAULT_PIXEL_HEIGHT = 1080
DEFAULT_PIXEL_WIDTH = 1920
DEFAULT_FPS = 30
DEFAULT_PIXEL_HEIGHT
DEFAULT_PIXEL_WIDTH
DEFAULT_FPS
Buffs
-----

.. code-block:: python
SMALL_BUFF = 0.1
MED_SMALL_BUFF = 0.25
MED_LARGE_BUFF = 0.5
LARGE_BUFF = 1
These values will be determined based on the ``size`` configuration in default_config.yml or custom_config.yml

DEFAULT_MOBJECT_TO_EDGE_BUFFER = MED_LARGE_BUFF # Distance between object and edge
DEFAULT_MOBJECT_TO_MOBJECT_BUFFER = MED_SMALL_BUFF # Distance between objects
Run times
---------

.. code-block:: python
DEFAULT_POINTWISE_FUNCTION_RUN_TIME = 3.0
DEFAULT_WAIT_TIME = 1.0
SMALL_BUFF
MED_SMALL_BUFF
MED_LARGE_BUFF
LARGE_BUFF
DEFAULT_MOBJECT_TO_EDGE_BUFF
DEFAULT_MOBJECT_TO_MOBJECT_BUFF
Coordinates
-----------
Expand Down Expand Up @@ -89,16 +86,11 @@ Text
OBLIQUE = "OBLIQUE"
BOLD = "BOLD"
Stroke width
------------

.. code-block:: python
DEFAULT_STROKE_WIDTH = 4
Colours
-------

Color constants are determined based on the ``color`` configuration in default_config.yml or custom_config.yml

Here are the preview of default colours. (Modified from
`elteoremadebeethoven <https://elteoremadebeethoven.github.io/manim_3feb_docs.github.io/html/_static/colors/colors.html>`_)

Expand Down
135 changes: 77 additions & 58 deletions docs/source/documentation/custom_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ custom_config
running file under the ``output`` path, and save the output (``images/``
or ``videos/``) in it.

- ``base``
The root directory that will hold files, such as video files manim renders,
or image resources that it pulls from

- ``output``
Output file path, the videos will be saved in the ``videos/`` folder under it,
and the pictures will be saved in the ``images/`` folder under it.
Expand Down Expand Up @@ -66,92 +70,107 @@ custom_config
The directory for storing sound files to be used in ``Scene.add_sound()`` (
including ``.wav`` and ``.mp3``).

- ``temporary_storage``
- ``cache``
The directory for storing temporarily generated cache files, including
``Tex`` cache, ``Text`` cache and storage of object points.

``tex``
-------

- ``executable``
The executable program used to compile LaTeX (``latex`` or ``xelatex -no-pdf``
is recommended)
``window``
----------

- ``template_file``
LaTeX template used, in ``manimlib/tex_templates``
- ``position_string``
The relative position of the playback window on the display (two characters,
the first character means upper(U) / middle(O) / lower(D), the second character
means left(L) / middle(O) / right(R)).

- ``intermediate_filetype``
The type of intermediate vector file generated after compilation (``dvi`` if
``latex`` is used, ``xdv`` if ``xelatex`` is used)

- ``text_to_replace``
The text to be replaced in the template (needn't to change)
- ``monitor_index``
If using multiple monitors, which one should the window show up in?

``universal_import_line``
-------------------------
- ``full_screen``
Should the preview window be full screen. If not, it defaults to half the screen

Import line that need to execute when entering interactive mode directly.
- ``position``
This is an option to more manually set the default window position, in pixel
coordinates, e.g. (500, 300)

``style``
---------
- ``size``
Option to more manually set the default window size, in pixel coordinates,
e.g. (1920, 1080)

- ``font``
Default font of Text

- ``text_alignment``
Default text alignment for LaTeX
``camera``
----------

- ``background_color``
Default background color
- ``resolution``
Resolution to render at, e.g. (1920, 1080)

``window_position``
-------------------
- ``background_color``
Default background color of scenes

The relative position of the playback window on the display (two characters,
the first character means upper(U) / middle(O) / lower(D), the second character
means left(L) / middle(O) / right(R)).
- ``fps``
Framerate

``window_monitor``
------------------
- ``background_opacity``
Opacity of the background

The number of the monitor you want the preview window to pop up on. (default is 0)

``full_screen``
``file_writer``
---------------
Configuration specifying how files are written, e.g. what ffmpeg parameters to use

Whether open the window in full screen. (default is false)

``break_into_partial_movies``
-----------------------------
``scene``
-------
Some default configuration for the Scene class

If this 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.
``text``
-------

``camera_resolutions``
----------------------
- ``font``
Default font of Text

Export resolutions
- ``text_alignment``
Default text alignment for LaTeX

- ``low``
Low resolutions (default is 480p)
``tex``
-------

- ``medium``
Medium resolutions (default is 720p)
- ``template``
Which configuration from the manimlib/tex_template.yml file should be used
to determine the latex compiler to use, and what preamble to include for
rendering tex.

- ``high``
High resolutions (default is 1080p)

- ``ultra_high``
Ultra high resolutions (default is 4K)
``sizes``
---------

- ``default_resolutions``
Default resolutions (one of the above four, default is high)
Valuess for various constants used in manimm to specify distances, like the height
of the frame, the value of SMALL_BUFF, LARGE_BUFF, etc.

``fps``
-------

Export frame rate. (default is 30)
``colors``
----------

Color pallete to use, determining values of color constants like RED, BLUE_E, TEAL, etc.

``loglevel``
------------

Can be DEBUG / INFO / WARNING / ERROR / CRITICAL


``universal_import_line``
-------------------------

Import line that need to execute when entering interactive mode directly.


``ignore_manimlib_modules_on_reload``
-------------------------------------

When calling ``reload`` during the interactive mode, imported modules are
by default reloaded, in case the user writing a scene which pulls from various
other files they have written. By default, modules withinn the manim library will
be ignored, but one developing manim may want to set this to be False so that
edits to the library are reloaded as well.
1 change: 0 additions & 1 deletion docs/source/getting_started/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ Below is the directory structure of manim:
├── 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
Expand Down
58 changes: 45 additions & 13 deletions manimlib/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
#!/usr/bin/env python
from addict import Dict

from manimlib import __version__
import manimlib.config
import manimlib.logger
import manimlib.utils.init_config
from manimlib.reload_manager import ReloadManager
from manimlib.config import manim_config
from manimlib.config import parse_cli
import manimlib.extract_scene
from manimlib.window import Window


from IPython.terminal.embed import KillEmbedded


from typing import TYPE_CHECKING
if TYPE_CHECKING:
from argparse import Namespace


def run_scenes():
"""
Runs the scenes in a loop and detects when a scene reload is requested.
"""
# Create a new dict to be able to upate without
# altering global configuration
scene_config = Dict(manim_config.scene)
run_config = manim_config.run

if run_config.show_in_window:
# Create a reusable window
window = Window(**manim_config.window)
scene_config.update(window=window)

while True:
try:
# Blocking call since a scene may init an IPython shell()
scenes = manimlib.extract_scene.main(scene_config, run_config)
for scene in scenes:
scene.run()
return
except KillEmbedded:
# Requested via the `exit_raise` IPython runline magic
# by means of the reload_scene() command
pass
except KeyboardInterrupt:
break


def main():
Expand All @@ -12,18 +51,11 @@ def main():
"""
print(f"ManimGL \033[32mv{__version__}\033[0m")

args = manimlib.config.parse_cli()
args = parse_cli()
if args.version and args.file is None:
return
if args.log_level:
manimlib.logger.log.setLevel(args.log_level)

if args.config:
manimlib.utils.init_config.init_customization()
return

reload_manager = ReloadManager(args)
reload_manager.run()
run_scenes()


if __name__ == "__main__":
Expand Down
14 changes: 6 additions & 8 deletions manimlib/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from manimlib.camera.camera_frame import CameraFrame
from manimlib.constants import BLACK
from manimlib.constants import DEFAULT_FPS
from manimlib.constants import DEFAULT_PIXEL_HEIGHT, DEFAULT_PIXEL_WIDTH
from manimlib.constants import DEFAULT_RESOLUTION
from manimlib.constants import FRAME_HEIGHT
from manimlib.constants import FRAME_WIDTH
from manimlib.mobject.mobject import Mobject
Expand All @@ -29,10 +28,9 @@ def __init__(
window: Optional[Window] = None,
background_image: Optional[str] = None,
frame_config: dict = dict(),
pixel_width: int = DEFAULT_PIXEL_WIDTH,
pixel_height: int = DEFAULT_PIXEL_HEIGHT,
fps: int = DEFAULT_FPS,
# Note: frame height and width will be resized to match the pixel aspect ratio
# Note: frame height and width will be resized to match this resolution aspect ratio
resolution=DEFAULT_RESOLUTION,
fps: int = 30,
background_color: ManimColor = BLACK,
background_opacity: float = 1.0,
# Points in vectorized mobjects with norm greater
Expand All @@ -47,9 +45,9 @@ def __init__(
# to set samples to be greater than 0.
samples: int = 0,
):
self.background_image = background_image
self.window = window
self.default_pixel_shape = (pixel_width, pixel_height)
self.background_image = background_image
self.default_pixel_shape = resolution # Rename?
self.fps = fps
self.max_allowable_norm = max_allowable_norm
self.image_mode = image_mode
Expand Down
Loading

0 comments on commit eeb4fdf

Please sign in to comment.