Skip to content

Commit eeb4fdf

Browse files
authored
Merge pull request #2266 from 3b1b/video-work
Refactor config
2 parents bac0c0c + e2e785d commit eeb4fdf

28 files changed

+680
-810
lines changed

docs/source/documentation/constants.rst

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,35 @@ they are only used inside manim.
88
Frame and pixel shape
99
---------------------
1010

11+
These values will be determined based on the ``camera`` configuration in default_config.yml or custom_config.yml
12+
1113
.. code-block:: python
1214
13-
ASPECT_RATIO = 16.0 / 9.0
14-
FRAME_HEIGHT = 8.0
15-
FRAME_WIDTH = FRAME_HEIGHT * ASPECT_RATIO
16-
FRAME_Y_RADIUS = FRAME_HEIGHT / 2
17-
FRAME_X_RADIUS = FRAME_WIDTH / 2
15+
ASPECT_RATIO
16+
FRAME_HEIGHT
17+
FRAME_WIDTH
18+
FRAME_Y_RADIUS
19+
FRAME_X_RADIUS
1820
19-
DEFAULT_PIXEL_HEIGHT = 1080
20-
DEFAULT_PIXEL_WIDTH = 1920
21-
DEFAULT_FPS = 30
21+
DEFAULT_PIXEL_HEIGHT
22+
DEFAULT_PIXEL_WIDTH
23+
DEFAULT_FPS
2224
2325
Buffs
2426
-----
2527

26-
.. code-block:: python
27-
28-
SMALL_BUFF = 0.1
29-
MED_SMALL_BUFF = 0.25
30-
MED_LARGE_BUFF = 0.5
31-
LARGE_BUFF = 1
28+
These values will be determined based on the ``size`` configuration in default_config.yml or custom_config.yml
3229

33-
DEFAULT_MOBJECT_TO_EDGE_BUFFER = MED_LARGE_BUFF # Distance between object and edge
34-
DEFAULT_MOBJECT_TO_MOBJECT_BUFFER = MED_SMALL_BUFF # Distance between objects
35-
36-
Run times
37-
---------
3830

3931
.. code-block:: python
4032
41-
DEFAULT_POINTWISE_FUNCTION_RUN_TIME = 3.0
42-
DEFAULT_WAIT_TIME = 1.0
33+
SMALL_BUFF
34+
MED_SMALL_BUFF
35+
MED_LARGE_BUFF
36+
LARGE_BUFF
37+
38+
DEFAULT_MOBJECT_TO_EDGE_BUFF
39+
DEFAULT_MOBJECT_TO_MOBJECT_BUFF
4340
4441
Coordinates
4542
-----------
@@ -89,16 +86,11 @@ Text
8986
OBLIQUE = "OBLIQUE"
9087
BOLD = "BOLD"
9188
92-
Stroke width
93-
------------
94-
95-
.. code-block:: python
96-
97-
DEFAULT_STROKE_WIDTH = 4
98-
9989
Colours
10090
-------
10191

92+
Color constants are determined based on the ``color`` configuration in default_config.yml or custom_config.yml
93+
10294
Here are the preview of default colours. (Modified from
10395
`elteoremadebeethoven <https://elteoremadebeethoven.github.io/manim_3feb_docs.github.io/html/_static/colors/colors.html>`_)
10496

docs/source/documentation/custom_config.rst

Lines changed: 77 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ custom_config
99
running file under the ``output`` path, and save the output (``images/``
1010
or ``videos/``) in it.
1111

12+
- ``base``
13+
The root directory that will hold files, such as video files manim renders,
14+
or image resources that it pulls from
15+
1216
- ``output``
1317
Output file path, the videos will be saved in the ``videos/`` folder under it,
1418
and the pictures will be saved in the ``images/`` folder under it.
@@ -66,92 +70,107 @@ custom_config
6670
The directory for storing sound files to be used in ``Scene.add_sound()`` (
6771
including ``.wav`` and ``.mp3``).
6872

69-
- ``temporary_storage``
73+
- ``cache``
7074
The directory for storing temporarily generated cache files, including
7175
``Tex`` cache, ``Text`` cache and storage of object points.
7276

73-
``tex``
74-
-------
7577

76-
- ``executable``
77-
The executable program used to compile LaTeX (``latex`` or ``xelatex -no-pdf``
78-
is recommended)
78+
``window``
79+
----------
7980

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

83-
- ``intermediate_filetype``
84-
The type of intermediate vector file generated after compilation (``dvi`` if
85-
``latex`` is used, ``xdv`` if ``xelatex`` is used)
86-
87-
- ``text_to_replace``
88-
The text to be replaced in the template (needn't to change)
86+
- ``monitor_index``
87+
If using multiple monitors, which one should the window show up in?
8988

90-
``universal_import_line``
91-
-------------------------
89+
- ``full_screen``
90+
Should the preview window be full screen. If not, it defaults to half the screen
9291

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

95-
``style``
96-
---------
96+
- ``size``
97+
Option to more manually set the default window size, in pixel coordinates,
98+
e.g. (1920, 1080)
9799

98-
- ``font``
99-
Default font of Text
100100

101-
- ``text_alignment``
102-
Default text alignment for LaTeX
101+
``camera``
102+
----------
103103

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

107-
``window_position``
108-
-------------------
107+
- ``background_color``
108+
Default background color of scenes
109109

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

114-
``window_monitor``
115-
------------------
113+
- ``background_opacity``
114+
Opacity of the background
116115

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

119-
``full_screen``
117+
``file_writer``
120118
---------------
119+
Configuration specifying how files are written, e.g. what ffmpeg parameters to use
121120

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

124-
``break_into_partial_movies``
125-
-----------------------------
122+
``scene``
123+
-------
124+
Some default configuration for the Scene class
126125

127-
If this is set to ``True``, then many small files will be written corresponding
128-
to each ``Scene.play`` and ``Scene.wait`` call, and these files will then be combined
129-
to form the full scene.
130126

131-
Sometimes video-editing is made easier when working with the broken up scene, which
132-
effectively has cuts at all the places you might want.
127+
``text``
128+
-------
133129

134-
``camera_resolutions``
135-
----------------------
130+
- ``font``
131+
Default font of Text
136132

137-
Export resolutions
133+
- ``text_alignment``
134+
Default text alignment for LaTeX
138135

139-
- ``low``
140-
Low resolutions (default is 480p)
136+
``tex``
137+
-------
141138

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

145-
- ``high``
146-
High resolutions (default is 1080p)
147144

148-
- ``ultra_high``
149-
Ultra high resolutions (default is 4K)
145+
``sizes``
146+
---------
150147

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

154-
``fps``
155-
-------
156151

157-
Export frame rate. (default is 30)
152+
``colors``
153+
----------
154+
155+
Color pallete to use, determining values of color constants like RED, BLUE_E, TEAL, etc.
156+
157+
``loglevel``
158+
------------
159+
160+
Can be DEBUG / INFO / WARNING / ERROR / CRITICAL
161+
162+
163+
``universal_import_line``
164+
-------------------------
165+
166+
Import line that need to execute when entering interactive mode directly.
167+
168+
169+
``ignore_manimlib_modules_on_reload``
170+
-------------------------------------
171+
172+
When calling ``reload`` during the interactive mode, imported modules are
173+
by default reloaded, in case the user writing a scene which pulls from various
174+
other files they have written. By default, modules withinn the manim library will
175+
be ignored, but one developing manim may want to set this to be False so that
176+
edits to the library are reloaded as well.

docs/source/getting_started/structure.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ Below is the directory structure of manim:
103103
├── family_ops.py # Process family members
104104
├── file_ops.py # Process files and directories
105105
├── images.py # Read image
106-
├── init_config.py # Configuration guide
107106
├── iterables.py # Functions related to list/dictionary processing
108107
├── paths.py # Curve path
109108
├── rate_functions.py # Some defined rate_functions

manimlib/__main__.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
#!/usr/bin/env python
2+
from addict import Dict
3+
24
from manimlib import __version__
3-
import manimlib.config
4-
import manimlib.logger
5-
import manimlib.utils.init_config
6-
from manimlib.reload_manager import ReloadManager
5+
from manimlib.config import manim_config
6+
from manimlib.config import parse_cli
7+
import manimlib.extract_scene
8+
from manimlib.window import Window
9+
10+
11+
from IPython.terminal.embed import KillEmbedded
12+
13+
14+
from typing import TYPE_CHECKING
15+
if TYPE_CHECKING:
16+
from argparse import Namespace
17+
18+
19+
def run_scenes():
20+
"""
21+
Runs the scenes in a loop and detects when a scene reload is requested.
22+
"""
23+
# Create a new dict to be able to upate without
24+
# altering global configuration
25+
scene_config = Dict(manim_config.scene)
26+
run_config = manim_config.run
27+
28+
if run_config.show_in_window:
29+
# Create a reusable window
30+
window = Window(**manim_config.window)
31+
scene_config.update(window=window)
32+
33+
while True:
34+
try:
35+
# Blocking call since a scene may init an IPython shell()
36+
scenes = manimlib.extract_scene.main(scene_config, run_config)
37+
for scene in scenes:
38+
scene.run()
39+
return
40+
except KillEmbedded:
41+
# Requested via the `exit_raise` IPython runline magic
42+
# by means of the reload_scene() command
43+
pass
44+
except KeyboardInterrupt:
45+
break
746

847

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

15-
args = manimlib.config.parse_cli()
54+
args = parse_cli()
1655
if args.version and args.file is None:
1756
return
18-
if args.log_level:
19-
manimlib.logger.log.setLevel(args.log_level)
20-
21-
if args.config:
22-
manimlib.utils.init_config.init_customization()
23-
return
2457

25-
reload_manager = ReloadManager(args)
26-
reload_manager.run()
58+
run_scenes()
2759

2860

2961
if __name__ == "__main__":

manimlib/camera/camera.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from manimlib.camera.camera_frame import CameraFrame
99
from manimlib.constants import BLACK
10-
from manimlib.constants import DEFAULT_FPS
11-
from manimlib.constants import DEFAULT_PIXEL_HEIGHT, DEFAULT_PIXEL_WIDTH
10+
from manimlib.constants import DEFAULT_RESOLUTION
1211
from manimlib.constants import FRAME_HEIGHT
1312
from manimlib.constants import FRAME_WIDTH
1413
from manimlib.mobject.mobject import Mobject
@@ -29,10 +28,9 @@ def __init__(
2928
window: Optional[Window] = None,
3029
background_image: Optional[str] = None,
3130
frame_config: dict = dict(),
32-
pixel_width: int = DEFAULT_PIXEL_WIDTH,
33-
pixel_height: int = DEFAULT_PIXEL_HEIGHT,
34-
fps: int = DEFAULT_FPS,
35-
# Note: frame height and width will be resized to match the pixel aspect ratio
31+
# Note: frame height and width will be resized to match this resolution aspect ratio
32+
resolution=DEFAULT_RESOLUTION,
33+
fps: int = 30,
3634
background_color: ManimColor = BLACK,
3735
background_opacity: float = 1.0,
3836
# Points in vectorized mobjects with norm greater
@@ -47,9 +45,9 @@ def __init__(
4745
# to set samples to be greater than 0.
4846
samples: int = 0,
4947
):
50-
self.background_image = background_image
5148
self.window = window
52-
self.default_pixel_shape = (pixel_width, pixel_height)
49+
self.background_image = background_image
50+
self.default_pixel_shape = resolution # Rename?
5351
self.fps = fps
5452
self.max_allowable_norm = max_allowable_norm
5553
self.image_mode = image_mode

0 commit comments

Comments
 (0)