Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

remove all CONFIG and all digest_config (#783)

Aron68e66dccf5b4
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index b9228ce67..1a914d08a 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -282,17 +282,20 @@ Plotting with Manim
:ref_functions: GraphScene.setup_axes GraphScene.get_graph GraphScene.get_vertical_line_to_graph GraphScene.input_to_graph_point
class SinAndCosFunctionPlot(GraphScene):
- CONFIG = {
- "x_min": -10,
- "x_max": 10.3,
- "num_graph_anchor_points": 100,
- "y_min": -1.5,
- "y_max": 1.5,
- "graph_origin": ORIGIN,
- "function_color": RED,
- "axes_color": GREEN,
- "x_labeled_nums": range(-10, 12, 2),
- }
+ def __init__(self, **kwargs):
+ GraphScene.__init__(
+ self,
+ x_min=-10,
+ x_max=10.3,
+ num_graph_anchor_points=100,
+ y_min=-1.5,
+ y_max=1.5,
+ graph_origin=ORIGIN,
+ axes_color=GREEN,
+ x_labeled_nums=range(-10, 12, 2),
+ **kwargs
+ )
+ self.function_color = RED
def construct(self):
self.setup_axes(animate=False)
@@ -313,15 +316,16 @@ Plotting with Manim
:ref_functions: GraphScene.setup_axes GraphScene.get_graph GraphScene.get_vertical_line_to_graph GraphScene.get_area
class GraphAreaPlot(GraphScene):
- CONFIG = {
- "x_min" : 0,
- "x_max" : 5,
- "y_min" : 0,
- "y_max" : 6,
- "y_tick_frequency" : 1,
- "x_tick_frequency" : 1,
- "x_labeled_nums" : [0,2,3]
- }
+ def __init__(self, **kwargs):
+ GraphScene.__init__(
+ self,
+ x_min=0,
+ x_max=5,
+ y_min=0,
+ y_max=6,
+ x_labeled_nums=[0,2,3],
+ **kwargs)
+
def construct(self):
self.setup_axes()
curve1 = self.get_graph(lambda x: 4 * x - x ** 2, x_min=0, x_max=4)
@@ -338,16 +342,18 @@ Plotting with Manim
:ref_functions: GraphScene.setup_axes GraphScene.coords_to_point
class HeatDiagramPlot(GraphScene):
- CONFIG = {
- "y_axis_label": r"T[$^\circ C$]",
- "x_axis_label": r"$\Delta Q$",
- "y_min": -8,
- "y_max": 30,
- "x_min": 0,
- "x_max": 40,
- "y_labeled_nums": np.arange(-5, 34, 5),
- "x_labeled_nums": np.arange(0, 40, 5),
- }
+ def __init__(self, **kwargs):
+ GraphScene.__init__(
+ self,
+ y_axis_label=r"T[$^\circ C$]",
+ x_axis_label=r"$\Delta Q$",
+ y_min=-8,
+ y_max=30,
+ x_min=0,
+ x_max=40,
+ y_labeled_nums=np.arange(-5, 34, 5),
+ x_labeled_nums=np.arange(0, 40, 5),
+ **kwargs)
def construct(self):
data = [20, 0, 0, -5]
@@ -407,15 +413,18 @@ Special Camera Settings
class MovingZoomedSceneAround(ZoomedScene):
# contributed by TheoremofBeethoven, www.youtube.com/c/TheoremofBeethoven
- CONFIG = {
- "zoom_factor": 0.3,
- "zoomed_display_height": 1,
- "zoomed_display_width": 6,
- "image_frame_stroke_width": 20,
- "zoomed_camera_config": {
- "default_frame_stroke_width": 3,
- },
- }
+ def __init__(self, **kwargs):
+ ZoomedScene.__init__(
+ self,
+ zoom_factor=0.3,
+ zoomed_display_height=1,
+ zoomed_display_width=6,
+ image_frame_stroke_width=20,
+ zoomed_camera_config={
+ "default_frame_stroke_width": 3,
+ },
+ **kwargs
+ )
def construct(self):
dot = Dot().shift(UL * 2)
diff --git a/manim/animation/animation.py b/manim/animation/animation.py
index 5fdd333af..005dcc494 100644
--- a/manim/animation/animation.py
+++ b/manim/animation/animation.py
@@ -10,7 +10,7 @@ import numpy as np
from .. import logger
from ..mobject.mobject import Mobject
-from ..utils.config_ops import digest_config
+
from ..utils.rate_functions import smooth
@@ -18,26 +18,45 @@ DEFAULT_ANIMATION_RUN_TIME = 1.0
DEFAULT_ANIMATION_LAG_RATIO = 0
-class Animation(object):
- CONFIG = {
- "run_time": DEFAULT_ANIMATION_RUN_TIME,
- "rate_func": smooth,
- "name": None,
- # Does this animation add or remove a mobject form the screen
- "remover": False,
- # If 0, the animation is applied to all submobjects
+class Animation:
+ def __init__(
+ self,
+ mobject,
+ # If lag_ratio is 0, the animation is applied to all submobjects
# at the same time
# If 1, it is applied to each successively.
# If 0 < lag_ratio < 1, its applied to each
# with lagged start times
- "lag_ratio": DEFAULT_ANIMATION_LAG_RATIO,
- "suspend_mobject_updating": True,
- }
-
- def __init__(self, mobject, **kwargs):
- assert isinstance(mobject, Mobject)
- digest_config(self, kwargs)
+ lag_ratio=DEFAULT_ANIMATION_LAG_RATIO,
+ run_time=DEFAULT_ANIMATION_RUN_TIME,
+ rate_func=smooth,
+ name=None,
+ remover=False, # remove a mobject from the screen?
+ suspend_mobject_updating=True,
+ **kwargs
+ ):
+ self._typecheck_input(mobject)
+ self.run_time = run_time
+ self.rate_func = rate_func
+ self.name = name
+ self.remover = remover
+ self.suspend_mobject_updating = suspend_mobject_updating
+ self.lag_ratio = lag_ratio
+ self.starting_mobject = None
self.mobject = mobject
+ if kwargs:
+ logger.debug("Animation received extra kwargs: %s", kwargs)
+
+ if hasattr(self, "CONFIG"):
+ logger.error(
+ "CONFIG has been removed from ManimCommunity. Please use keyword arguments instead."
+ )
+
+ def _typecheck_input(self, mobject):
+ if mobject is None:
+ logger.warning("creating dummy animation")
+ elif not isinstance(mobject, Mobject):
+ raise TypeError("Animation only works on Mobjects")
def __str__(self):
if self.name:
@@ -105,7 +124,7 @@ class Animation(object):
return deepcopy(self)
def update_config(self, **kwargs):
- digest_config(self, kwargs)
+ self.__dict__.update(kwargs)
return self
# Methods for interpolation, the mean of an Animation
@@ -168,10 +187,11 @@ class Animation(object):
class Wait(Animation):
- def __init__(self, stop_condition=None, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, duration=1, stop_condition=None, **kwargs):
+ self.duration = duration
self.mobject = None
self.stop_condition = stop_condition
+ super().__init__(None, **kwargs)
def begin(self):
pass
diff --git a/manim/animation/composition.py b/manim/animation/composition.py
index a96b28eda..5cccf6e27 100644
--- a/manim/animation/composition.py
+++ b/manim/animation/composition.py
@@ -4,7 +4,6 @@ import numpy as np
from ..animation.animation import Animation
from ..mobject.mobject import Group
from ..utils.bezier import interpolate
-from ..utils.config_ops import digest_config
from ..utils.iterables import remove_list_redundancies
from ..utils.rate_functions import linear
@@ -15,28 +14,24 @@ DEFAULT_LAGGED_START_LAG_RATIO = 0.05
class AnimationGroup(Animation):
- CONFIG = {
- # If None, this defaults to the sum of all
- # internal animations
- "run_time": None,
- "rate_func": linear,
- # If 0, all animations are played at once.
- # If 1, all are played successively.
- # If >0 and <1, they start at lagged times
- # from one and other.
- "lag_ratio": 0,
- "group": None,
- }
-
- def __init__(self, *animations, **kwargs):
- digest_config(self, kwargs)
+ def __init__(
+ self,
+ *animations,
+ group=None,
+ run_time=None,
+ rate_func=linear,
+ lag_ratio=0,
+ **kwargs
+ ):
self.animations = animations
+ self.group = group
if self.group is None:
self.group = Group(
*remove_list_redundancies([anim.mobject for anim in animations])
)
+ super().__init__(self.group, rate_func=rate_func, lag_ratio=lag_ratio, **kwargs)
+ self.run_time = run_time
self.init_run_time()
- Animation.__init__(self, self.group, **kwargs)
def get_all_mobjects(self):
return self.group
@@ -68,8 +63,7 @@ class AnimationGroup(Animation):
self.max_end_time = np.max([awt[2] for awt in self.anims_with_timings])
else:
self.max_end_time = 0
- if self.run_time is None:
- self.run_time = self.max_end_time
+ self.run_time = self.max_end_time if self.run_time is None else self.run_time
def build_animations_with_timings(self):
"""
@@ -103,9 +97,8 @@ class AnimationGroup(Animation):
class Succession(AnimationGroup):
- CONFIG = {
- "lag_ratio": 1,
- }
+ def __init__(self, *animations, lag_ratio=1, **kwargs):
+ super().__init__(*animations, lag_ratio=lag_ratio, **kwargs)
def begin(self):
assert len(self.animations) > 0
@@ -148,17 +141,12 @@ class Succession(AnimationGroup):
class LaggedStart(AnimationGroup):
- CONFIG = {
- "lag_ratio": DEFAULT_LAGGED_START_LAG_RATIO,
- }
+ def __init__(self, *animations, lag_ratio=DEFAULT_LAGGED_START_LAG_RATIO, **kwargs):
+ super().__init__(*animations, lag_ratio=lag_ratio, **kwargs)
class LaggedStartMap(LaggedStart):
- CONFIG = {
- "run_time": 2,
- }
-
- def __init__(self, AnimationClass, mobject, arg_creator=None, **kwargs):
+ def __init__(self, AnimationClass, mobject, arg_creator=None, run_time=2, **kwargs):
args_list = []
for submob in mobject:
if arg_creator:
@@ -169,4 +157,4 @@ class LaggedStartMap(LaggedStart):
if "lag_ratio" in anim_kwargs:
anim_kwargs.pop("lag_ratio")
animations = [AnimationClass(*args, **anim_kwargs) for args in args_list]
- super().__init__(*animations, **kwargs)
+ super().__init__(*animations, run_time=run_time, **kwargs)
diff --git a/manim/animation/creation.py b/manim/animation/creation.py
index 96ad38b20..f8bc9e182 100644
--- a/manim/animation/creation.py
+++ b/manim/animation/creation.py
@@ -19,7 +19,6 @@ from ..animation.composition import Succession
from ..mobject.types.vectorized_mobject import VMobject
from ..mobject.mobject import Group
from ..utils.bezier import integer_interpolate
-from ..utils.config_ops import digest_config
from ..utils.rate_functions import linear
from ..utils.rate_functions import double_smooth
from ..utils.rate_functions import smooth
@@ -72,33 +71,41 @@ class ShowCreation(ShowPartial):
"""
- CONFIG = {
- "lag_ratio": 1,
- }
+ def __init__(self, mobject, lag_ratio=1, **kwargs):
+ super().__init__(mobject, lag_ratio=lag_ratio, **kwargs)
def get_bounds(self, alpha):
return (0, alpha)
class Uncreate(ShowCreation):
- CONFIG = {"rate_func": lambda t: smooth(1 - t), "remover": True}
+ def __init__(
+ self, mobject, rate_func=lambda t: smooth(1 - t), remover=True, **kwargs
+ ):
+ super().__init__(mobject, rate_func=rate_func, remover=remover, **kwargs)
class DrawBorderThenFill(Animation):
- CONFIG = {
- "run_time": 2,
- "rate_func": double_smooth,
- "stroke_width": 2,
- "stroke_color": None,
- "draw_border_animation_config": {},
- "fill_animation_config": {},
- }
-
- def __init__(self, vmobject, **kwargs):
- self.check_validity_of_input(vmobject)
- super().__init__(vmobject, **kwargs)
-
- def check_validity_of_input(self, vmobject):
+ def __init__(
+ self,
+ vmobject,
+ run_time=2,
+ rate_func=double_smooth,
+ stroke_width=2,
+ stroke_color=None,
+ draw_border_animation_config={},
+ fill_animation_config={},
+ **kwargs
+ ):
+ self._typecheck_input(vmobject)
+ super().__init__(vmobject, run_time=run_time, rate_func=rate_func, **kwargs)
+ self.stroke_width = stroke_width
+ self.stroke_color = stroke_color
+ self.draw_border_animation_config = draw_border_animation_config
+ self.fill_animation_config = fill_animation_config
+ self.outline = None
+
+ def _typecheck_input(self, vmobject):
if not isinstance(vmobject, VMobject):
raise TypeError("DrawBorderThenFill only works for VMobjects")
@@ -133,21 +140,22 @@ class DrawBorderThenFill(Animation):
class Write(DrawBorderThenFill):
- CONFIG = {
- # To be figured out in
- # set_default_config_from_lengths
- "run_time": None,
- "lag_ratio": None,
- "rate_func": linear,
- }
-
- def __init__(self, mobject, **kwargs):
- digest_config(self, kwargs)
- self.set_default_config_from_length(mobject)
- super().__init__(mobject, **kwargs)
+ def __init__(
+ self, vmobject, run_time=None, lag_ratio=None, rate_func=linear, **kwargs
+ ):
+ self.run_time = run_time
+ self.lag_ratio = lag_ratio
+ self._set_default_config_from_length(vmobject)
+ super().__init__(
+ vmobject,
+ run_time=self.run_time,
+ lag_ratio=self.lag_ratio,
+ rate_func=rate_func,
+ **kwargs,
+ )
- def set_default_config_from_length(self, mobject):
- length = len(mobject.family_members_with_points())
+ def _set_default_config_from_length(self, vmobject):
+ length = len(vmobject.family_members_with_points())
if self.run_time is None:
if length < 15:
self.run_time = 1
@@ -158,14 +166,14 @@ class Write(DrawBorderThenFill):
class ShowIncreasingSubsets(Animation):
- CONFIG = {
- "suspend_mobject_updating": False,
- "int_func": np.floor,
- }
-
- def __init__(self, group, **kwargs):
+ def __init__(
+ self, group, suspend_mobject_updating=False, int_func=np.floor, **kwargs
+ ):
self.all_submobs = list(group.submobjects)
- super().__init__(group, **kwargs)
+ self.int_func = int_func
+ super().__init__(
+ group, suspend_mobject_updating=suspend_mobject_updating, **kwargs
+ )
def interpolate_mobject(self, alpha):
n_submobs = len(self.all_submobs)
@@ -181,33 +189,38 @@ class AddTextLetterByLetter(ShowIncreasingSubsets):
Add a Text Object letter by letter on the scene. Use time_per_char to change frequency of appearance of the letters.
"""
- CONFIG = {
- "suspend_mobject_updating": False,
- "int_func": np.ceil,
- "rate_func": linear,
- "time_per_char": 0.1,
- }
-
- def __init__(self, text, **kwargs):
- digest_config(self, kwargs)
-
- self.run_time = np.max((0.06, self.time_per_char)) * len(
- text
- ) # Time_per_char must be above 0.06. Otherwise the animation doesn't finish.
- super().__init__(text, **kwargs)
+ def __init__(
+ self,
+ text,
+ suspend_mobject_updating=False,
+ int_func=np.ceil,
+ rate_func=linear,
+ time_per_char=0.1,
+ run_time=None,
+ **kwargs
+ ):
+ # time_per_char must be above 0.06, or the animation won't finish
+ self.time_per_char = time_per_char
+ self.run_time = run_time
+ if self.run_time is None:
+ self.run_time = np.max((0.06, self.time_per_char)) * len(text)
+
+ super().__init__(
+ text,
+ suspend_mobject_updating=suspend_mobject_updating,
+ int_func=int_func,
+ rate_func=rate_func,
+ run_time=self.run_time,
+ **kwargs,
+ )
class ShowSubmobjectsOneByOne(ShowIncreasingSubsets):
- CONFIG = {
- "int_func": np.ceil,
- }
-
- def __init__(self, group, **kwargs):
+ def __init__(self, group, int_func=np.ceil, **kwargs):
new_group = Group(*group)
- super().__init__(new_group, **kwargs)
+ super().__init__(new_group, int_func=int_func, **kwargs)
def update_submobject_list(self, index):
- # N = len(self.all_submobs)
if index == 0:
self.mobject.submobjects = []
else:
@@ -216,15 +229,8 @@ class ShowSubmobjectsOneByOne(ShowIncreasingSubsets):
# TODO, this is broken...
class AddTextWordByWord(Succession):
- CONFIG = {
- # If given a value for run_time, it will
- # override the time_per_char
- "run_time": None,
- "time_per_char": 0.06,
- }
-
- def __init__(self, text_mobject, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, text_mobject, run_time=None, time_per_char=0.06, **kwargs):
+ self.time_per_char = time_per_char
tpc = self.time_per_char
anims = it.chain(
*[
diff --git a/manim/animation/fading.py b/manim/animation/fading.py
index 7d8694ed1..66fbb1d4f 100644
--- a/manim/animation/fading.py
+++ b/manim/animation/fading.py
@@ -17,7 +17,6 @@ __all__ = [
from ..animation.animation import Animation
-from ..animation.animation import DEFAULT_ANIMATION_LAG_RATIO
from ..animation.transform import Transform
from ..constants import DOWN
from ..mobject.types.vectorized_mobject import VMobject
@@ -55,10 +54,10 @@ class FadeOut(Transform):
"""
- CONFIG = {
- "remover": True,
- "lag_ratio": DEFAULT_FADE_LAG_RATIO,
- }
+ def __init__(
+ self, vmobject, remover=True, lag_ratio=DEFAULT_FADE_LAG_RATIO, **kwargs
+ ):
+ super().__init__(vmobject, remover=remover, lag_ratio=lag_ratio, **kwargs)
def create_target(self):
return self.mobject.copy().fade(1)
@@ -69,9 +68,8 @@ class FadeOut(Transform):
class FadeIn(Transform):
- CONFIG = {
- "lag_ratio": DEFAULT_FADE_LAG_RATIO,
- }
+ def __init__(self, vmobject, lag_ratio=DEFAULT_FADE_LAG_RATIO, **kwargs):
+ super().__init__(vmobject, lag_ratio=lag_ratio, **kwargs)
def create_target(self):
return self.mobject
@@ -86,14 +84,8 @@ class FadeIn(Transform):
class FadeInFrom(Transform):
- CONFIG = {
- "direction": DOWN,
- "lag_ratio": DEFAULT_ANIMATION_LAG_RATIO,
- }
-
- def __init__(self, mobject, direction=None, **kwargs):
- if direction is not None:
- self.direction = direction
+ def __init__(self, mobject, direction=DOWN, **kwargs):
+ self.direction = direction
super().__init__(mobject, **kwargs)
def create_target(self):
@@ -111,26 +103,16 @@ class FadeInFromDown(FadeInFrom):
communicates the default
"""
- CONFIG = {
- "direction": DOWN,
- "lag_ratio": DEFAULT_ANIMATION_LAG_RATIO,
- }
-
- def __init__(self, mobject, **kwargs):
- super().__init__(mobject, direction=DOWN, **kwargs)
+ def __init__(self, mobject, direction=DOWN, **kwargs):
+ super().__init__(mobject, direction=direction, **kwargs)
logger.warning(
"FadeInFromDown is deprecated and will eventually disappear. Please use FadeInFrom(<mobject>, direction=DOWN, <other_args>) instead."
)
class FadeOutAndShift(FadeOut):
- CONFIG = {
- "direction": DOWN,
- }
-
- def __init__(self, mobject, direction=None, **kwargs):
- if direction is not None:
- self.direction = direction
+ def __init__(self, mobject, direction=DOWN, **kwargs):
+ self.direction = direction
super().__init__(mobject, **kwargs)
def create_target(self):
@@ -145,12 +127,8 @@ class FadeOutAndShiftDown(FadeOutAndShift):
communicates the default
"""
- CONFIG = {
- "direction": DOWN,
- }
-
- def __init__(self, mobject, **kwargs):
- super().__init__(mobject, direction=DOWN, **kwargs)
+ def __init__(self, mobject, direction=DOWN, **kwargs):
+ super().__init__(mobject, direction=direction, **kwargs)
logger.warning(
"FadeOutAndShiftDown is deprecated and will eventually disappear. Please use FadeOutAndShift(<mobject>, direction=DOWN, <other_args>) instead."
)
@@ -169,13 +147,8 @@ class FadeInFromPoint(FadeIn):
class FadeInFromLarge(FadeIn):
- CONFIG = {
- "scale_factor": 2,
- }
-
def __init__(self, mobject, scale_factor=2, **kwargs):
- if scale_factor is not None:
- self.scale_factor = scale_factor
+ self.scale_factor = scale_factor
super().__init__(mobject, **kwargs)
def create_starting_mobject(self):
@@ -189,9 +162,10 @@ class VFadeIn(Animation):
VFadeIn and VFadeOut only work for VMobjects,
"""
- CONFIG = {
- "suspend_mobject_updating": False,
- }
+ def __init__(self, mobject, suspend_mobject_updating=False, **kwargs):
+ super().__init__(
+ mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs
+ )
def interpolate_submobject(self, submob, start, alpha):
submob.set_stroke(opacity=interpolate(0, start.get_stroke_opacity(), alpha))
@@ -199,14 +173,13 @@ class VFadeIn(Animation):
class VFadeOut(VFadeIn):
- CONFIG = {"remover": True}
+ def __init__(self, mobject, remover=True, **kwargs):
+ super().__init__(mobject, remover=remover, **kwargs)
def interpolate_submobject(self, submob, start, alpha):
super().interpolate_submobject(submob, start, 1 - alpha)
class VFadeInThenOut(VFadeIn):
- CONFIG = {
- "rate_func": there_and_back,
- "remover": True,
- }
+ def __init__(self, mobject, remover=True, rate_func=there_and_back, **kwargs):
+ super().__init__(mobject, remover=remover, rate_func=rate_func, **kwargs)
diff --git a/manim/animation/growing.py b/manim/animation/growing.py
index 62fbee89e..f1fb54b4a 100644
--- a/manim/animation/growing.py
+++ b/manim/animation/growing.py
@@ -14,12 +14,9 @@ from ..constants import PI
class GrowFromPoint(Transform):
- CONFIG = {
- "point_color": None,
- }
-
- def __init__(self, mobject, point, **kwargs):
+ def __init__(self, mobject, point, point_color=None, **kwargs):
self.point = point
+ self.point_color = point_color
super().__init__(mobject, **kwargs)
def create_target(self):
@@ -35,9 +32,9 @@ class GrowFromPoint(Transform):
class GrowFromCenter(GrowFromPoint):
- def __init__(self, mobject, **kwargs):
+ def __init__(self, mobject, point_color=None, **kwargs):
point = mobject.get_center()
- super().__init__(mobject, point, **kwargs)
+ super().__init__(mobject, point, point_color=point_color, **kwargs)
class GrowFromEdge(GrowFromPoint):
@@ -53,6 +50,5 @@ class GrowArrow(GrowFromPoint):
class SpinInFromNothing(GrowFromCenter):
- CONFIG = {
- "path_arc": PI,
- }
+ def __init__(self, mobject, path_arc=PI, **kwargs):
+ super().__init__(mobject, path_arc=path_arc, **kwargs)
diff --git a/manim/animation/indication.py b/manim/animation/indication.py
index b92c45a8e..ba6a3629a 100644
--- a/manim/animation/indication.py
+++ b/manim/animation/indication.py
@@ -37,25 +37,21 @@ from ..mobject.shape_matchers import SurroundingRectangle
from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.geometry import Line
from ..utils.bezier import interpolate
-from ..utils.config_ops import digest_config
from ..utils.rate_functions import there_and_back
from ..utils.rate_functions import wiggle
from ..utils.color import GREY, YELLOW
class FocusOn(Transform):
- CONFIG = {
- "opacity": 0.2,
- "color": GREY,
- "run_time": 2,
- "remover": True,
- }
-
- def __init__(self, focus_point, **kwargs):
+ def __init__(
+ self, focus_point, opacity=0.2, color=GREY, run_time=2, remover=True, **kwargs
+ ):
self.focus_point = focus_point
+ self.color = color
+ self.opacity = opacity
# Initialize with blank mobject, while create_target
# and create_starting_mobject handle the meat
- super().__init__(VMobject(), **kwargs)
+ super().__init__(VMobject(), run_time=run_time, remover=remover, **kwargs)
def create_target(self):
little_dot = Dot(radius=0)
@@ -73,11 +69,17 @@ class FocusOn(Transform):
class Indicate(Transform):
- CONFIG = {
- "rate_func": there_and_back,
- "scale_factor": 1.2,
- "color": YELLOW,
- }
+ def __init__(
+ self,
+ mobject,
+ scale_factor=1.2,
+ color=YELLOW,
+ rate_func=there_and_back,
+ **kwargs
+ ):
+ self.color = color
+ self.scale_factor = scale_factor
+ super().__init__(mobject, rate_func=rate_func, **kwargs)
def create_target(self):
target = self.mobject.copy()
@@ -87,23 +89,30 @@ class Indicate(Transform):
class Flash(AnimationGroup):
- CONFIG = {
- "line_length": 0.2,
- "num_lines": 12,
- "flash_radius": 0.3,
- "line_stroke_width": 3,
- "run_time": 1,
- }
-
- def __init__(self, point, color=YELLOW, **kwargs):
+ def __init__(
+ self,
+ point,
+ line_length=0.2,
+ num_lines=12,
+ flash_radius=0.3,
+ line_stroke_width=3,
+ color=YELLOW,
+ run_time=1,
+ **kwargs
+ ):
self.point = point
self.color = color
- digest_config(self, kwargs)
+ self.line_length = line_length
+ self.num_lines = num_lines
+ self.flash_radius = flash_radius
+ self.line_stroke_width = line_stroke_width
+
self.lines = self.create_lines()
animations = self.create_line_anims()
super().__init__(
*animations,
group=self.lines,
+ run_time=run_time,
**kwargs,
)
@@ -124,18 +133,17 @@ class Flash(AnimationGroup):
class CircleIndicate(Indicate):
- CONFIG = {
- "rate_func": there_and_back,
- "remover": True,
- "circle_config": {
- "color": YELLOW,
- },
- }
-
- def __init__(self, mobject, **kwargs):
- digest_config(self, kwargs)
+ def __init__(
+ self,
+ mobject,
+ circle_config={"color": YELLOW},
+ rate_func=there_and_back,
+ remover=True,
+ **kwargs
+ ):
+ self.circle_config = circle_config
circle = self.get_circle(mobject)
- super().__init__(circle, **kwargs)
+ super().__init__(circle, rate_func=rate_func, remover=remover, **kwargs)
def get_circle(self, mobject):
circle = Circle(**self.circle_config)
@@ -165,10 +173,9 @@ class ShowPassingFlash(ShowPartial):
"""
- CONFIG = {
- "time_width": 0.1,
- "remover": True,
- }
+ def __init__(self, mobject, time_width=0.1, remover=True, **kwargs):
+ self.time_width = time_width
+ super().__init__(mobject, remover=remover, **kwargs)
def get_bounds(self, alpha):
tw = self.time_width
@@ -185,34 +192,29 @@ class ShowPassingFlash(ShowPartial):
class ShowCreationThenDestruction(ShowPassingFlash):
- CONFIG = {
- "time_width": 2.0,
- "run_time": 1,
- }
+ def __init__(self, mobject, time_width=2.0, run_time=1, **kwargs):
+ super().__init__(mobject, time_width=time_width, run_time=run_time, **kwargs)
class ShowCreationThenFadeOut(Succession):
- CONFIG = {
- "remover": True,
- }
-
- def __init__(self, mobject, **kwargs):
- super().__init__(ShowCreation(mobject), FadeOut(mobject), **kwargs)
+ def __init__(self, mobject, remover=True, **kwargs):
+ super().__init__(
+ ShowCreation(mobject), FadeOut(mobject), remover=remover, **kwargs
+ )
class AnimationOnSurroundingRectangle(AnimationGroup):
- CONFIG = {
- "surrounding_rectangle_config": {},
- # Function which takes in a rectangle, and spits
- # out some animation. Could be some animation class,
- # could be something more
- "rect_animation": Animation,
- }
-
- def __init__(self, mobject, **kwargs):
- digest_config(self, kwargs)
- if "surrounding_rectangle_config" in kwargs:
- kwargs.pop("surrounding_rectangle_config")
+ def __init__(
+ self,
+ mobject,
+ rect_animation=Animation,
+ surrounding_rectangle_config={},
+ **kwargs
+ ):
+ # Callable which takes in a rectangle, and spits out some animation. Could be
+ # some animation class, could be something more
+ self.rect_animation = rect_animation
+ self.surrounding_rectangle_config = surrounding_rectangle_config
self.mobject_to_surround = mobject
rect = self.get_rect()
@@ -229,26 +231,24 @@ class AnimationOnSurroundingRectangle(AnimationGroup):
class ShowPassingFlashAround(AnimationOnSurroundingRectangle):
- CONFIG = {"rect_animation": ShowPassingFlash}
+ def __init__(self, mobject, rect_animation=ShowPassingFlash, **kwargs):
+ super().__init__(mobject, rect_animation=rect_animation, **kwargs)
class ShowCreationThenDestructionAround(AnimationOnSurroundingRectangle):
- CONFIG = {"rect_animation": ShowCreationThenDestruction}
+ def __init__(self, mobject, rect_animation=ShowCreationThenDestruction, **kwargs):
+ super().__init__(mobject, rect_animation=rect_animation, **kwargs)
class ShowCreationThenFadeAround(AnimationOnSurroundingRectangle):
- CONFIG = {"rect_animation": ShowCreationThenFadeOut}
+ def __init__(self, mobject, rect_animation=ShowCreationThenFadeOut, **kwargs):
+ super().__init__(mobject, rect_animation=rect_animation, **kwargs)
class ApplyWave(Homotopy):
- CONFIG = {
- "direction": UP,
- "amplitude": 0.2,
- "run_time": 1,
- }
-
- def __init__(self, mobject, **kwargs):
- digest_config(self, kwargs, locals())
+ def __init__(self, mobject, direction=UP, amplitude=0.2, run_time=1, **kwargs):
+ self.direction = direction
+ self.amplitude = amplitude
left_x = mobject.get_left()[0]
right_x = mobject.get_right()[0]
vect = self.amplitude * self.direction
@@ -259,18 +259,27 @@ class ApplyWave(Homotopy):
nudge = there_and_back(t ** power)
return np.array([x, y, z]) + nudge * vect
- super().__init__(homotopy, mobject, **kwargs)
+ super().__init__(homotopy, mobject, run_time=run_time, **kwargs)
class WiggleOutThenIn(Animation):
- CONFIG = {
- "scale_value": 1.1,
- "rotation_angle": 0.01 * TAU,
- "n_wiggles": 6,
- "run_time": 2,
- "scale_about_point": None,
- "rotate_about_point": None,
- }
+ def __init__(
+ self,
+ mobject,
+ scale_value=1.1,
+ rotation_angle=0.01 * TAU,
+ n_wiggles=6,
+ scale_about_point=None,
+ rotate_about_point=None,
+ run_time=2,
+ **kwargs
+ ):
+ self.scale_value = scale_value
+ self.rotation_angle = rotation_angle
+ self.n_wiggles = n_wiggles
+ self.scale_about_point = scale_about_point
+ self.rotate_about_point = rotate_about_point
+ super().__init__(mobject, run_time=run_time, **kwargs)
def get_scale_about_point(self):
if self.scale_about_point is None:
@@ -293,9 +302,8 @@ class WiggleOutThenIn(Animation):
class TurnInsideOut(Transform):
- CONFIG = {
- "path_arc": TAU / 4,
- }
+ def __init__(self, mobject, path_arc=TAU / 4, **kwargs):
+ super().__init__(mobject, path_arc=path_arc, **kwargs)
def create_target(self):
return self.mobject.copy().reverse_points()
diff --git a/manim/animation/movement.py b/manim/animation/movement.py
index 34268237c..7c258a5ec 100644
--- a/manim/animation/movement.py
+++ b/manim/animation/movement.py
@@ -14,18 +14,16 @@ from ..utils.rate_functions import linear
class Homotopy(Animation):
- CONFIG = {
- "run_time": 3,
- "apply_function_kwargs": {},
- }
-
- def __init__(self, homotopy, mobject, **kwargs):
+ def __init__(
+ self, homotopy, mobject, run_time=3, apply_function_kwargs={}, **kwargs
+ ):
"""
Homotopy is a function from
(x, y, z, t) to (x', y', z')
"""
self.homotopy = homotopy
- super().__init__(mobject, **kwargs)
+ self.apply_function_kwargs = apply_function_kwargs
+ super().__init__(mobject, run_time=run_time, **kwargs)
def function_at_time_t(self, t):
return lambda p: self.homotopy(*p, t)
@@ -57,15 +55,23 @@ class ComplexHomotopy(Homotopy):
class PhaseFlow(Animation):
- CONFIG = {
- "virtual_time": 1,
- "rate_func": linear,
- "suspend_mobject_updating": False,
- }
-
- def __init__(self, function, mobject, **kwargs):
+ def __init__(
+ self,
+ function,
+ mobject,
+ virtual_time=1,
+ suspend_mobject_updating=False,
+ rate_func=linear,
+ **kwargs
+ ):
+ self.virtual_time = virtual_time
self.function = function
- super().__init__(mobject, **kwargs)
+ super().__init__(
+ mobject,
+ suspend_mobject_updating=suspend_mobject_updating,
+ rate_func=rate_func,
+ **kwargs
+ )
def interpolate_mobject(self, alpha):
if hasattr(self, "last_alpha"):
@@ -75,13 +81,11 @@ class PhaseFlow(Animation):
class MoveAlongPath(Animation):
- CONFIG = {
- "suspend_mobject_updating": False,
- }
-
- def __init__(self, mobject, path, **kwargs):
+ def __init__(self, mobject, path, suspend_mobject_updating=False, **kwargs):
self.path = path
- super().__init__(mobject, **kwargs)
+ super().__init__(
+ mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs
+ )
def interpolate_mobject(self, alpha):
point = self.path.point_from_proportion(alpha)
diff --git a/manim/animation/numbers.py b/manim/animation/numbers.py
index c45ac9838..cde3049a0 100644
--- a/manim/animation/numbers.py
+++ b/manim/animation/numbers.py
@@ -11,15 +11,15 @@ from ..utils.bezier import interpolate
class ChangingDecimal(Animation):
- CONFIG = {
- "suspend_mobject_updating": False,
- }
-
- def __init__(self, decimal_mob, number_update_func, **kwargs):
+ def __init__(
+ self, decimal_mob, number_update_func, suspend_mobject_updating=False, **kwargs
+ ):
self.check_validity_of_input(decimal_mob)
self.yell_about_depricated_configuration(**kwargs)
self.number_update_func = number_update_func
- super().__init__(decimal_mob, **kwargs)
+ super().__init__(
+ decimal_mob, suspend_mobject_updating=suspend_mobject_updating, **kwargs
+ )
def check_validity_of_input(self, decimal_mob):
if not isinstance(decimal_mob, DecimalNumber):
diff --git a/manim/animation/rotation.py b/manim/animation/rotation.py
index 38704f903..bb78cdcf8 100644
--- a/manim/animation/rotation.py
+++ b/manim/animation/rotation.py
@@ -12,14 +12,22 @@ from ..utils.rate_functions import linear
class Rotating(Animation):
- CONFIG = {
- "axis": OUT,
- "radians": TAU,
- "run_time": 5,
- "rate_func": linear,
- "about_point": None,
- "about_edge": None,
- }
+ def __init__(
+ self,
+ mobject,
+ axis=OUT,
+ radians=TAU,
+ about_point=None,
+ about_edge=None,
+ run_time=5,
+ rate_func=linear,
+ **kwargs
+ ):
+ self.axis = axis
+ self.radians = radians
+ self.about_point = about_point
+ self.about_edge = about_edge
+ super().__init__(mobject, run_time=run_time, rate_func=rate_func, **kwargs)
def interpolate_mobject(self, alpha):
self.mobject.become(self.starting_mobject)
@@ -32,18 +40,17 @@ class Rotating(Animation):
class Rotate(Transform):
- CONFIG = {
- "about_point": None,
- "about_edge": None,
- }
-
- def __init__(self, mobject, angle=PI, axis=OUT, **kwargs):
+ def __init__(
+ self, mobject, angle=PI, axis=OUT, about_point=None, about_edge=None, **kwargs
+ ):
if "path_arc" not in kwargs:
kwargs["path_arc"] = angle
if "path_arc_axis" not in kwargs:
kwargs["path_arc_axis"] = axis
self.angle = angle
self.axis = axis
+ self.about_edge = about_edge
+ self.about_point = about_point
super().__init__(mobject, **kwargs)
def create_target(self):
diff --git a/manim/animation/transform.py b/manim/animation/transform.py
index 4b8b60546..cebaef883 100644
--- a/manim/animation/transform.py
+++ b/manim/animation/transform.py
@@ -33,7 +33,6 @@ from ..constants import OUT
from ..constants import DEGREES
from ..mobject.mobject import Group
from ..mobject.mobject import Mobject
-from ..utils.config_ops import digest_config
from ..utils.paths import path_along_arc
from ..utils.paths import straight_path
from ..utils.rate_functions import smooth
@@ -41,19 +40,25 @@ from ..utils.rate_functions import squish_rate_func
class Transform(Animation):
- CONFIG = {
- "path_arc": 0,
- "path_arc_axis": OUT,
- "path_func": None,
- "replace_mobject_with_target_in_scene": False,
- }
-
- def __init__(self, mobject, target_mobject=None, **kwargs):
- super().__init__(mobject, **kwargs)
+ def __init__(
+ self,
+ mobject,
+ target_mobject=None,
+ path_func=None,
+ path_arc=0,
+ path_arc_axis=OUT,
+ replace_mobject_with_target_in_scene=False,
+ **kwargs
+ ):
+ self.path_arc = path_arc
+ self.path_func = path_func
+ self.path_arc_axis = path_arc_axis
+ self.replace_mobject_with_target_in_scene = replace_mobject_with_target_in_scene
self.target_mobject = target_mobject
- self.init_path_func()
+ super().__init__(mobject, **kwargs)
+ self._init_path_func()
- def init_path_func(self):
+ def _init_path_func(self):
if self.path_func is not None:
return
elif self.path_arc == 0:
@@ -125,9 +130,10 @@ class Transform(Animation):
class ReplacementTransform(Transform):
- CONFIG = {
- "replace_mobject_with_target_in_scene": True,
- }
+ def __init__(self, mobject, target_mobject, **kwargs):
+ super().__init__(
+ mobject, target_mobject, replace_mobject_with_target_in_scene=True, **kwargs
+ )
class TransformFromCopy(Transform):
@@ -143,11 +149,13 @@ class TransformFromCopy(Transform):
class ClockwiseTransform(Transform):
- CONFIG = {"path_arc": -np.pi}
+ def __init__(self, mobject, target_mobject, path_arc=-np.pi, **kwargs):
+ super().__init__(mobject, target_mobject, path_arc=path_arc, **kwargs)
class CounterclockwiseTransform(Transform):
- CONFIG = {"path_arc": np.pi}
+ def __init__(self, mobject, target_mobject, path_arc=np.pi, **kwargs):
+ super().__init__(mobject, target_mobject, path_arc=path_arc, **kwargs)
class MoveToTarget(Transform):
@@ -220,10 +228,10 @@ class ApplyPointwiseFunction(ApplyMethod):
"""
- CONFIG = {"run_time": DEFAULT_POINTWISE_FUNCTION_RUN_TIME}
-
- def __init__(self, function, mobject, **kwargs):
- super().__init__(mobject.apply_function, function, **kwargs)
+ def __init__(
+ self, function, mobject, run_time=DEFAULT_POINTWISE_FUNCTION_RUN_TIME, **kwargs
+ ):
+ super().__init__(mobject.apply_function, function, run_time=run_time, **kwargs)
class ApplyPointwiseFunctionToCenter(ApplyPointwiseFunction):
@@ -296,23 +304,19 @@ class ApplyComplexFunction(ApplyMethod):
method = mobject.apply_complex_function
super().__init__(method, function, **kwargs)
- def init_path_func(self):
+ def _init_path_func(self):
func1 = self.function(complex(1))
self.path_arc = np.log(func1).imag
- super().init_path_func()
+ super()._init_path_func()
###
class CyclicReplace(Transform):
- CONFIG = {
- "path_arc": 90 * DEGREES,
- }
-
- def __init__(self, *mobjects, **kwargs):
+ def __init__(self, *mobjects, path_arc=90 * DEGREES, **kwargs):
self.group = Group(*mobjects)
- super().__init__(self.group, **kwargs)
+ super().__init__(self.group, path_arc=path_arc, **kwargs)
def create_target(self):
target = self.group.copy()
@@ -328,10 +332,11 @@ class Swap(CyclicReplace):
# TODO, this may be depricated...worth reimplementing?
class TransformAnimations(Transform):
- CONFIG = {"rate_func": squish_rate_func(smooth)}
-
- def __init__(self, start_anim, end_anim, **kwargs):
- digest_config(self, kwargs, locals())
+ def __init__(
+ self, start_anim, end_anim, rate_func=squish_rate_func(smooth), **kwargs
+ ):
+ self.start_anim = start_anim
+ self.end_anim = end_anim
if "run_time" in kwargs:
self.run_time = kwargs.pop("run_time")
else:
@@ -348,7 +353,9 @@ class TransformAnimations(Transform):
if hasattr(anim, "target_mobject"):
anim.starting_mobject.align_data(anim.target_mobject)
- Transform.__init__(self, start_anim.mobject, end_anim.mobject, **kwargs)
+ super().__init__(
+ start_anim.mobject, end_anim.mobject, rate_func=rate_func, **kwargs
+ )
# Rewire starting and ending mobjects
start_anim.mobject = self.starting_mobject
end_anim.mobject = self.target_mobject
diff --git a/manim/animation/update.py b/manim/animation/update.py
index 11934a6db..7b6286fa5 100644
--- a/manim/animation/update.py
+++ b/manim/animation/update.py
@@ -15,13 +15,13 @@ class UpdateFromFunc(Animation):
on another simultaneously animated mobject
"""
- CONFIG = {
- "suspend_mobject_updating": False,
- }
-
- def __init__(self, mobject, update_function, **kwargs):
+ def __init__(
+ self, mobject, update_function, suspend_mobject_updating=False, **kwargs
+ ):
self.update_function = update_function
- super().__init__(mobject, **kwargs)
+ super().__init__(
+ mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs
+ )
def interpolate_mobject(self, alpha):
self.update_function(self.mobject)
diff --git a/manim/camera/camera.py b/manim/camera/camera.py
index b92e8b298..cffbcb50b 100644
--- a/manim/camera/camera.py
+++ b/manim/camera/camera.py
@@ -21,7 +21,6 @@ from ..mobject.mobject import Mobject
from ..mobject.types.point_cloud_mobject import PMobject
from ..mobject.types.vectorized_mobject import VMobject
from ..utils.color import color_to_int_rgba
-from ..utils.config_ops import digest_config
from ..utils.images import get_full_raster_image_path
from ..utils.iterables import list_difference_update
from ..utils.simple_functions import fdiv
@@ -36,7 +35,7 @@ class Camera(object):
This is the object which takes care of what exactly is displayed
on screen at any given moment.
- Some important CONFIG values and local variables to note are:
+ Some important configuration values and local variables to note are:
background_image : :class:`str`, optional
The path to an image that should be the background image.
@@ -47,24 +46,24 @@ class Camera(object):
"""
- CONFIG = {
- "background_image": None,
- # Note: frame height and width will be resized to match
- # the pixel aspect ratio
- "frame_center": ORIGIN,
- # Points in vectorized mobjects with norm greater
- # than this value will be rescaled.
- "image_mode": "RGBA",
- "n_channels": 4,
- "pixel_array_dtype": "uint8",
- # z_buff_func is only used if the flag above is set to True.
- # round z coordinate to nearest hundredth when comparring
- "z_buff_func": lambda m: np.round(m.get_center()[2], 2),
- "cairo_line_width_multiple": 0.01,
- "use_z_index": True,
- }
-
- def __init__(self, video_quality_config, background=None, **kwargs):
+ def __init__(
+ self,
+ background_image=None,
+ frame_center=ORIGIN,
+ image_mode="RGBA",
+ n_channels=4,
+ pixel_array_dtype="uint8",
+ z_buff_func=lambda m: np.round(m.get_center()[2], 2),
+ cairo_line_width_multiple=0.01,
+ use_z_index=True,
+ background=None,
+ pixel_height=None,
+ pixel_width=None,
+ frame_height=None,
+ frame_width=None,
+ frame_rate=None,
+ **kwargs,
+ ):
"""Initialises the Camera.
Parameters
@@ -74,22 +73,35 @@ class Camera(object):
**kwargs
Any local variables to be set.
"""
- digest_config(self, kwargs, locals())
-
- # All of the following are set to EITHER the value passed via kwargs,
- # OR the value stored in the global config dict at the time of
- # _instance construction_. Before, they were in the CONFIG dict, which
- # is a class attribute and is defined at the time of _class
- # definition_. This did not allow for creating two Cameras with
- # different configurations in the same session.
- for attr in [
- "pixel_height",
- "pixel_width",
- "frame_height",
- "frame_width",
- "frame_rate",
- ]:
- setattr(self, attr, kwargs.get(attr, config[attr]))
+ self.background_image = background_image
+ self.frame_center = frame_center
+ self.image_mode = image_mode
+ self.n_channels = n_channels
+ self.pixel_array_dtype = pixel_array_dtype
+ self.z_buff_func = z_buff_func
+ self.cairo_line_width_multiple = cairo_line_width_multiple
+ self.use_z_index = use_z_index
+ self.background = background
+
+ if pixel_height is None:
+ pixel_height = config["pixel_height"]
+ self.pixel_height = pixel_height
+
+ if pixel_width is None:
+ pixel_width = config["pixel_width"]
+ self.pixel_width = pixel_width
+
+ if frame_height is None:
+ frame_height = config["frame_height"]
+ self.frame_height = frame_height
+
+ if frame_width is None:
+ frame_width = config["frame_width"]
+ self.frame_width = frame_width
+
+ if frame_rate is None:
+ frame_rate = config["frame_rate"]
+ self.frame_rate = frame_rate
for attr in ["background_color", "background_opacity"]:
setattr(self, f"_{attr}", kwargs.get(attr, config[attr]))
diff --git a/manim/camera/mapping_camera.py b/manim/camera/mapping_camera.py
index 124ed8b74..861b08618 100644
--- a/manim/camera/mapping_camera.py
+++ b/manim/camera/mapping_camera.py
@@ -8,7 +8,6 @@ import numpy as np
from ..camera.camera import Camera
from ..mobject.types.vectorized_mobject import VMobject
from ..utils.config_ops import DictAsObject
-from ..utils.config_ops import digest_config
# TODO: Add an attribute to mobjects under which they can specify that they should just
# map their centers but remain otherwise undistorted (useful for labels, etc.)
@@ -19,11 +18,17 @@ class MappingCamera(Camera):
between objects.
"""
- CONFIG = {
- "mapping_func": lambda p: p,
- "min_num_curves": 50,
- "allow_object_intrusion": False,
- }
+ def __init__(
+ self,
+ mapping_func=lambda p: p,
+ min_num_curves=50,
+ allow_object_intrusion=False,
+ **kwargs
+ ):
+ self.mapping_func = mapping_func
+ self.min_num_curves = min_num_curves
+ self.allow_object_intrusion = allow_object_intrusion
+ Camera.__init__(self, **kwargs)
def points_to_pixel_coords(self, points):
return Camera.points_to_pixel_coords(
@@ -117,7 +122,7 @@ class OldMultiCamera(Camera):
class SplitScreenCamera(OldMultiCamera):
def __init__(self, left_camera, right_camera, **kwargs):
- digest_config(self, kwargs)
+ Camera.__init__(self, **kwargs) # to set attributes such as pixel_width
self.left_camera = left_camera
self.right_camera = right_camera
diff --git a/manim/camera/moving_camera.py b/manim/camera/moving_camera.py
index 9cf891ff3..767e65f57 100644
--- a/manim/camera/moving_camera.py
+++ b/manim/camera/moving_camera.py
@@ -14,18 +14,13 @@ from ..camera.camera import Camera
from ..constants import ORIGIN
from ..mobject.frame import ScreenRectangle
from ..mobject.types.vectorized_mobject import VGroup
-from ..utils.config_ops import digest_config
from ..utils.color import WHITE
# TODO, think about how to incorporate perspective
class CameraFrame(VGroup):
- CONFIG = {
- "center": ORIGIN,
- }
-
- def __init__(self, **kwargs):
- VGroup.__init__(self, **kwargs)
+ def __init__(self, center=ORIGIN, **kwargs):
+ VGroup.__init__(self, center=center, **kwargs)
self.width = config["frame_width"]
self.height = config["frame_height"]
@@ -40,18 +35,21 @@ class MovingCamera(Camera):
"""
- CONFIG = {
- "fixed_dimension": 0, # width
- "default_frame_stroke_color": WHITE,
- "default_frame_stroke_width": 0,
- }
-
- def __init__(self, video_quality_config, frame=None, **kwargs):
+ def __init__(
+ self,
+ frame=None,
+ fixed_dimension=0, # width
+ default_frame_stroke_color=WHITE,
+ default_frame_stroke_width=0,
+ **kwargs
+ ):
"""
frame is a Mobject, (should almost certainly be a rectangle)
determining which region of space the camera displys
"""
- digest_config(self, kwargs)
+ self.fixed_dimension = fixed_dimension
+ self.default_frame_stroke_color = default_frame_stroke_color
+ self.default_frame_stroke_width = default_frame_stroke_width
if frame is None:
frame = ScreenRectangle(height=config["frame_height"])
frame.set_stroke(
@@ -59,7 +57,7 @@ class MovingCamera(Camera):
self.default_frame_stroke_width,
)
self.frame = frame
- Camera.__init__(self, video_quality_config, **kwargs)
+ Camera.__init__(self, **kwargs)
# TODO, make these work for a rotated frame
@property
diff --git a/manim/camera/multi_camera.py b/manim/camera/multi_camera.py
index 02ad2e032..e4816a476 100644
--- a/manim/camera/multi_camera.py
+++ b/manim/camera/multi_camera.py
@@ -10,12 +10,11 @@ from ..utils.iterables import list_difference_update
class MultiCamera(MovingCamera):
"""Camera Object that allows for multiple perspectives."""
- CONFIG = {
- "allow_cameras_to_capture_their_own_display": False,
- }
-
def __init__(
- self, video_quality_config, image_mobjects_from_cameras=None, **kwargs
+ self,
+ image_mobjects_from_cameras=None,
+ allow_cameras_to_capture_their_own_display=False,
+ **kwargs
):
"""Initalises the MultiCamera
@@ -30,7 +29,10 @@ class MultiCamera(MovingCamera):
if image_mobjects_from_cameras is not None:
for imfc in image_mobjects_from_cameras:
self.add_image_mobject_from_camera(imfc)
- MovingCamera.__init__(self, video_quality_config, **kwargs)
+ self.allow_cameras_to_capture_their_own_display = (
+ allow_cameras_to_capture_their_own_display
+ )
+ MovingCamera.__init__(self, **kwargs)
def add_image_mobject_from_camera(self, image_mobject_from_camera):
"""Adds an ImageMobject that's been obtained from the camera
diff --git a/manim/camera/three_d_camera.py b/manim/camera/three_d_camera.py
index d2e2d4c6e..5cba4f9f2 100644
--- a/manim/camera/three_d_camera.py
+++ b/manim/camera/three_d_camera.py
@@ -21,19 +21,19 @@ from ..utils.family import extract_mobject_family_members
class ThreeDCamera(Camera):
- CONFIG = {
- "shading_factor": 0.2,
- "distance": 20.0,
- "default_distance": 5.0,
- "phi": 0, # Angle off z axis
- "theta": -90 * DEGREES, # Rotation about z axis
- "gamma": 0, # Rotation about normal vector to camera
- "light_source_start_point": 9 * DOWN + 7 * LEFT + 10 * OUT,
- "should_apply_shading": True,
- "exponential_projection": False,
- }
-
- def __init__(self, *args, **kwargs):
+ def __init__(
+ self,
+ distance=20.0,
+ shading_factor=0.2,
+ default_distance=5.0,
+ light_source_start_point=9 * DOWN + 7 * LEFT + 10 * OUT,
+ should_apply_shading=True,
+ exponential_projection=False,
+ phi=0,
+ theta=-90 * DEGREES,
+ gamma=0,
+ **kwargs
+ ):
"""Initializes the ThreeDCamera
Parameters
@@ -43,14 +43,23 @@ class ThreeDCamera(Camera):
*kwargs
Any keyword argument of Camera.
"""
- Camera.__init__(self, *args, **kwargs)
+ self._frame_center = Point(kwargs.get("frame_center", ORIGIN))
+ super().__init__(**kwargs)
+ self.distance = distance
+ self.phi = phi
+ self.theta = theta
+ self.gamma = gamma
+ self.shading_factor = shading_factor
+ self.default_distance = default_distance
+ self.light_source_start_point = light_source_start_point
+ self.light_source = Point(self.light_source_start_point)
+ self.should_apply_shading = should_apply_shading
+ self.exponential_projection = exponential_projection
self.max_allowable_norm = 3 * config["frame_width"]
self.phi_tracker = ValueTracker(self.phi)
self.theta_tracker = ValueTracker(self.theta)
self.distance_tracker = ValueTracker(self.distance)
self.gamma_tracker = ValueTracker(self.gamma)
- self.light_source = Point(self.light_source_start_point)
- self._frame_center = Point(kwargs.get("frame_center", ORIGIN))
self.fixed_orientation_mobjects = dict()
self.fixed_in_frame_mobjects = set()
self.reset_rotation_matrix()
@@ -82,9 +91,7 @@ class ThreeDCamera(Camera):
self.gamma_tracker,
]
- def modified_rgbas(
- self, vmobject, rgbas
- ): # TODO: Write DocStrings for this method.
+ def modified_rgbas(self, vmobject, rgbas):
if not self.should_apply_shading:
return rgbas
if vmobject.shade_in_3d and (vmobject.get_num_points() > 0):
diff --git a/manim/constants.py b/manim/constants.py
index b0bf8a031..e1e8e3064 100644
--- a/manim/constants.py
+++ b/manim/constants.py
@@ -11,11 +11,6 @@ You haven't set font.
If you are not using English, this may cause text rendering problem.
You set font like:
text = Text('your text', font='your font')
-or:
-class MyText(Text):
- CONFIG = {
- 'font': 'My Font'
- }
"""
SCENE_NOT_FOUND_MESSAGE = """
{} is not in the script
diff --git a/manim/container.py b/manim/container.py
index 5182b6858..ccacf2ba4 100644
--- a/manim/container.py
+++ b/manim/container.py
@@ -8,7 +8,7 @@ __all__ = ["Container"]
from abc import ABC, abstractmethod
-from .utils.config_ops import digest_config
+from . import logger
class Container(ABC):
@@ -18,12 +18,17 @@ class Container(ABC):
Parameters
----------
kwargs : Any
- Arguments to be passed to :func:`~.digest_config`
"""
def __init__(self, **kwargs):
- digest_config(self, kwargs)
+ if kwargs:
+ logger.debug("Container received extra kwargs: %s", kwargs)
+
+ if hasattr(self, "CONFIG"):
+ logger.error(
+ "CONFIG has been removed from ManimCommunity. Please use keyword arguments instead."
+ )
@abstractmethod
def add(self, *items):
diff --git a/manim/mobject/changing.py b/manim/mobject/changing.py
index 51a442266..88a705156 100644
--- a/manim/mobject/changing.py
+++ b/manim/mobject/changing.py
@@ -27,17 +27,24 @@ class AnimatedBoundary(VGroup):
"""
- CONFIG = {
- "colors": [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
- "max_stroke_width": 3,
- "cycle_rate": 0.5,
- "back_and_forth": True,
- "draw_rate_func": smooth,
- "fade_rate_func": smooth,
- }
-
- def __init__(self, vmobject, **kwargs):
+ def __init__(
+ self,
+ vmobject,
+ colors=[BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
+ max_stroke_width=3,
+ cycle_rate=0.5,
+ back_and_forth=True,
+ draw_rate_func=smooth,
+ fade_rate_func=smooth,
+ **kwargs
+ ):
super().__init__(**kwargs)
+ self.colors = colors
+ self.max_stroke_width = max_stroke_width
+ self.cycle_rate = cycle_rate
+ self.back_and_forth = back_and_forth
+ self.draw_rate_func = draw_rate_func
+ self.fade_rate_func = fade_rate_func
self.vmobject = vmobject
self.boundary_copies = [
vmobject.copy().set_style(stroke_width=0, fill_opacity=0) for x in range(2)
@@ -91,7 +98,7 @@ class TracedPath(VMobject):
class TracedPathExample(Scene):
def construct(self):
- circ = Circle(Color=RED).shift(4*LEFT)
+ circ = Circle(color=RED).shift(4*LEFT)
dot = Dot(color=RED).move_to(circ.get_start())
rolling_circle = VGroup(circ, dot)
trace = TracedPath(circ.get_start)
@@ -101,14 +108,16 @@ class TracedPath(VMobject):
"""
- CONFIG = {
- "stroke_width": 2,
- "stroke_color": WHITE,
- "min_distance_to_new_point": 0.1,
- }
-
- def __init__(self, traced_point_func, **kwargs):
- super().__init__(**kwargs)
+ def __init__(
+ self,
+ traced_point_func,
+ stroke_width=2,
+ stroke_color=WHITE,
+ min_distance_to_new_point=0.1,
+ **kwargs
+ ):
+ super().__init__(stroke_color=stroke_color, stroke_width=stroke_width, **kwargs)
+ self.min_distance_to_new_point = min_distance_to_new_point
self.traced_point_func = traced_point_func
self.add_updater(lambda m: m.update_path())
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py
index e90d57381..ece6e353b 100644
--- a/manim/mobject/coordinate_systems.py
+++ b/manim/mobject/coordinate_systems.py
@@ -130,18 +130,26 @@ class CoordinateSystem:
class Axes(VGroup, CoordinateSystem):
- CONFIG = {
- "axis_config": {
- "color": LIGHT_GREY,
- "include_tip": True,
- "exclude_zero_from_default_numbers": True,
- },
- "x_axis_config": {},
- "y_axis_config": {"label_direction": LEFT},
- "center_point": ORIGIN,
- }
-
- def __init__(self, **kwargs):
+ def __init__(
+ self,
+ axis_config=None,
+ x_axis_config=None,
+ y_axis_config={"label_direction": LEFT},
+ center_point=ORIGIN,
+ **kwargs
+ ):
+ if axis_config is None:
+ axis_config = {
+ "color": LIGHT_GREY,
+ "include_tip": True,
+ "exclude_zero_from_default_numbers": True,
+ }
+ self.axis_config = axis_config
+ if x_axis_config is None:
+ x_axis_config = {}
+ self.x_axis_config = x_axis_config
+ self.y_axis_config = y_axis_config
+ self.center_point = center_point
CoordinateSystem.__init__(self)
VGroup.__init__(self, **kwargs)
self.x_axis = self.create_axis(self.x_min, self.x_max, self.x_axis_config)
@@ -150,7 +158,7 @@ class Axes(VGroup, CoordinateSystem):
# Add as a separate group in case various other
# mobjects are added to self, as for example in
# NumberPlane below
- self.axes = VGroup(self.x_axis, self.y_axis)
+ self.axes = VGroup(self.x_axis, self.y_axis, dim=self.dim)
self.add(*self.axes)
self.shift(self.center_point)
@@ -198,16 +206,24 @@ class Axes(VGroup, CoordinateSystem):
class ThreeDAxes(Axes):
- CONFIG = {
- "z_axis_config": {},
- "z_min": -3.5,
- "z_max": 3.5,
- "z_normal": DOWN,
- "num_axis_pieces": 20,
- "light_source": 9 * DOWN + 7 * LEFT + 10 * OUT,
- }
-
- def __init__(self, **kwargs):
+ def __init__(
+ self,
+ z_axis_config=None,
+ z_min=-3.5,
+ z_max=3.5,
+ z_normal=DOWN,
+ num_axis_pieces=20,
+ light_source=9 * DOWN + 7 * LEFT + 10 * OUT,
+ **kwargs
+ ):
+ if z_axis_config is None:
+ z_axis_config = {}
+ self.z_axis_config = z_axis_config
+ self.z_min = z_min
+ self.z_max = z_max
+ self.z_normal = z_normal
+ self.num_axis_pieces = num_axis_pieces
+ self.light_source = light_source
self.x_min = -5.5
self.x_max = 5.5
self.y_min = -5.5
@@ -248,32 +264,53 @@ class ThreeDAxes(Axes):
class NumberPlane(Axes):
- CONFIG = {
- "axis_config": {
- "stroke_color": WHITE,
- "stroke_width": 2,
- "include_ticks": False,
- "include_tip": False,
- "line_to_number_buff": SMALL_BUFF,
- "label_direction": DR,
- "number_scale_val": 0.5,
- },
- "y_axis_config": {"label_direction": DR},
- "background_line_style": {
- "stroke_color": BLUE_D,
- "stroke_width": 2,
- "stroke_opacity": 1,
- },
+ def __init__(
+ self,
+ axis_config=None,
+ y_axis_config=None,
+ background_line_style=None,
+ faded_line_style=None,
+ x_line_frequency=1,
+ y_line_frequency=1,
+ faded_line_ratio=1,
+ make_smooth_after_applying_functions=True,
+ **kwargs
+ ):
+ if axis_config is None:
+ axis_config = {
+ "stroke_color": WHITE,
+ "stroke_width": 2,
+ "include_ticks": False,
+ "include_tip": False,
+ "line_to_number_buff": SMALL_BUFF,
+ "label_direction": DR,
+ "number_scale_val": 0.5,
+ }
+ self.axis_config = axis_config
+ if y_axis_config is None:
+ y_axis_config = {"label_direction": DR}
+ self.y_axis_config = y_axis_config
+
+ if background_line_style is None:
+ background_line_style = {
+ "stroke_color": BLUE_D,
+ "stroke_width": 2,
+ "stroke_opacity": 1,
+ }
+ self.background_line_style = background_line_style
+
# Defaults to a faded version of line_config
- "faded_line_style": None,
- "x_line_frequency": 1,
- "y_line_frequency": 1,
- "faded_line_ratio": 1,
- "make_smooth_after_applying_functions": True,
- }
-
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
+ self.faded_line_style = faded_line_style
+ self.x_line_frequency = x_line_frequency
+ self.y_line_frequency = y_line_frequency
+ self.faded_line_ratio = faded_line_ratio
+ self.make_smooth_after_applying_functions = make_smooth_after_applying_functions
+
+ super().__init__(
+ axis_config=self.axis_config,
+ y_axis_config=self.y_axis_config,
+ **kwargs,
+ )
self.init_background_lines()
def init_background_lines(self):
@@ -400,10 +437,13 @@ class NumberPlane(Axes):
class ComplexPlane(NumberPlane):
- CONFIG = {
- "color": BLUE,
- "line_frequency": 1,
- }
+ def __init__(self, color=BLUE, x_line_frequency=1, y_line_frequency=1, **kwargs):
+ super().__init__(
+ color=color,
+ x_line_frequency=x_line_frequency,
+ y_line_frequency=y_line_frequency,
+ **kwargs,
+ )
def number_to_point(self, number):
number = complex(number)
diff --git a/manim/mobject/frame.py b/manim/mobject/frame.py
index 6fe404356..a9c860e1b 100644
--- a/manim/mobject/frame.py
+++ b/manim/mobject/frame.py
@@ -11,14 +11,13 @@ __all__ = [
from .. import config
from ..constants import *
from ..mobject.geometry import Rectangle
-from ..utils.config_ops import digest_config
from ..utils.color import BLACK
class ScreenRectangle(Rectangle):
- CONFIG = {"aspect_ratio": 16.0 / 9.0, "height": 4}
-
- def __init__(self, **kwargs):
+ def __init__(self, aspect_ratio=16.0 / 9.0, height=4, **kwargs):
+ self.aspect_ratio = aspect_ratio
+ self.height = height
Rectangle.__init__(self, **kwargs)
self.set_width(self.aspect_ratio * self.get_height(), stretch=True)
@@ -30,18 +29,20 @@ class FullScreenRectangle(ScreenRectangle):
class FullScreenFadeRectangle(FullScreenRectangle):
- CONFIG = {
- "stroke_width": 0,
- "fill_color": BLACK,
- "fill_opacity": 0.7,
- }
+ def __init__(self, stroke_width=0, fill_color=BLACK, fill_opacity=0.7, **kwargs):
+ FullScreenRectangle.__init__(
+ self,
+ stroke_width=stroke_width,
+ fill_color=fill_color,
+ fill_opacity=fill_opacity,
+ **kwargs
+ )
class PictureInPictureFrame(Rectangle):
- CONFIG = {"height": 3, "aspect_ratio": 16.0 / 9.0}
-
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, height=3, aspect_ratio=16.0 / 9.0, **kwargs):
+ self.height = height
+ self.aspect_ratio = aspect_ratio
Rectangle.__init__(
self, width=self.aspect_ratio * self.height, height=self.height, **kwargs
)
diff --git a/manim/mobject/functions.py b/manim/mobject/functions.py
index f0ac9236d..a73c1c984 100644
--- a/manim/mobject/functions.py
+++ b/manim/mobject/functions.py
@@ -6,7 +6,6 @@ __all__ = ["ParametricFunction", "FunctionGraph"]
from .. import config
from ..constants import *
from ..mobject.types.vectorized_mobject import VMobject
-from ..utils.config_ops import digest_config
from ..utils.color import YELLOW
import math
@@ -47,18 +46,22 @@ class ParametricFunction(VMobject):
self.wait()
"""
- CONFIG = {
- "t_min": 0,
- "t_max": 1,
- "step_size": 0.01, # Use "auto" (lowercase) for automatic step size
- "dt": 1e-8,
- # TODO, be smarter about figuring these out?
- "discontinuities": [],
- }
-
- def __init__(self, function=None, **kwargs):
- # either get a function from __init__ or from CONFIG
- self.function = function or self.function
+ def __init__(
+ self,
+ function=None,
+ t_min=0,
+ t_max=1,
+ step_size=0.01,
+ dt=1e-8,
+ discontinuities=None,
+ **kwargs
+ ):
+ self.function = function
+ self.t_min = t_min
+ self.t_max = t_max
+ self.step_size = step_size
+ self.dt = dt
+ self.discontinuities = [] if discontinuities is None else discontinuities
VMobject.__init__(self, **kwargs)
def get_function(self):
@@ -116,12 +119,7 @@ class ParametricFunction(VMobject):
class FunctionGraph(ParametricFunction):
- CONFIG = {
- "color": YELLOW,
- }
-
- def __init__(self, function, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, function, color=YELLOW, **kwargs):
self.x_min = -config["frame_x_radius"]
self.x_max = config["frame_x_radius"]
self.parametric_function = lambda t: np.array([t, function(t), 0])
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py
index 528c14f60..c3cf17f24 100644
--- a/manim/mobject/geometry.py
+++ b/manim/mobject/geometry.py
@@ -65,7 +65,6 @@ from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.types.vectorized_mobject import VMobject
from ..mobject.types.vectorized_mobject import DashedVMobject
-from ..utils.config_ops import digest_config
from ..utils.iterables import adjacent_n_tuples
from ..utils.iterables import adjacent_pairs
from ..utils.simple_functions import fdiv
@@ -104,12 +103,17 @@ class TipableVMobject(VMobject):
"""
- CONFIG = {
- "tip_length": DEFAULT_ARROW_TIP_LENGTH,
- # TODO
- "normal_vector": OUT,
- "tip_style": dict(),
- }
+ def __init__(
+ self,
+ tip_length=DEFAULT_ARROW_TIP_LENGTH,
+ normal_vector=OUT,
+ tip_style={},
+ **kwargs
+ ):
+ self.tip_length = tip_length
+ self.normal_vector = normal_vector
+ self.tip_style = tip_style
+ VMobject.__init__(self, **kwargs)
# Adding, Creating, Modifying tips
@@ -255,18 +259,26 @@ class TipableVMobject(VMobject):
class Arc(TipableVMobject):
"""A circular arc."""
- CONFIG = {
- "radius": 1.0,
- "num_components": 9,
- "anchors_span_full_range": True,
- "arc_center": ORIGIN,
- }
-
- def __init__(self, start_angle=0, angle=TAU / 4, **kwargs):
+ def __init__(
+ self,
+ start_angle=0,
+ angle=TAU / 4,
+ radius=1.0,
+ num_components=9,
+ anchors_span_full_range=True,
+ arc_center=ORIGIN,
+ **kwargs
+ ):
+ if radius is None: # apparently None is passed by ArcBetweenPoints
+ radius = 1.0
+ self.radius = radius
+ self.num_components = num_components
+ self.anchors_span_full_range = anchors_span_full_range
+ self.arc_center = arc_center
self.start_angle = start_angle
self.angle = angle
self._failed_to_get_center = False
- VMobject.__init__(self, **kwargs)
+ TipableVMobject.__init__(self, **kwargs)
def generate_points(self):
self.set_pre_positioned_points()
@@ -351,7 +363,7 @@ class ArcBetweenPoints(Arc):
arc_height = radius - math.sqrt(radius ** 2 - halfdist ** 2)
angle = math.acos((radius - arc_height) / radius) * sign
- Arc.__init__(self, angle=angle, **kwargs)
+ Arc.__init__(self, radius=radius, angle=angle, **kwargs)
if angle == 0:
self.set_points_as_corners([LEFT, RIGHT])
self.put_start_and_end_on(start, end)
@@ -367,25 +379,31 @@ class ArcBetweenPoints(Arc):
class CurvedArrow(ArcBetweenPoints):
def __init__(self, start_point, end_point, **kwargs):
ArcBetweenPoints.__init__(self, start_point, end_point, **kwargs)
- self.add_tip(tip_shape=kwargs.get("tip_shape", ArrowTriangleFilledTip))
+ self.add_tip(tip_shape=kwargs.pop("tip_shape", ArrowTriangleFilledTip))
class CurvedDoubleArrow(CurvedArrow):
def __init__(self, start_point, end_point, **kwargs):
if "tip_shape_end" in kwargs:
kwargs["tip_shape"] = kwargs.pop("tip_shape_end")
+ tip_shape_start = kwargs.pop("tip_shape_start", ArrowTriangleFilledTip)
CurvedArrow.__init__(self, start_point, end_point, **kwargs)
- self.add_tip(
- at_start=True,
- tip_shape=kwargs.get("tip_shape_start", ArrowTriangleFilledTip),
- )
+ self.add_tip(at_start=True, tip_shape=tip_shape_start)
class Circle(Arc):
- CONFIG = {"color": RED, "close_new_points": True, "anchors_span_full_range": False}
-
- def __init__(self, **kwargs):
- Arc.__init__(self, 0, TAU, **kwargs)
+ def __init__(
+ self, color=RED, close_new_points=True, anchors_span_full_range=False, **kwargs
+ ):
+ Arc.__init__(
+ self,
+ start_angle=0,
+ angle=TAU,
+ color=color,
+ close_new_points=close_new_points,
+ anchors_span_full_range=anchors_span_full_range,
+ **kwargs
+ )
def surround(self, mobject, dim_to_match=0, stretch=False, buffer_factor=1.2):
# Ignores dim_to_match and stretch; result will always be a circle
@@ -404,15 +422,24 @@ class Circle(Arc):
class Dot(Circle):
- CONFIG = {
- "radius": DEFAULT_DOT_RADIUS,
- "stroke_width": 0,
- "fill_opacity": 1.0,
- "color": WHITE,
- }
-
- def __init__(self, point=ORIGIN, **kwargs):
- Circle.__init__(self, arc_center=point, **kwargs)
+ def __init__(
+ self,
+ point=ORIGIN,
+ radius=DEFAULT_DOT_RADIUS,
+ stroke_width=0,
+ fill_opacity=1.0,
+ color=WHITE,
+ **kwargs
+ ):
+ Circle.__init__(
+ self,
+ arc_center=point,
+ radius=radius,
+ stroke_width=stroke_width,
+ fill_opacity=fill_opacity,
+ color=color,
+ **kwargs
+ )
class SmallDot(Dot):
@@ -420,7 +447,8 @@ class SmallDot(Dot):
A dot with small radius
"""
- CONFIG = {"radius": DEFAULT_SMALL_DOT_RADIUS}
+ def __init__(self, radius=DEFAULT_SMALL_DOT_RADIUS, **kwargs):
+ Dot.__init__(self, radius=radius, **kwargs)
class AnnotationDot(Dot):
@@ -428,12 +456,22 @@ class AnnotationDot(Dot):
A dot with bigger radius and bold stroke to annotate scenes.
"""
- CONFIG = {
- "radius": DEFAULT_DOT_RADIUS * 1.3,
- "stroke_width": 5,
- "stroke_color": WHITE,
- "fill_color": BLUE,
- }
+ def __init__(
+ self,
+ radius=DEFAULT_DOT_RADIUS * 1.3,
+ stroke_width=5,
+ stroke_color=WHITE,
+ fill_color=BLUE,
+ **kwargs
+ ):
+ Dot.__init__(
+ self,
+ radius=radius,
+ stroke_width=stroke_width,
+ stroke_color=stroke_color,
+ fill_color=fill_color,
+ **kwargs
+ )
class LabeledDot(Dot):
@@ -490,24 +528,37 @@ class LabeledDot(Dot):
class Ellipse(Circle):
- CONFIG = {"width": 2, "height": 1}
-
- def __init__(self, **kwargs):
+ def __init__(self, width=2, height=1, **kwargs):
Circle.__init__(self, **kwargs)
+ self.width = width
+ self.height = height
self.set_width(self.width, stretch=True)
self.set_height(self.height, stretch=True)
class AnnularSector(Arc):
- CONFIG = {
- "inner_radius": 1,
- "outer_radius": 2,
- "angle": TAU / 4,
- "start_angle": 0,
- "fill_opacity": 1,
- "stroke_width": 0,
- "color": WHITE,
- }
+ def __init__(
+ self,
+ inner_radius=1,
+ outer_radius=2,
+ angle=TAU / 4,
+ start_angle=0,
+ fill_opacity=1,
+ stroke_width=0,
+ color=WHITE,
+ **kwargs
+ ):
+ self.inner_radius = inner_radius
+ self.outer_radius = outer_radius
+ Arc.__init__(
+ self,
+ start_angle=start_angle,
+ angle=angle,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ color=color,
+ **kwargs
+ )
def generate_points(self):
inner_arc, outer_arc = [
@@ -527,18 +578,33 @@ class AnnularSector(Arc):
class Sector(AnnularSector):
- CONFIG = {"outer_radius": 1, "inner_radius": 0}
+ def __init__(self, outer_radius=1, inner_radius=0, **kwargs):
+ AnnularSector.__init__(
+ self, inner_radius=inner_radius, outer_radius=outer_radius, **kwargs
+ )
class Annulus(Circle):
- CONFIG = {
- "inner_radius": 1,
- "outer_radius": 2,
- "fill_opacity": 1,
- "stroke_width": 0,
- "color": WHITE,
- "mark_paths_closed": False,
- }
+ def __init__(
+ self,
+ inner_radius=1,
+ outer_radius=2,
+ fill_opacity=1,
+ stroke_width=0,
+ color=WHITE,
+ mark_paths_closed=False,
+ **kwargs
+ ):
+ self.mark_paths_closed = mark_paths_closed # is this even used?
+ self.inner_radius = inner_radius
+ self.outer_radius = outer_radius
+ Circle.__init__(
+ self,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ color=color,
+ **kwargs
+ )
def generate_points(self):
self.radius = self.outer_radius
@@ -551,12 +617,11 @@ class Annulus(Circle):
class Line(TipableVMobject):
- CONFIG = {"buff": 0, "path_arc": None} # angle of arc specified here
-
- def __init__(self, start=LEFT, end=RIGHT, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, start=LEFT, end=RIGHT, buff=0, path_arc=None, **kwargs):
+ self.buff = buff
+ self.path_arc = path_arc
self.set_start_and_end_attrs(start, end)
- VMobject.__init__(self, **kwargs)
+ TipableVMobject.__init__(self, **kwargs)
def generate_points(self):
if self.path_arc:
@@ -645,18 +710,22 @@ class Line(TipableVMobject):
class DashedLine(Line):
- CONFIG = {
- "dash_length": DEFAULT_DASH_LENGTH,
- "dash_spacing": None,
- "positive_space_ratio": 0.5,
- }
-
- def __init__(self, *args, **kwargs):
+ def __init__(
+ self,
+ *args,
+ dash_length=DEFAULT_DASH_LENGTH,
+ dash_spacing=None,
+ positive_space_ratio=0.5,
+ **kwargs
+ ):
+ self.dash_length = dash_length
+ self.dash_spacing = (dash_spacing,)
+ self.positive_space_ratio = positive_space_ratio
Line.__init__(self, *args, **kwargs)
- ps_ratio = self.positive_space_ratio
- num_dashes = self.calculate_num_dashes(ps_ratio)
dashes = DashedVMobject(
- self, num_dashes=num_dashes, positive_space_ratio=ps_ratio
+ self,
+ num_dashes=self.calculate_num_dashes(positive_space_ratio),
+ positive_space_ratio=positive_space_ratio,
)
self.clear_points()
self.add(*dashes)
@@ -691,10 +760,9 @@ class DashedLine(Line):
class TangentLine(Line):
- CONFIG = {"length": 1, "d_alpha": 1e-6}
-
- def __init__(self, vmob, alpha, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, vmob, alpha, length=1, d_alpha=1e-6, **kwargs):
+ self.length = length
+ self.d_alpha = d_alpha
da = self.d_alpha
a1 = np.clip(alpha - da, 0, 1)
a2 = np.clip(alpha + da, 0, 1)
@@ -705,9 +773,9 @@ class TangentLine(Line):
class Elbow(VMobject):
- CONFIG = {"width": 0.2, "angle": 0}
-
- def __init__(self, **kwargs):
+ def __init__(self, width=0.2, angle=0, **kwargs):
+ self.width = width
+ self.angle = angle
VMobject.__init__(self, **kwargs)
self.set_points_as_corners([UP, UP + RIGHT, RIGHT])
self.set_width(self.width, about_point=ORIGIN)
@@ -715,20 +783,31 @@ class Elbow(VMobject):
class Arrow(Line):
- CONFIG = {
- "stroke_width": 6,
- "buff": MED_SMALL_BUFF,
- "max_tip_length_to_length_ratio": 0.25,
- "max_stroke_width_to_length_ratio": 5,
- "preserve_tip_size_when_scaling": True,
- }
-
- def __init__(self, *args, **kwargs):
- Line.__init__(self, *args, **kwargs)
+ def __init__(
+ self,
+ *args,
+ stroke_width=6,
+ buff=MED_SMALL_BUFF,
+ max_tip_length_to_length_ratio=0.25,
+ max_stroke_width_to_length_ratio=5,
+ preserve_tip_size_when_scaling=True,
+ **kwargs
+ ):
+ self.max_tip_length_to_length_ratio = (
+ max_tip_length_to_length_ratio # is this used anywhere
+ )
+ self.max_stroke_width_to_length_ratio = (
+ max_stroke_width_to_length_ratio # is this used anywhere
+ )
+ self.preserve_tip_size_when_scaling = (
+ preserve_tip_size_when_scaling # is this used anywhere
+ )
+ tipp_shape = kwargs.pop("tip_shape", ArrowTriangleFilledTip)
+ Line.__init__(self, *args, buff=buff, stroke_width=stroke_width, **kwargs)
# TODO, should this be affected when
# Arrow.set_stroke is called?
self.initial_stroke_width = self.stroke_width
- self.add_tip(tip_shape=kwargs.get("tip_shape", ArrowTriangleFilledTip))
+ self.add_tip(tip_shape=tipp_shape)
self.set_stroke_width_from_length()
def scale(self, factor, scale_tips=False, **kwargs):
@@ -746,7 +825,7 @@ class Arrow(Line):
>>> scaled_arrow = arrow.scale(2)
>>> scaled_arrow.get_start_and_end()
(array([-2., -2., 0.]), array([2., 2., 0.]))
- >>> arrow.tip.tip_length == scaled_arrow.tip.tip_length
+ >>> arrow.tip.length == scaled_arrow.tip.length
True
Manually scaling the object using the default method
@@ -754,7 +833,7 @@ class Arrow(Line):
>>> new_arrow = Arrow(np.array([-1, -1, 0]), np.array([1, 1, 0]), buff=0)
>>> another_scaled_arrow = VMobject.scale(new_arrow, 2)
- >>> another_scaled_arrow.tip.tip_length == arrow.tip.tip_length
+ >>> another_scaled_arrow.tip.length == arrow.tip.length
False
"""
@@ -801,23 +880,20 @@ class Arrow(Line):
class Vector(Arrow):
- CONFIG = {"buff": 0}
-
- def __init__(self, direction=RIGHT, **kwargs):
+ def __init__(self, direction=RIGHT, buff=0, **kwargs):
+ self.buff = buff
if len(direction) == 2:
direction = np.append(np.array(direction), 0)
- Arrow.__init__(self, ORIGIN, direction, **kwargs)
+ Arrow.__init__(self, ORIGIN, direction, buff=buff, **kwargs)
class DoubleArrow(Arrow):
def __init__(self, *args, **kwargs):
if "tip_shape_end" in kwargs:
kwargs["tip_shape"] = kwargs.pop("tip_shape_end")
+ tip_shape_start = kwargs.pop("tip_shape_start", ArrowTriangleFilledTip)
Arrow.__init__(self, *args, **kwargs)
- self.add_tip(
- at_start=True,
- tip_shape=kwargs.get("tip_shape_start", ArrowTriangleFilledTip),
- )
+ self.add_tip(at_start=True, tip_shape=tip_shape_start)
class CubicBezier(VMobject):
@@ -827,10 +903,8 @@ class CubicBezier(VMobject):
class Polygon(VMobject):
- CONFIG = {"color": BLUE}
-
- def __init__(self, *vertices, **kwargs):
- VMobject.__init__(self, **kwargs)
+ def __init__(self, *vertices, color=BLUE, **kwargs):
+ VMobject.__init__(self, color=color, **kwargs)
self.set_points_as_corners([*vertices, vertices[0]])
def get_vertices(self):
@@ -872,10 +946,8 @@ class Polygon(VMobject):
class RegularPolygon(Polygon):
- CONFIG = {"start_angle": None}
-
- def __init__(self, n=6, **kwargs):
- digest_config(self, kwargs, locals())
+ def __init__(self, n=6, start_angle=None, **kwargs):
+ self.start_angle = start_angle
if self.start_angle is None:
if n % 2 == 0:
self.start_angle = 0
@@ -1130,34 +1202,33 @@ class Triangle(RegularPolygon):
class Rectangle(Polygon):
- CONFIG = {
- "color": WHITE,
- "height": 2.0,
- "width": 4.0,
- "mark_paths_closed": True,
- "close_new_points": True,
- }
-
- def __init__(self, **kwargs):
- Polygon.__init__(self, UL, UR, DR, DL, **kwargs)
+ def __init__(
+ self,
+ color=WHITE,
+ height=2.0,
+ width=4.0,
+ mark_paths_closed=True,
+ close_new_points=True,
+ **kwargs
+ ):
+ self.height = height
+ self.width = width
+ self.mark_paths_closed = mark_paths_closed
+ self.close_new_points = close_new_points
+ Polygon.__init__(self, UL, UR, DR, DL, color=color, **kwargs)
self.set_width(self.width, stretch=True)
self.set_height(self.height, stretch=True)
class Square(Rectangle):
- CONFIG = {"side_length": 2.0}
-
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
- Rectangle.__init__(
- self, height=self.side_length, width=self.side_length, **kwargs
- )
+ def __init__(self, side_length=2.0, **kwargs):
+ self.side_length = side_length
+ Rectangle.__init__(self, height=side_length, width=side_length, **kwargs)
class RoundedRectangle(Rectangle):
- CONFIG = {"corner_radius": 0.5}
-
- def __init__(self, **kwargs):
+ def __init__(self, corner_radius=0.5, **kwargs):
+ self.corner_radius = corner_radius
Rectangle.__init__(self, **kwargs)
self.round_corners(self.corner_radius)
@@ -1191,8 +1262,9 @@ class ArrowTip(VMobject):
>>> class MyCustomArrowTip(ArrowTip, RegularPolygon):
... def __init__(self, **kwargs):
... RegularPolygon.__init__(self, n=5, **kwargs)
- ... self.set_width(self.length)
- ... self.set_height(self.length, stretch=True)
+ ... length = 0.35
+ ... self.set_width(length)
+ ... self.set_height(length, stretch=True)
>>> arr = Arrow(np.array([-2, -2, 0]), np.array([2, 2, 0]),
... tip_shape=MyCustomArrowTip)
>>> isinstance(arr.tip, RegularPolygon)
@@ -1231,12 +1303,6 @@ class ArrowTip(VMobject):
self.add(a00, a11, a12, a21, a22, a31, a32, b11, b12, b21)
"""
- CONFIG = {
- "fill_opacity": 0,
- "stroke_width": 3,
- "length": DEFAULT_ARROW_TIP_LENGTH,
- "start_angle": PI,
- }
def __init__(self, *args, **kwargs):
raise NotImplementedError("Has to be implemented in inheriting subclasses.")
@@ -1304,7 +1370,7 @@ class ArrowTip(VMobject):
return angle_of_vector(self.vector)
@property
- def tip_length(self):
+ def length(self):
r"""The length of the arrow tip.
Examples
@@ -1312,85 +1378,105 @@ class ArrowTip(VMobject):
::
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 2, 0]))
- >>> round(arrow.tip.tip_length, 3)
+ >>> round(arrow.tip.length, 3)
0.35
"""
return get_norm(self.vector)
-class ArrowFilledTip(ArrowTip):
- r"""Base class for arrow tips with filled tip.
-
- Note
- ----
- In comparison to :class:`ArrowTip`, this class only provides
- different default settings for styling arrow tips. These settings
- (in particular `fill_opacity` and `stroke_width`) can also be
- overridden manually.
-
- See Also
- --------
- :class:`ArrowTip`
- :class:`ArrowTriangleFilledTip`
- :class:`ArrowCircleFilledTip`
- :class:`ArrowSquareFilledTip`
-
- """
- CONFIG = {
- "fill_opacity": 1,
- "stroke_width": 0,
- "length": DEFAULT_ARROW_TIP_LENGTH,
- "start_angle": PI,
- }
-
-
class ArrowTriangleTip(ArrowTip, Triangle):
r"""Triangular arrow tip."""
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
- Triangle.__init__(self, **kwargs)
- self.set_width(self.length)
- self.set_height(self.length, stretch=True)
+ def __init__(
+ self,
+ fill_opacity=0,
+ stroke_width=3,
+ length=DEFAULT_ARROW_TIP_LENGTH,
+ start_angle=PI,
+ **kwargs
+ ):
+ Triangle.__init__(
+ self,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ start_angle=start_angle,
+ **kwargs
+ )
+ self.set_width(length)
+ self.set_height(length, stretch=True)
-class ArrowTriangleFilledTip(ArrowFilledTip, ArrowTriangleTip):
+class ArrowTriangleFilledTip(ArrowTriangleTip):
r"""Triangular arrow tip with filled tip.
This is the default arrow tip shape.
"""
- pass
+
+ def __init__(self, fill_opacity=1, stroke_width=0, **kwargs):
+ ArrowTriangleTip.__init__(
+ self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
+ )
class ArrowCircleTip(ArrowTip, Circle):
r"""Circular arrow tip."""
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
- Circle.__init__(self, **kwargs)
- self.set_width(self.length)
- self.set_height(self.length, stretch=True)
+ def __init__(
+ self,
+ fill_opacity=0,
+ stroke_width=3,
+ length=DEFAULT_ARROW_TIP_LENGTH,
+ start_angle=PI,
+ **kwargs
+ ):
+ self.start_angle = start_angle
+ Circle.__init__(
+ self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
+ )
+ self.set_width(length)
+ self.set_height(length, stretch=True)
-class ArrowCircleFilledTip(ArrowFilledTip, ArrowCircleTip):
+class ArrowCircleFilledTip(ArrowCircleTip):
r"""Circular arrow tip with filled tip."""
- pass
+
+ def __init__(self, fill_opacity=1, stroke_width=0, **kwargs):
+ ArrowCircleTip.__init__(
+ self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
+ )
class ArrowSquareTip(ArrowTip, Square):
r"""Square arrow tip."""
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
- Square.__init__(self, side_length=self.length, **kwargs)
- self.set_width(self.length)
- self.set_height(self.length, stretch=True)
+ def __init__(
+ self,
+ fill_opacity=0,
+ stroke_width=3,
+ length=DEFAULT_ARROW_TIP_LENGTH,
+ start_angle=PI,
+ **kwargs
+ ):
+ self.start_angle = start_angle
+ Square.__init__(
+ self,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ side_length=length,
+ **kwargs
+ )
+ self.set_width(length)
+ self.set_height(length, stretch=True)
-class ArrowSquareFilledTip(ArrowFilledTip, ArrowSquareTip):
+class ArrowSquareFilledTip(ArrowSquareTip):
r"""Square arrow tip with filled tip."""
- pass
+
+ def __init__(self, fill_opacity=1, stroke_width=0, **kwargs):
+ ArrowSquareTip.__init__(
+ self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
+ )
class Cutout(VMobject):
diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py
index becff30aa..6c70f5d8c 100644
--- a/manim/mobject/matrix.py
+++ b/manim/mobject/matrix.py
@@ -64,25 +64,37 @@ def vector_coordinate_label(vector_mob, integer_labels=True, n_dim=2, color=WHIT
class Matrix(VMobject):
- CONFIG = {
- "v_buff": 0.8,
- "h_buff": 1.3,
- "bracket_h_buff": MED_SMALL_BUFF,
- "bracket_v_buff": MED_SMALL_BUFF,
- "add_background_rectangles_to_entries": False,
- "include_background_rectangle": False,
- "element_to_mobject": MathTex,
- "element_to_mobject_config": {},
- "element_alignment_corner": DR,
- "left_bracket": "\\big[",
- "right_bracket": "\\big]",
- }
-
- def __init__(self, matrix, **kwargs):
+ def __init__(
+ self,
+ matrix,
+ v_buff=0.8,
+ h_buff=1.3,
+ bracket_h_buff=MED_SMALL_BUFF,
+ bracket_v_buff=MED_SMALL_BUFF,
+ add_background_rectangles_to_entries=False,
+ include_background_rectangle=False,
+ element_to_mobject=MathTex,
+ element_to_mobject_config={},
+ element_alignment_corner=DR,
+ left_bracket="\\big[",
+ right_bracket="\\big]",
+ **kwargs
+ ):
"""
Matrix can either either include numbres, tex_strings,
or mobjects
"""
+ self.v_buff = v_buff
+ self.h_buff = h_buff
+ self.bracket_h_buff = bracket_h_buff
+ self.bracket_v_buff = bracket_v_buff
+ self.add_background_rectangles_to_entries = add_background_rectangles_to_entries
+ self.include_background_rectangle = include_background_rectangle
+ self.element_to_mobject = element_to_mobject
+ self.element_to_mobject_config = element_to_mobject_config
+ self.element_alignment_corner = element_alignment_corner
+ self.left_bracket = left_bracket
+ self.right_bracket = right_bracket
VMobject.__init__(self, **kwargs)
matrix = np.array(matrix, ndmin=1)
mob_matrix = self.matrix_to_mob_matrix(matrix)
@@ -181,22 +193,28 @@ class Matrix(VMobject):
class DecimalMatrix(Matrix):
- CONFIG = {
- "element_to_mobject": DecimalNumber,
- "element_to_mobject_config": {"num_decimal_places": 1},
- }
+ def __init__(
+ self,
+ element_to_mobject=DecimalNumber,
+ element_to_mobject_config={"num_decimal_places": 1},
+ **kwargs
+ ):
+ Matrix.__init__(
+ self,
+ element_to_mobject=element_to_mobject,
+ element_to_mobject_config=element_to_mobject_config,
+ **kwargs
+ )
class IntegerMatrix(Matrix):
- CONFIG = {
- "element_to_mobject": Integer,
- }
+ def __init__(self, element_to_mobject=Integer, **kwargs):
+ Matrix.__init__(self, element_to_mobject=element_to_mobject, **kwargs)
class MobjectMatrix(Matrix):
- CONFIG = {
- "element_to_mobject": lambda m: m,
- }
+ def __init__(self, element_to_mobject=lambda m: m, **kwargs):
+ Matrix.__init__(self, element_to_mobject=element_to_mobject, **kwargs)
def get_det_text(
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index d0249fd98..1ebe6b411 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -42,26 +42,21 @@ class Mobject(Container):
"""
- CONFIG = {
- "color": WHITE,
- "name": None,
- "dim": 3,
- "target": None,
- "z_index": 0,
- }
-
- def __init__(self, **kwargs):
- Container.__init__(self, **kwargs)
+ def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0, **kwargs):
+ self.color = color
+ self.name = self.__class__.__name__ if name is None else name
+ self.dim = dim
+ self.target = target
+ self.z_index = z_index
self.point_hash = None
self.submobjects = []
self.color = Color(self.color)
- if self.name is None:
- self.name = self.__class__.__name__
self.updaters = []
self.updating_suspended = False
self.reset_points()
self.generate_points()
self.init_colors()
+ Container.__init__(self, **kwargs)
def __repr__(self):
return str(self.name)
@@ -214,7 +209,7 @@ class Mobject(Container):
def generate_target(self, use_deepcopy=False):
self.target = None # Prevent exponential explosion
if use_deepcopy:
- self.target = self.deepcopy()
+ self.target = copy.deepcopy(self)
else:
self.target = self.copy()
return self.target
diff --git a/manim/mobject/number_line.py b/manim/mobject/number_line.py
index 4571f76c5..28d332e4e 100644
--- a/manim/mobject/number_line.py
+++ b/manim/mobject/number_line.py
@@ -12,7 +12,6 @@ from ..mobject.geometry import Line
from ..mobject.numbers import DecimalNumber
from ..mobject.types.vectorized_mobject import VGroup
from ..utils.bezier import interpolate
-from ..utils.config_ops import digest_config
from ..utils.config_ops import merge_dicts_recursively
from ..utils.simple_functions import fdiv
from ..utils.space_ops import normalize
@@ -20,44 +19,69 @@ from ..utils.color import LIGHT_GREY
class NumberLine(Line):
- CONFIG = {
- "color": LIGHT_GREY,
- "unit_size": 1,
- "width": None, # overrides unit_size if a value is passed
- "include_ticks": True,
- "tick_size": 0.1,
- "tick_frequency": 1,
+ def __init__(
+ self,
+ color=LIGHT_GREY,
+ unit_size=1,
+ width=None,
+ include_ticks=True,
+ tick_size=0.1,
+ tick_frequency=1,
# Defaults to value near x_min s.t. 0 is a tick
# TODO, rename this
- "leftmost_tick": None,
+ leftmost_tick=None,
# Change name
- "numbers_with_elongated_ticks": [0],
- "include_numbers": False,
- "numbers_to_show": None,
- "longer_tick_multiple": 2,
- "number_at_center": 0,
- "number_scale_val": 0.75,
- "label_direction": DOWN,
- "line_to_number_buff": MED_SMALL_BUFF,
- "include_tip": False,
- "tip_width": 0.25,
- "tip_height": 0.25,
- "add_start": 0, # extend number line by this amount at its starting point
- "add_end": 0, # extend number line by this amount at its end point
- "decimal_number_config": {
- "num_decimal_places": 0,
- },
- "exclude_zero_from_default_numbers": False,
- }
-
- def __init__(self, **kwargs):
- self.x_min = -config["frame_x_radius"]
- self.x_max = config["frame_x_radius"]
- digest_config(self, kwargs)
- start = self.unit_size * self.x_min * RIGHT
- end = self.unit_size * self.x_max * RIGHT
+ numbers_with_elongated_ticks=[0],
+ include_numbers=False,
+ numbers_to_show=None,
+ longer_tick_multiple=2,
+ number_at_center=0,
+ number_scale_val=0.75,
+ label_direction=DOWN,
+ line_to_number_buff=MED_SMALL_BUFF,
+ include_tip=False,
+ tip_width=0.25,
+ tip_height=0.25,
+ add_start=0, # extend number line by this amount at its starting point
+ add_end=0, # extend number line by this amount at its end point
+ decimal_number_config={"num_decimal_places": 0},
+ exclude_zero_from_default_numbers=False,
+ x_min=-config["frame_x_radius"],
+ x_max=config["frame_x_radius"],
+ **kwargs
+ ):
+ self.unit_size = unit_size
+ self.include_ticks = include_ticks
+ self.tick_size = tick_size
+ self.width = width
+ self.tick_frequency = tick_frequency
+ self.leftmost_tick = leftmost_tick
+ self.numbers_with_elongated_ticks = numbers_with_elongated_ticks
+ self.include_numbers = include_numbers
+ self.numbers_to_show = numbers_to_show
+ self.longer_tick_multiple = longer_tick_multiple
+ self.number_at_center = number_at_center
+ self.number_scale_val = number_scale_val
+ self.label_direction = label_direction
+ self.line_to_number_buff = line_to_number_buff
+ self.include_tip = include_tip
+ self.tip_width = tip_width
+ self.tip_height = tip_height
+ self.add_start = add_start
+ self.add_end = add_end
+ self.decimal_number_config = decimal_number_config
+ self.exclude_zero_from_default_numbers = exclude_zero_from_default_numbers
+ self.x_min = x_min
+ self.x_max = x_max
+
+ start = unit_size * self.x_min * RIGHT
+ end = unit_size * self.x_max * RIGHT
Line.__init__(
- self, start - self.add_start * RIGHT, end + self.add_end * RIGHT, **kwargs
+ self,
+ start=start - add_start * RIGHT,
+ end=end + add_end * RIGHT,
+ color=color,
+ **kwargs,
)
if self.width is not None:
self.set_width(self.width)
@@ -171,7 +195,6 @@ class NumberLine(Line):
if direction is None:
direction = self.label_direction
buff = buff or self.line_to_number_buff
-
num_mob = DecimalNumber(number, **number_config)
num_mob.scale(scale_val)
num_mob.next_to(self.number_to_point(number), direction=direction, buff=buff)
@@ -194,17 +217,25 @@ class NumberLine(Line):
class UnitInterval(NumberLine):
- CONFIG = {
- "unit_size": 6,
- "tick_frequency": 0.1,
- "numbers_with_elongated_ticks": [0, 1],
- "number_at_center": 0.5,
- "decimal_number_config": {
+ def __init__(
+ self,
+ unit_size=6,
+ tick_frequency=0.1,
+ numbers_with_elongated_ticks=[0, 1],
+ number_at_center=0.5,
+ decimal_number_config={
"num_decimal_places": 1,
},
- }
-
- def __init__(self, **kwargs):
- NumberLine.__init__(self, **kwargs)
- self.x_min = 0
- self.x_max = 1
+ **kwargs
+ ):
+ NumberLine.__init__(
+ self,
+ unit_size=unit_size,
+ tick_frequency=tick_frequency,
+ numbers_with_elongated_ticks=numbers_with_elongated_ticks,
+ number_at_center=number_at_center,
+ decimal_number_config=decimal_number_config,
+ x_min=0,
+ x_max=1,
+ **kwargs,
+ )
diff --git a/manim/mobject/numbers.py b/manim/mobject/numbers.py
index 6bfb1a1d5..beaffb1fe 100644
--- a/manim/mobject/numbers.py
+++ b/manim/mobject/numbers.py
@@ -40,21 +40,43 @@ class DecimalNumber(VMobject):
"""
- CONFIG = {
- "num_decimal_places": 2,
- "include_sign": False,
- "group_with_commas": True,
- "digit_to_digit_buff": 0.05,
- "show_ellipsis": False,
- "unit": None, # Aligned to bottom unless it starts with "^"
- "include_background_rectangle": False,
- "edge_to_fix": LEFT,
- }
-
- def __init__(self, number=0, **kwargs):
+ def __init__(
+ self,
+ number=0,
+ num_decimal_places=2,
+ include_sign=False,
+ group_with_commas=True,
+ digit_to_digit_buff=0.05,
+ show_ellipsis=False,
+ unit=None, # Aligned to bottom unless it starts with "^"
+ include_background_rectangle=False,
+ edge_to_fix=LEFT,
+ **kwargs
+ ):
super().__init__(**kwargs)
self.number = number
- self.initial_config = kwargs
+ self.num_decimal_places = num_decimal_places
+ self.include_sign = include_sign
+ self.group_with_commas = group_with_commas
+ self.digit_to_digit_buff = digit_to_digit_buff
+ self.show_ellipsis = show_ellipsis
+ self.unit = unit
+ self.include_background_rectangle = include_background_rectangle
+ self.edge_to_fix = edge_to_fix
+
+ self.initial_config = kwargs.copy()
+ self.initial_config.update(
+ {
+ "num_decimal_places": num_decimal_places,
+ "include_sign": include_sign,
+ "group_with_commas": group_with_commas,
+ "digit_to_digit_buff": digit_to_digit_buff,
+ "show_ellipsis": show_ellipsis,
+ "unit": unit,
+ "include_background_rectangle": include_background_rectangle,
+ "edge_to_fix": edge_to_fix,
+ }
+ )
if isinstance(number, complex):
formatter = self.get_complex_formatter()
@@ -144,7 +166,7 @@ class DecimalNumber(VMobject):
)
def set_value(self, number, **config):
- full_config = dict(self.CONFIG)
+ full_config = dict()
full_config.update(self.initial_config)
full_config.update(config)
new_decimal = DecimalNumber(number, **full_config)
@@ -170,9 +192,10 @@ class DecimalNumber(VMobject):
class Integer(DecimalNumber):
- CONFIG = {
- "num_decimal_places": 0,
- }
+ def __init__(self, number=0, num_decimal_places=0, **kwargs):
+ DecimalNumber.__init__(
+ self, number=number, num_decimal_places=num_decimal_places, **kwargs
+ )
def get_value(self):
return int(np.round(super().get_value()))
@@ -187,7 +210,7 @@ class Variable(VMobject):
----------
var : Union[:class:`int`, :class:`float`]
The python variable you need to keep track of and display.
- label : Union[:class:`str`, :class:`~.Tex`, :class:`~.MathTex`, :class:`~.Text`, :class:`~.TexSymbol`, :class:`~.SingleStringMathTex`, :class:`~.MathTexFromPresetString`]
+ label : Union[:class:`str`, :class:`~.Tex`, :class:`~.MathTex`, :class:`~.Text`, :class:`~.TexSymbol`, :class:`~.SingleStringMathTex`]
The label for your variable, for example ``x = ...``. To use math mode, for e.g.
subscripts, superscripts, etc. simply pass in a raw string.
var_type : Union[:class:`DecimalNumber`, :class:`Integer`], optional
@@ -200,7 +223,7 @@ class Variable(VMobject):
Attributes
----------
- label : Union[:class:`str`, :class:`~.Tex`, :class:`~.MathTex`, :class:`~.Text`, :class:`~.TexSymbol`, :class:`~.SingleStringMathTex`, :class:`~.MathTexFromPresetString`]
+ label : Union[:class:`str`, :class:`~.Tex`, :class:`~.MathTex`, :class:`~.Text`, :class:`~.TexSymbol`, :class:`~.SingleStringMathTex`]
The label for your variable, for example ``x = ...``.
tracker : :class:`~.ValueTracker`
Useful in updating the value of your variable on-screen.
diff --git a/manim/mobject/probability.py b/manim/mobject/probability.py
index f8ab706d7..667cfbf81 100644
--- a/manim/mobject/probability.py
+++ b/manim/mobject/probability.py
@@ -27,16 +27,26 @@ EPSILON = 0.0001
class SampleSpace(Rectangle):
- CONFIG = {
- "height": 3,
- "width": 3,
- "fill_color": DARK_GREY,
- "fill_opacity": 1,
- "stroke_width": 0.5,
- "stroke_color": LIGHT_GREY,
- ##
- "default_label_scale_val": 1,
- }
+ def __init__(
+ self,
+ height=3,
+ width=3,
+ fill_color=DARK_GREY,
+ fill_opacity=1,
+ stroke_width=0.5,
+ stroke_color=LIGHT_GREY,
+ default_label_scale_val=1,
+ ):
+ Rectangle.__init__(
+ self,
+ height=height,
+ width=width,
+ fill_color=fill_color,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ stroke_color=stroke_color,
+ )
+ self.default_label_scale_val = default_label_scale_val
def add_title(self, title="Sample space", buff=MED_SMALL_BUFF):
# TODO, should this really exist in SampleSpaceScene
@@ -147,23 +157,37 @@ class SampleSpace(Rectangle):
class BarChart(VGroup):
- CONFIG = {
- "height": 4,
- "width": 6,
- "n_ticks": 4,
- "tick_width": 0.2,
- "label_y_axis": True,
- "y_axis_label_height": 0.25,
- "max_value": 1,
- "bar_colors": [BLUE, YELLOW],
- "bar_fill_opacity": 0.8,
- "bar_stroke_width": 3,
- "bar_names": [],
- "bar_label_scale_val": 0.75,
- }
-
- def __init__(self, values, **kwargs):
+ def __init__(
+ self,
+ values,
+ height=4,
+ width=6,
+ n_ticks=4,
+ tick_width=0.2,
+ label_y_axis=True,
+ y_axis_label_height=0.25,
+ max_value=1,
+ bar_colors=[BLUE, YELLOW],
+ bar_fill_opacity=0.8,
+ bar_stroke_width=3,
+ bar_names=[],
+ bar_label_scale_val=0.75,
+ **kwargs
+ ):
VGroup.__init__(self, **kwargs)
+ self.height = height
+ self.width = width
+ self.n_ticks = n_ticks
+ self.tick_width = tick_width
+ self.label_y_axis = label_y_axis
+ self.y_axis_label_height = y_axis_label_height
+ self.max_value = max_value
+ self.bar_colors = bar_colors
+ self.bar_fill_opacity = bar_fill_opacity
+ self.bar_stroke_width = bar_stroke_width
+ self.bar_names = bar_names
+ self.bar_label_scale_val = bar_label_scale_val
+
if self.max_value is None:
self.max_value = max(values)
diff --git a/manim/mobject/shape_matchers.py b/manim/mobject/shape_matchers.py
index 24a761e6b..25ef29f47 100644
--- a/manim/mobject/shape_matchers.py
+++ b/manim/mobject/shape_matchers.py
@@ -9,34 +9,39 @@ from ..mobject.geometry import Rectangle
from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.types.vectorized_mobject import VMobject
from ..utils.color import Color, YELLOW, BLACK, RED
-from ..utils.config_ops import digest_config
class SurroundingRectangle(Rectangle):
- CONFIG = {
- "color": YELLOW,
- "buff": SMALL_BUFF,
- }
-
- def __init__(self, mobject, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, mobject, color=YELLOW, buff=SMALL_BUFF, **kwargs):
+ self.color = color
+ self.buff = buff
kwargs["width"] = mobject.get_width() + 2 * self.buff
kwargs["height"] = mobject.get_height() + 2 * self.buff
- Rectangle.__init__(self, **kwargs)
+ Rectangle.__init__(self, color=color, **kwargs)
self.move_to(mobject)
class BackgroundRectangle(SurroundingRectangle):
- CONFIG = {
- "color": BLACK,
- "stroke_width": 0,
- "stroke_opacity": 0,
- "fill_opacity": 0.75,
- "buff": 0,
- }
-
- def __init__(self, mobject, **kwargs):
- SurroundingRectangle.__init__(self, mobject, **kwargs)
+ def __init__(
+ self,
+ mobject,
+ color=BLACK,
+ stroke_width=0,
+ stroke_opacity=0,
+ fill_opacity=0.75,
+ buff=0,
+ **kwargs
+ ):
+ SurroundingRectangle.__init__(
+ self,
+ mobject,
+ color=color,
+ stroke_width=stroke_width,
+ stroke_opacity=stroke_opacity,
+ fill_opacity=fill_opacity,
+ buff=buff,
+ **kwargs
+ )
self.original_fill_opacity = self.fill_opacity
def pointwise_become_partial(self, mobject, a, b):
@@ -66,12 +71,9 @@ class BackgroundRectangle(SurroundingRectangle):
class Cross(VGroup):
- CONFIG = {
- "stroke_color": RED,
- "stroke_width": 6,
- }
-
- def __init__(self, mobject, **kwargs):
+ def __init__(self, mobject, stroke_color=RED, stroke_width=6, **kwargs):
+ self.stroke_color = stroke_color
+ self.stroke_width = stroke_width
VGroup.__init__(
self,
Line(UP + LEFT, DOWN + RIGHT),
@@ -82,11 +84,7 @@ class Cross(VGroup):
class Underline(Line):
- CONFIG = {
- "buff": SMALL_BUFF,
- }
-
- def __init__(self, mobject, **kwargs):
- super().__init__(LEFT, RIGHT, **kwargs)
+ def __init__(self, mobject, buff=SMALL_BUFF, **kwargs):
+ super().__init__(LEFT, RIGHT, buff=buff, **kwargs)
self.match_width(mobject)
self.next_to(mobject, DOWN, buff=self.buff)
diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py
index 997e0911d..3a7ce3a0f 100644
--- a/manim/mobject/svg/brace.py
+++ b/manim/mobject/svg/brace.py
@@ -13,7 +13,6 @@ from ...mobject.svg.tex_mobject import MathTex
from ...mobject.svg.tex_mobject import Tex
from ...mobject.types.vectorized_mobject import VMobject
from ...mobject.geometry import Line
-from ...utils.config_ops import digest_config
from ...utils.space_ops import get_norm
@@ -48,16 +47,21 @@ class Brace(MathTex):
"""
- CONFIG = {
- "buff": 0.2,
- "width_multiplier": 2,
- "max_num_quads": 15,
- "min_num_quads": 0,
- "background_stroke_width": 0,
- }
-
- def __init__(self, mobject, direction=DOWN, **kwargs):
- digest_config(self, kwargs, locals())
+ def __init__(
+ self,
+ mobject,
+ direction=DOWN,
+ buff=0.2,
+ width_multiplier=2,
+ max_num_quads=15,
+ min_num_quads=0,
+ background_stroke_width=0,
+ **kwargs
+ ):
+ self.width_multiplier = width_multiplier
+ self.max_num_quads = max_num_quads
+ self.min_num_quads = min_num_quads
+ self.buff = buff
angle = -np.arctan2(*direction[:2]) + np.pi
mobject.rotate(-angle, about_point=ORIGIN)
left = mobject.get_corner(DOWN + LEFT)
@@ -71,7 +75,9 @@ class Brace(MathTex):
self.max_num_quads,
)
tex_string = "\\underbrace{%s}" % (num_quads * "\\qquad")
- MathTex.__init__(self, tex_string, **kwargs)
+ MathTex.__init__(
+ self, tex_string, background_stroke_width=background_stroke_width, **kwargs
+ )
self.tip_point_index = np.argmin(self.get_all_points()[:, 1])
self.stretch_to_fit_width(target_width)
self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)
@@ -110,12 +116,17 @@ class Brace(MathTex):
class BraceLabel(VMobject):
- CONFIG = {
- "label_constructor": MathTex,
- "label_scale": 1,
- }
-
- def __init__(self, obj, text, brace_direction=DOWN, **kwargs):
+ def __init__(
+ self,
+ obj,
+ text,
+ brace_direction=DOWN,
+ label_constructor=MathTex,
+ label_scale=1,
+ **kwargs
+ ):
+ self.label_constructor = label_constructor
+ self.label_scale = label_scale
VMobject.__init__(self, **kwargs)
self.brace_direction = brace_direction
if isinstance(obj, list):
@@ -159,7 +170,8 @@ class BraceLabel(VMobject):
class BraceText(BraceLabel):
- CONFIG = {"label_constructor": Tex}
+ def __init__(self, obj, text, label_constructor=Tex, **kwargs):
+ super().__init__(obj, text, label_constructor=label_constructor, **kwargs)
class BraceBetweenPoints(Brace):
diff --git a/manim/mobject/svg/code_mobject.py b/manim/mobject/svg/code_mobject.py
index a4a1f8efe..d9e4efe4a 100644
--- a/manim/mobject/svg/code_mobject.py
+++ b/manim/mobject/svg/code_mobject.py
@@ -126,34 +126,57 @@ class Code(VGroup):
"""
# tuples in the form (name, aliases, filetypes, mimetypes)
- # 'language' of CONFIG is aliases or short names
+ # 'language' is aliases or short names
# For more information about pygments.lexers visit https://pygments.org/docs/lexers/
# from pygments.lexers import get_all_lexers
# all_lexers = get_all_lexers()
styles_list = list(get_all_styles())
# For more information about pygments.styles visit https://pygments.org/docs/styles/
- CONFIG = {
- "tab_width": 3,
- "line_spacing": 0.3,
- "scale_factor": 0.5,
- "font": "Monospac821 BT",
- "stroke_width": 0,
- "margin": 0.3,
- "indentation_chars": " ",
- "background": "rectangle", # or window
- "background_stroke_width": 1,
- "background_stroke_color": WHITE,
- "corner_radius": 0.2,
- "insert_line_no": True,
- "line_no_from": 1,
- "line_no_buff": 0.4,
- "style": "vim",
- "language": None,
- "generate_html_file": False,
- }
-
- def __init__(self, file_name=None, **kwargs):
- VGroup.__init__(self, **kwargs)
+
+ def __init__(
+ self,
+ file_name=None,
+ tab_width=3,
+ line_spacing=0.3,
+ scale_factor=0.5,
+ font="Monospac821 BT",
+ stroke_width=0,
+ margin=0.3,
+ indentation_chars=" ",
+ background="rectangle", # or window
+ background_stroke_width=1,
+ background_stroke_color=WHITE,
+ corner_radius=0.2,
+ insert_line_no=True,
+ line_no_from=1,
+ line_no_buff=0.4,
+ style="vim",
+ language=None,
+ generate_html_file=False,
+ **kwargs
+ ):
+ VGroup.__init__(
+ self,
+ stroke_width=stroke_width,
+ background_stroke_color=background_stroke_color,
+ background_stroke_width=background_stroke_width,
+ **kwargs
+ )
+ self.tab_width = tab_width
+ self.line_spacing = line_spacing
+ self.scale_factor = scale_factor
+ self.font = font
+ self.margin = margin
+ self.indentation_chars = indentation_chars
+ self.background = background
+ self.corner_radius = corner_radius
+ self.insert_line_no = insert_line_no
+ self.line_no_from = line_no_from
+ self.line_no_buff = line_no_buff
+ self.style = style
+ self.language = language
+ self.generate_html_file = generate_html_file
+
self.file_name = file_name or self.file_name
self.ensure_valid_file()
self.style = self.style.lower()
diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py
index dde7d5940..b5cf62839 100644
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@ -20,8 +20,6 @@ from ...mobject.geometry import RoundedRectangle
from ...mobject.types.vectorized_mobject import VGroup
from ...mobject.types.vectorized_mobject import VMobject
from ...utils.color import *
-from ...utils.config_ops import digest_config
-from ...utils.config_ops import digest_locals
def string_to_numbers(num_string):
@@ -72,23 +70,26 @@ class SVGMobject(VMobject):
Specifies the opacity of the image. `1` is opaque, `0` is transparent. Defaults to `1`.
"""
- CONFIG = {
- "should_center": True,
- "height": 2,
- "width": None,
- # Must be filled in in a subclass, or when called
- "file_name": None,
- "unpack_groups": True, # if False, creates a hierarchy of VGroups
- "stroke_width": DEFAULT_STROKE_WIDTH,
- "fill_opacity": 1.0,
- # "fill_color" : LIGHT_GREY,
- }
-
- def __init__(self, file_name=None, **kwargs):
- digest_config(self, kwargs)
+ def __init__(
+ self,
+ file_name=None,
+ should_center=True,
+ height=2,
+ width=None,
+ unpack_groups=True, # if False, creates a hierarchy of VGroups
+ stroke_width=DEFAULT_STROKE_WIDTH,
+ fill_opacity=1.0,
+ **kwargs
+ ):
self.file_name = file_name or self.file_name
self.ensure_valid_file()
- VMobject.__init__(self, **kwargs)
+ self.should_center = should_center
+ self.height = height
+ self.width = width
+ self.unpack_groups = unpack_groups
+ VMobject.__init__(
+ self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
+ )
self.move_into_position()
def ensure_valid_file(self):
@@ -520,7 +521,7 @@ class SVGMobject(VMobject):
class VMobjectFromSVGPathstring(VMobject):
def __init__(self, path_string, **kwargs):
- digest_locals(self)
+ self.path_string = path_string
VMobject.__init__(self, **kwargs)
def get_path_commands(self):
diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.py
index ae73b84d8..435e9f5eb 100644
--- a/manim/mobject/svg/tex_mobject.py
+++ b/manim/mobject/svg/tex_mobject.py
@@ -162,7 +162,6 @@ __all__ = [
"MathTex",
"Tex",
"BulletedList",
- "MathTexFromPresetString",
"Title",
"TexMobject",
"TextMobject",
@@ -179,7 +178,6 @@ from ...mobject.svg.svg_mobject import SVGMobject
from ...mobject.svg.svg_mobject import VMobjectFromSVGPathstring
from ...mobject.types.vectorized_mobject import VGroup
from ...mobject.types.vectorized_mobject import VectorizedPoint
-from ...utils.config_ops import digest_config
from ...utils.strings import split_string_list_to_isolate_substrings
from ...utils.tex_file_writing import tex_to_svg_file
from ...utils.color import BLACK
@@ -205,22 +203,31 @@ class SingleStringMathTex(SVGMobject):
SingleStringMathTex('Test')
"""
- CONFIG = {
- "stroke_width": 0,
- "fill_opacity": 1.0,
- "background_stroke_width": 0,
- "background_stroke_color": BLACK,
- "should_center": True,
- "height": None,
- "organize_left_to_right": False,
- "tex_environment": "align*",
- "tex_template": None,
- }
-
- def __init__(self, tex_string, **kwargs):
- digest_config(self, kwargs)
- if self.tex_template is None:
- self.tex_template = kwargs.get("tex_template", config["tex_template"])
+ def __init__(
+ self,
+ tex_string,
+ stroke_width=0,
+ fill_opacity=1.0,
+ background_stroke_width=0,
+ background_stroke_color=BLACK,
+ should_center=True,
+ height=None,
+ organize_left_to_right=False,
+ tex_environment="align*",
+ tex_template=None,
+ **kwargs,
+ ):
+ self.stroke_width = stroke_width
+ self.fill_opacity = fill_opacity
+ self.background_stroke_width = background_stroke_width
+ self.background_stroke_color = background_stroke_color
+ self.should_center = should_center
+ self.height = height
+ self.organize_left_to_right = organize_left_to_right
+ self.tex_environment = tex_environment
+ if tex_template is None:
+ tex_template = config["tex_template"]
+ self.tex_template = tex_template
assert isinstance(tex_string, str)
self.tex_string = tex_string
@@ -229,7 +236,17 @@ class SingleStringMathTex(SVGMobject):
environment=self.tex_environment,
tex_template=self.tex_template,
)
- SVGMobject.__init__(self, file_name=file_name, **kwargs)
+ SVGMobject.__init__(
+ self,
+ file_name=file_name,
+ should_center=self.should_center,
+ stroke_width=self.stroke_width,
+ height=self.height,
+ fill_opacity=self.fill_opacity,
+ background_stroke_width=self.background_stroke_width,
+ background_stroke_color=self.background_stroke_color,
+ **kwargs,
+ )
if self.height is None:
self.scale(TEX_MOB_SCALE_FACTOR)
if self.organize_left_to_right:
@@ -322,7 +339,7 @@ class SingleStringMathTex(SVGMobject):
class MathTex(SingleStringMathTex):
- """A string compiled with LaTeX in math mode.
+ r"""A string compiled with LaTeX in math mode.
Examples
--------
@@ -343,23 +360,34 @@ class MathTex(SingleStringMathTex):
"""
- CONFIG = {
- "arg_separator": " ",
- "substrings_to_isolate": [],
- "tex_to_color_map": {},
- "tex_environment": "align*",
- }
-
- def __init__(self, *tex_strings, **kwargs):
- digest_config(self, kwargs)
+ def __init__(
+ self,
+ *tex_strings,
+ arg_separator=" ",
+ substrings_to_isolate=None,
+ tex_to_color_map=None,
+ tex_environment="align*",
+ **kwargs,
+ ):
+ self.tex_template = kwargs.pop("tex_template", config["tex_template"])
+ self.arg_separator = arg_separator
+ self.substrings_to_isolate = (
+ [] if substrings_to_isolate is None else substrings_to_isolate
+ )
+ self.tex_to_color_map = tex_to_color_map
+ if self.tex_to_color_map is None:
+ self.tex_to_color_map = {}
+ self.tex_environment = tex_environment
tex_strings = self.break_up_tex_strings(tex_strings)
self.tex_strings = tex_strings
SingleStringMathTex.__init__(
- self, self.arg_separator.join(tex_strings), **kwargs
+ self,
+ self.arg_separator.join(tex_strings),
+ tex_environment=self.tex_environment,
+ tex_template=self.tex_template,
+ **kwargs,
)
- config = dict(self.CONFIG)
- config.update(kwargs)
- self.break_up_by_substrings(config)
+ self.break_up_by_substrings()
self.set_color_by_tex_to_color_map(self.tex_to_color_map)
if self.organize_left_to_right:
@@ -378,7 +406,7 @@ class MathTex(SingleStringMathTex):
split_list = [s for s in split_list if s != ""]
return split_list
- def break_up_by_substrings(self, config):
+ def break_up_by_substrings(self):
"""
Reorganize existing submojects one layer
deeper based on the structure of tex_strings (as a list
@@ -387,7 +415,11 @@ class MathTex(SingleStringMathTex):
new_submobjects = []
curr_index = 0
for tex_string in self.tex_strings:
- sub_tex_mob = SingleStringMathTex(tex_string, **config)
+ sub_tex_mob = SingleStringMathTex(
+ tex_string,
+ tex_environment=self.tex_environment,
+ tex_template=self.tex_template,
+ )
num_submobs = len(sub_tex_mob.submobjects)
new_index = curr_index + num_submobs
if num_submobs == 0:
@@ -465,21 +497,30 @@ class Tex(MathTex):
"""
- CONFIG = {
- "arg_separator": "",
- "tex_environment": "center",
- }
+ def __init__(
+ self, *tex_strings, arg_separator="", tex_environment="center", **kwargs
+ ):
+ MathTex.__init__(
+ self,
+ *tex_strings,
+ arg_separator=arg_separator,
+ tex_environment=tex_environment,
+ **kwargs,
+ )
class BulletedList(Tex):
- CONFIG = {
- "buff": MED_LARGE_BUFF,
- "dot_scale_factor": 2,
- # Have to include because of handle_multiple_args implementation
- "tex_environment": None,
- }
-
- def __init__(self, *items, **kwargs):
+ def __init__(
+ self,
+ *items,
+ buff=MED_LARGE_BUFF,
+ dot_scale_factor=2,
+ tex_environment=None,
+ **kwargs,
+ ):
+ self.buff = buff
+ self.dot_scale_factor = dot_scale_factor
+ self.tex_environment = tex_environment
line_separated_items = [s + "\\\\" for s in items]
Tex.__init__(self, *line_separated_items, **kwargs)
for part in self:
@@ -503,29 +544,20 @@ class BulletedList(Tex):
other_part.set_fill(opacity=opacity)
-class MathTexFromPresetString(MathTex):
- CONFIG = {
- # To be filled by subclasses
- "tex": None,
- "color": None,
- }
-
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
- MathTex.__init__(self, self.tex, **kwargs)
- self.set_color(self.color)
-
-
class Title(Tex):
- CONFIG = {
- "scale_factor": 1,
- "include_underline": True,
- # This will override underline_width
- "match_underline_width_to_text": False,
- "underline_buff": MED_SMALL_BUFF,
- }
-
- def __init__(self, *text_parts, **kwargs):
+ def __init__(
+ self,
+ *text_parts,
+ scale_factor=1,
+ include_underline=True,
+ match_underline_width_to_text=False,
+ underline_buff=MED_SMALL_BUFF,
+ **kwargs,
+ ):
+ self.scale_factor = scale_factor
+ self.include_underline = include_underline
+ self.match_underline_width_to_text = match_underline_width_to_text
+ self.underline_buff = underline_buff
Tex.__init__(self, *text_parts, **kwargs)
self.underline_width = config["frame_width"] - 2
self.scale(self.scale_factor)
diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.py
index 1755e16a9..6c7bae094 100644
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@ -60,7 +60,6 @@ from ...constants import *
from ...mobject.geometry import Dot
from ...mobject.svg.svg_mobject import SVGMobject
from ...mobject.types.vectorized_mobject import VGroup
-from ...utils.config_ops import digest_config
from ...utils.color import WHITE
TEXT_MOB_SCALE_FACTOR = 0.05
@@ -134,33 +133,61 @@ class CairoText(SVGMobject):
"""
- CONFIG = {
+ def __init__(
+ self,
+ text,
# Mobject
- "color": WHITE,
- "height": None,
- "width": None,
- "fill_opacity": 1,
- "stroke_width": 0,
- "should_center": True,
- "unpack_groups": True,
+ color=WHITE,
+ height=None,
+ width=None,
+ fill_opacity=1,
+ stroke_width=0,
+ should_center=True,
+ unpack_groups=True,
# Text
- "font": "",
- "gradient": None,
- "line_spacing": -1,
- "size": 1,
- "slant": NORMAL,
- "weight": NORMAL,
- "t2c": {},
- "t2f": {},
- "t2g": {},
- "t2s": {},
- "t2w": {},
- "tab_width": 4,
- }
-
- def __init__(self, text, **config):
- self.full2short(config)
- digest_config(self, config)
+ font="",
+ gradient=None,
+ line_spacing=-1,
+ size=1,
+ slant=NORMAL,
+ weight=NORMAL,
+ t2c=None,
+ t2f=None,
+ t2g=None,
+ t2s=None,
+ t2w=None,
+ tab_width=4,
+ **kwargs,
+ ):
+ # self.full2short(config)
+ if t2c is None:
+ t2c = {}
+ if t2f is None:
+ t2f = {}
+ if t2g is None:
+ t2g = {}
+ if t2s is None:
+ t2s = {}
+ if t2w is None:
+ t2w = {}
+ # If long form arguments are present, they take precedence
+ t2c = kwargs.pop("text2color", t2c)
+ t2f = kwargs.pop("text2font", t2f)
+ t2g = kwargs.pop("text2gradient", t2g)
+ t2s = kwargs.pop("text2slant", t2s)
+ t2w = kwargs.pop("text2weight", t2w)
+ self.t2c = t2c
+ self.t2f = t2f
+ self.t2g = t2g
+ self.t2s = t2s
+ self.t2w = t2w
+ self.font = font
+ self.gradient = gradient
+ self.line_spacing = line_spacing
+ self.size = size
+ self.slant = slant
+ self.weight = weight
+ self.tab_width = tab_width
self.original_text = text
text_without_tabs = text
if text.find("\t") != -1:
@@ -172,7 +199,14 @@ class CairoText(SVGMobject):
self.line_spacing = self.size + self.size * self.line_spacing
file_name = self.text2svg()
self.remove_last_M(file_name)
- SVGMobject.__init__(self, file_name, **config)
+ SVGMobject.__init__(
+ self,
+ file_name,
+ height=height,
+ width=width,
+ unpack_groups=unpack_groups,
+ color=color ** config,
+ )
self.text = text
self.submobjects = [*self.gen_chars()]
self.chars = VGroup(*self.submobjects)
@@ -251,18 +285,18 @@ class CairoText(SVGMobject):
index = text.find(word, index + len(word))
return indexes
- def full2short(self, config):
- for kwargs in [config, self.CONFIG]:
- if kwargs.__contains__("text2color"):
- kwargs["t2c"] = kwargs.pop("text2color")
- if kwargs.__contains__("text2font"):
- kwargs["t2f"] = kwargs.pop("text2font")
- if kwargs.__contains__("text2gradient"):
- kwargs["t2g"] = kwargs.pop("text2gradient")
- if kwargs.__contains__("text2slant"):
- kwargs["t2s"] = kwargs.pop("text2slant")
- if kwargs.__contains__("text2weight"):
- kwargs["t2w"] = kwargs.pop("text2weight")
+ # def full2short(self, config_args):
+ # for kwargs in [config_args]:
+ # if kwargs.__contains__("text2color"):
+ # kwargs["t2c"] = kwargs.pop("text2color")
+ # if kwargs.__contains__("text2font"):
+ # kwargs["t2f"] = kwargs.pop("text2font")
+ # if kwargs.__contains__("text2gradient"):
+ # kwargs["t2g"] = kwargs.pop("text2gradient")
+ # if kwargs.__contains__("text2slant"):
+ # kwargs["t2s"] = kwargs.pop("text2slant")
+ # if kwargs.__contains__("text2weight"):
+ # kwargs["t2w"] = kwargs.pop("text2weight")
def set_color_by_t2c(self, t2c=None):
t2c = t2c if t2c else self.t2c
@@ -427,12 +461,9 @@ class Paragraph(VGroup):
"""
- CONFIG = {
- "line_spacing": -1,
- "alignment": None,
- }
-
- def __init__(self, *text, **config):
+ def __init__(self, *text, line_spacing=-1, alignment=None, **config):
+ self.line_spacing = line_spacing
+ self.alignment = alignment
VGroup.__init__(self, **config)
lines_str = "\n".join(list(text))
@@ -690,37 +721,64 @@ class Text(SVGMobject):
"""
- CONFIG = {
+ def __init__(
+ self,
+ text: str,
+ fill_opacity=1,
+ stroke_width=0,
+ color=WHITE,
+ size=1,
+ line_spacing=-1,
+ font="",
+ slant=NORMAL,
+ weight=NORMAL,
+ t2c=None,
+ t2f=None,
+ t2g=None,
+ t2s=None,
+ t2w=None,
+ gradient=None,
+ tab_width=4,
# Mobject
- "color": WHITE,
- "height": None,
- "width": None,
- "fill_opacity": 1,
- "stroke_width": 0,
- "should_center": True,
- "unpack_groups": True,
- # Text
- "font": "",
- "gradient": None,
- "line_spacing": -1,
- "size": 1,
- "slant": NORMAL,
- "weight": NORMAL,
- "t2c": {},
- "t2f": {},
- "t2g": {},
- "t2s": {},
- "t2w": {},
- "tab_width": 4,
- }
-
- def __init__(self, text: str, **config): # pylint: disable=redefined-outer-name
+ height=None,
+ width=None,
+ should_center=True,
+ unpack_groups=True,
+ **kwargs,
+ ):
logger.info(
"Text now uses Pango for rendering. "
"In case of problems, the old implementation is available as CairoText."
)
- self.full2short(config)
- digest_config(self, config)
+ self.size = size
+ self.line_spacing = line_spacing
+ self.font = font
+ self.slant = slant
+ self.weight = weight
+ self.gradient = gradient
+ self.tab_width = tab_width
+ if t2c is None:
+ t2c = {}
+ if t2f is None:
+ t2f = {}
+ if t2g is None:
+ t2g = {}
+ if t2s is None:
+ t2s = {}
+ if t2w is None:
+ t2w = {}
+ # If long form arguments are present, they take precedence
+ t2c = kwargs.pop("text2color", t2c)
+ t2f = kwargs.pop("text2font", t2f)
+ t2g = kwargs.pop("text2gradient", t2g)
+ t2s = kwargs.pop("text2slant", t2s)
+ t2w = kwargs.pop("text2weight", t2w)
+ self.t2c = t2c
+ self.t2f = t2f
+ self.t2g = t2g
+ self.t2s = t2s
+ self.t2w = t2w
+
self.original_text = text
text_without_tabs = text
if text.find("\t") != -1:
@@ -732,7 +790,18 @@ class Text(SVGMobject):
self.line_spacing = self.size + self.size * self.line_spacing
file_name = self.text2svg()
self.remove_last_M(file_name)
- SVGMobject.__init__(self, file_name, **config)
+ SVGMobject.__init__(
+ self,
+ file_name,
+ color=color,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ height=height,
+ width=width,
+ should_center=should_center,
+ unpack_groups=unpack_groups,
+ **kwargs,
+ )
self.text = text
self.chars = VGroup(*self.submobjects)
self.text = text_without_tabs.replace(" ", "").replace("\n", "")
@@ -790,25 +859,24 @@ class Text(SVGMobject):
index = text.find(word, index + len(word))
return indexes
- def full2short(self, config): # pylint: disable=redefined-outer-name
- """Internally used function. Fomats some exapansion to short forms.
- text2color -> t2c
- text2font -> t2f
- text2gradient -> t2g
- text2slant -> t2s
- text2weight -> t2w
- """
- for kwargs in [config, self.CONFIG]:
- if "text2color" in kwargs:
- kwargs["t2c"] = kwargs.pop("text2color")
- if "text2font" in kwargs:
- kwargs["t2f"] = kwargs.pop("text2font")
- if "text2gradient" in kwargs:
- kwargs["t2g"] = kwargs.pop("text2gradient")
- if "text2slant" in kwargs:
- kwargs["t2s"] = kwargs.pop("text2slant")
- if "text2weight" in kwargs:
- kwargs["t2w"] = kwargs.pop("text2weight")
+ # def full2short(self, kwargs):
+ # """Internally used function. Fomats some exapansion to short forms.
+ # text2color -> t2c
+ # text2font -> t2f
+ # text2gradient -> t2g
+ # text2slant -> t2s
+ # text2weight -> t2w
+ # """
+ # if "text2color" in kwargs:
+ # self.t2c = kwargs.pop("text2color")
+ # if "text2font" in kwargs:
+ # self.t2f = kwargs.pop("text2font")
+ # if "text2gradient" in kwargs:
+ # self.t2g = kwargs.pop("text2gradient")
+ # if "text2slant" in kwargs:
+ # self.t2s = kwargs.pop("text2slant")
+ # if "text2weight" in kwargs:
+ # self.t2w = kwargs.pop("text2weight")
def set_color_by_t2c(self, t2c=None):
"""Internally used function. Sets colour for specified strings."""
diff --git a/manim/mobject/three_dimensions.py b/manim/mobject/three_dimensions.py
index e904e9c9a..6c41acb9c 100644
--- a/manim/mobject/three_dimensions.py
+++ b/manim/mobject/three_dimensions.py
@@ -14,30 +14,45 @@ from ..utils.color import BLUE_D, BLUE, BLUE_E, LIGHT_GREY
class ThreeDVMobject(VMobject):
- CONFIG = {
- "shade_in_3d": True,
- }
+ def __init__(self, shade_in_3d=True, **kwargs):
+ super().__init__(shade_in_3d=shade_in_3d, **kwargs)
class ParametricSurface(VGroup):
- CONFIG = {
- "u_min": 0,
- "u_max": 1,
- "v_min": 0,
- "v_max": 1,
- "resolution": 32,
- "surface_piece_config": {},
- "fill_color": BLUE_D,
- "fill_opacity": 1.0,
- "checkerboard_colors": [BLUE_D, BLUE_E],
- "stroke_color": LIGHT_GREY,
- "stroke_width": 0.5,
- "should_make_jagged": False,
- "pre_function_handle_to_anchor_scale_factor": 0.00001,
- }
-
- def __init__(self, func, **kwargs):
+ def __init__(
+ self,
+ func,
+ u_min=0,
+ u_max=1,
+ v_min=0,
+ v_max=1,
+ resolution=32,
+ surface_piece_config={},
+ fill_color=BLUE_D,
+ fill_opacity=1.0,
+ checkerboard_colors=[BLUE_D, BLUE_E],
+ stroke_color=LIGHT_GREY,
+ stroke_width=0.5,
+ should_make_jagged=False,
+ pre_function_handle_to_anchor_scale_factor=0.00001,
+ **kwargs
+ ):
VGroup.__init__(self, **kwargs)
+ self.u_min = u_min
+ self.u_max = u_max
+ self.v_min = v_min
+ self.v_max = v_max
+ self.resolution = resolution
+ self.surface_piece_config = surface_piece_config
+ self.fill_color = fill_color
+ self.fill_opacity = fill_opacity
+ self.checkerboard_colors = checkerboard_colors
+ self.stroke_color = stroke_color
+ self.stroke_width = stroke_width
+ self.should_make_jagged = should_make_jagged
+ self.pre_function_handle_to_anchor_scale_factor = (
+ pre_function_handle_to_anchor_scale_factor
+ )
self.func = func
self.setup_in_uv_space()
self.apply_function(lambda p: func(p[0], p[1]))
@@ -105,30 +120,51 @@ class ParametricSurface(VGroup):
class Sphere(ParametricSurface):
- CONFIG = {
- "resolution": (12, 24),
- "radius": 1,
- "u_min": 0.001,
- "u_max": PI - 0.001,
- "v_min": 0,
- "v_max": TAU,
- }
-
- def __init__(self, **kwargs):
- ParametricSurface.__init__(self, self.func, **kwargs)
+ def __init__(
+ self,
+ radius=1,
+ resolution=(12, 24),
+ u_min=0.001,
+ u_max=PI - 0.001,
+ v_min=0,
+ v_max=TAU,
+ **kwargs
+ ):
+ ParametricSurface.__init__(
+ self,
+ self.func,
+ resolution=resolution,
+ u_min=u_min,
+ u_max=u_max,
+ v_min=v_min,
+ v_max=v_max,
+ **kwargs
+ )
+ self.radius = radius
self.scale(self.radius)
- def func(self, u, v):
+ def func(
+ self, u, v
+ ): # FIXME: An attribute defined in manim.mobject.three_dimensions line 56 hides this method
return np.array([np.cos(v) * np.sin(u), np.sin(v) * np.sin(u), np.cos(u)])
class Cube(VGroup):
- CONFIG = {
- "fill_opacity": 0.75,
- "fill_color": BLUE,
- "stroke_width": 0,
- "side_length": 2,
- }
+ def __init__(
+ self,
+ side_length=2,
+ fill_opacity=0.75,
+ fill_color=BLUE,
+ stroke_width=0,
+ **kwargs
+ ):
+ self.side_length = side_length
+ super().__init__(
+ fill_color=fill_color,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ **kwargs
+ )
def generate_points(self):
for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
@@ -144,7 +180,9 @@ class Cube(VGroup):
class Prism(Cube):
- CONFIG = {"dimensions": [3, 2, 1]}
+ def __init__(self, dimensions=[3, 2, 1], **kwargs):
+ self.dimensions = dimensions
+ Cube.__init__(self, **kwargs)
def generate_points(self):
Cube.generate_points(self)
diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py
index 7125c4d5e..039f9285c 100644
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -14,7 +14,6 @@ from ...mobject.mobject import Mobject
from ...mobject.shape_matchers import SurroundingRectangle
from ...utils.bezier import interpolate
from ...utils.color import color_to_int_rgb, WHITE
-from ...utils.config_ops import digest_config
from ...utils.images import get_full_raster_image_path
from manim.constants import QUALITIES, DEFAULT_QUALITY
@@ -30,14 +29,9 @@ class AbstractImageMobject(Mobject):
This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
"""
- CONFIG = {
- "pixel_array_dtype": "uint8",
- }
-
- def __init__(self, scale_to_resolution, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, scale_to_resolution, pixel_array_dtype="uint8", **kwargs):
+ self.pixel_array_dtype = pixel_array_dtype
self.scale_to_resolution = scale_to_resolution
-
Mobject.__init__(self, **kwargs)
def get_pixel_array(self):
@@ -70,11 +64,10 @@ class ImageMobject(AbstractImageMobject):
"""Displays an Image from a numpy array or a file.
Parameters
- ----------
- scale_to_resolution : :class:`int`
- At this resolution the image is placed pixel by pixel onto the screen, so it will look the sharpest and best.
- This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
-
+ ----------
+ scale_to_resolution : :class:`int`
+ At this resolution the image is placed pixel by pixel onto the screen, so it will look the sharpest and best.
+ This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
Example
@@ -91,24 +84,23 @@ class ImageMobject(AbstractImageMobject):
"""
- CONFIG = {
- "invert": False,
- "image_mode": "RGBA",
- }
-
def __init__(
self,
filename_or_array,
scale_to_resolution=QUALITIES[DEFAULT_QUALITY]["pixel_height"],
+ invert=False,
+ image_mode="RGBA",
**kwargs,
):
- digest_config(self, kwargs)
+ self.invert = invert
+ self.image_mode = image_mode
if isinstance(filename_or_array, (str, pathlib.PurePath)):
path = get_full_raster_image_path(filename_or_array)
image = Image.open(path).convert(self.image_mode)
self.pixel_array = np.array(image)
else:
self.pixel_array = np.array(filename_or_array)
+ self.pixel_array_dtype = kwargs.get("pixel_array_dtype", "uint8")
self.change_to_rgba_array()
if self.invert:
self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3]
@@ -200,16 +192,15 @@ class ImageMobject(AbstractImageMobject):
class ImageMobjectFromCamera(AbstractImageMobject):
- CONFIG = {
- "default_display_frame_config": {
- "stroke_width": 3,
- "stroke_color": WHITE,
- "buff": 0,
- }
- }
-
- def __init__(self, camera, **kwargs):
+ def __init__(self, camera, default_display_frame_config=None, **kwargs):
self.camera = camera
+ if default_display_frame_config is None:
+ default_display_frame_config = {
+ "stroke_width": 3,
+ "stroke_color": WHITE,
+ "buff": 0,
+ }
+ self.default_display_frame_config = default_display_frame_config
self.pixel_array = self.camera.pixel_array
AbstractImageMobject.__init__(self, scale_to_resolution=False, **kwargs)
diff --git a/manim/mobject/types/point_cloud_mobject.py b/manim/mobject/types/point_cloud_mobject.py
index f092de718..954772ff3 100644
--- a/manim/mobject/types/point_cloud_mobject.py
+++ b/manim/mobject/types/point_cloud_mobject.py
@@ -9,15 +9,14 @@ from ...utils.bezier import interpolate
from ...utils.color import color_gradient, YELLOW_C, WHITE, BLACK, YELLOW
from ...utils.color import color_to_rgba
from ...utils.color import rgba_to_color
-from ...utils.config_ops import digest_config
from ...utils.iterables import stretch_array_to_length
from ...utils.space_ops import get_norm
class PMobject(Mobject):
- CONFIG = {
- "stroke_width": DEFAULT_STROKE_WIDTH,
- }
+ def __init__(self, stroke_width=DEFAULT_STROKE_WIDTH, **kwargs):
+ self.stroke_width = stroke_width
+ super().__init__(**kwargs)
def reset_points(self):
self.rgbas = np.zeros((0, 4))
@@ -180,14 +179,10 @@ class PMobject(Mobject):
# TODO, Make the two implementations bellow non-redundant
class Mobject1D(PMobject):
- CONFIG = {
- "density": DEFAULT_POINT_DENSITY_1D,
- }
-
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, density=DEFAULT_POINT_DENSITY_1D, **kwargs):
+ self.density = density
self.epsilon = 1.0 / self.density
- Mobject.__init__(self, **kwargs)
+ PMobject.__init__(self, **kwargs)
def add_line(self, start, end, color=None):
start, end = list(map(np.array, [start, end]))
@@ -201,14 +196,10 @@ class Mobject1D(PMobject):
class Mobject2D(PMobject):
- CONFIG = {
- "density": DEFAULT_POINT_DENSITY_2D,
- }
-
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, density=DEFAULT_POINT_DENSITY_2D, **kwargs):
+ self.density = density
self.epsilon = 1.0 / self.density
- Mobject.__init__(self, **kwargs)
+ PMobject.__init__(self, **kwargs)
class PGroup(PMobject):
@@ -220,15 +211,24 @@ class PGroup(PMobject):
class PointCloudDot(Mobject1D):
- CONFIG = {
- "radius": 0.075,
- "stroke_width": 2,
- "density": DEFAULT_POINT_DENSITY_1D,
- "color": YELLOW,
- }
-
- def __init__(self, center=ORIGIN, **kwargs):
- Mobject1D.__init__(self, **kwargs)
+ def __init__(
+ self,
+ center=ORIGIN,
+ radius=0.075,
+ stroke_width=2,
+ density=DEFAULT_POINT_DENSITY_1D,
+ color=YELLOW,
+ **kwargs
+ ):
+ self.radius = radius
+ Mobject1D.__init__(
+ self,
+ radius=radius,
+ stroke_width=stroke_width,
+ density=density,
+ color=color,
+ **kwargs
+ )
self.shift(center)
def generate_points(self):
@@ -242,10 +242,6 @@ class PointCloudDot(Mobject1D):
class Point(PMobject):
- CONFIG = {
- "color": BLACK,
- }
-
- def __init__(self, location=ORIGIN, **kwargs):
- PMobject.__init__(self, **kwargs)
+ def __init__(self, location=ORIGIN, color=BLACK, **kwargs):
+ PMobject.__init__(self, color=color, **kwargs)
self.add_points([location])
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py
index 7c2b00af3..ed60a2338 100644
--- a/manim/mobject/types/vectorized_mobject.py
+++ b/manim/mobject/types/vectorized_mobject.py
@@ -42,37 +42,59 @@ from ...utils.space_ops import shoelace_direction
class VMobject(Mobject):
- CONFIG = {
- "fill_color": None,
- "fill_opacity": 0.0,
- "stroke_color": None,
- "stroke_opacity": 1.0,
- "stroke_width": DEFAULT_STROKE_WIDTH,
+ def __init__(
+ self,
+ fill_color=None,
+ fill_opacity=0.0,
+ stroke_color=None,
+ stroke_opacity=1.0,
+ stroke_width=DEFAULT_STROKE_WIDTH,
# The purpose of background stroke is to have
# something that won't overlap the fill, e.g.
# For text against some textured background
- "background_stroke_color": BLACK,
- "background_stroke_opacity": 1.0,
- "background_stroke_width": 0,
+ background_stroke_color=BLACK,
+ background_stroke_opacity=1.0,
+ background_stroke_width=0,
# When a color c is set, there will be a second color
# computed based on interpolating c to WHITE by with
# sheen_factor, and the display will gradient to this
# secondary color in the direction of sheen_direction.
- "sheen_factor": 0.0,
- "sheen_direction": UL,
+ sheen_factor=0.0,
+ sheen_direction=UL,
# Indicates that it will not be displayed, but
# that it should count in parent mobject's path
- "close_new_points": False,
- "pre_function_handle_to_anchor_scale_factor": 0.01,
- "make_smooth_after_applying_functions": False,
- "background_image_file": None,
- "shade_in_3d": False,
+ close_new_points=False,
+ pre_function_handle_to_anchor_scale_factor=0.01,
+ make_smooth_after_applying_functions=False,
+ background_image_file=None,
+ shade_in_3d=False,
# This is within a pixel
# TODO, do we care about accounting for
# varying zoom levels?
- "tolerance_for_point_equality": 1e-6,
- "n_points_per_cubic_curve": 4,
- }
+ tolerance_for_point_equality=1e-6,
+ n_points_per_cubic_curve=4,
+ **kwargs
+ ):
+ self.fill_color = fill_color
+ self.fill_opacity = fill_opacity
+ self.stroke_color = stroke_color
+ self.stroke_opacity = stroke_opacity
+ self.stroke_width = stroke_width
+ self.background_stroke_color = background_stroke_color
+ self.background_stroke_opacity = background_stroke_opacity
+ self.background_stroke_width = background_stroke_width
+ self.sheen_factor = sheen_factor
+ self.sheen_direction = sheen_direction
+ self.close_new_points = close_new_points
+ self.pre_function_handle_to_anchor_scale_factor = (
+ pre_function_handle_to_anchor_scale_factor
+ )
+ self.make_smooth_after_applying_functions = make_smooth_after_applying_functions
+ self.background_image_file = background_image_file
+ self.shade_in_3d = shade_in_3d
+ self.tolerance_for_point_equality = tolerance_for_point_equality
+ self.n_points_per_cubic_curve = n_points_per_cubic_curve
+ Mobject.__init__(self, **kwargs)
def get_group_class(self):
return VGroup
@@ -617,7 +639,7 @@ class VMobject(Mobject):
Generator to not materialize a list or np.array needlessly.
"""
- nppcc = VMobject.CONFIG["n_points_per_cubic_curve"]
+ nppcc = self.n_points_per_cubic_curve
remainder = len(points) % nppcc
points = points[: len(points) - remainder]
return (points[i : i + nppcc] for i in range(0, len(points), nppcc))
@@ -1018,7 +1040,7 @@ class VDict(VMobject):
especially when there are a lot of mobjects in the
:class:`VDict`. Defaults to False.
kwargs : Any
- Other arguments to be passed to `Mobject` or the CONFIG.
+ Other arguments to be passed to `Mobject`.
Attributes
----------
@@ -1331,16 +1353,25 @@ class VDict(VMobject):
class VectorizedPoint(VMobject):
- CONFIG = {
- "color": BLACK,
- "fill_opacity": 0,
- "stroke_width": 0,
- "artificial_width": 0.01,
- "artificial_height": 0.01,
- }
-
- def __init__(self, location=ORIGIN, **kwargs):
- VMobject.__init__(self, **kwargs)
+ def __init__(
+ self,
+ location=ORIGIN,
+ color=BLACK,
+ fill_opacity=0,
+ stroke_width=0,
+ artificial_width=0.01,
+ artificial_height=0.01,
+ **kwargs
+ ):
+ self.artificial_width = artificial_width
+ self.artificial_height = artificial_height
+ VMobject.__init__(
+ self,
+ color=color,
+ fill_opacity=fill_opacity,
+ stroke_width=stroke_width,
+ **kwargs
+ )
self.set_points(np.array([location]))
def get_width(self):
@@ -1368,11 +1399,12 @@ class CurvesAsSubmobjects(VGroup):
class DashedVMobject(VMobject):
- CONFIG = {"num_dashes": 15, "positive_space_ratio": 0.5, "color": WHITE}
-
- def __init__(self, vmobject, **kwargs):
- VMobject.__init__(self, **kwargs)
- num_dashes = self.num_dashes
+ def __init__(
+ self, vmobject, num_dashes=15, positive_space_ratio=0.5, color=WHITE, **kwargs
+ ):
+ self.num_dashes = num_dashes
+ self.positive_space_ratio = positive_space_ratio
+ VMobject.__init__(self, color=color, **kwargs)
ps_ratio = self.positive_space_ratio
if num_dashes > 0:
# End points of the unit interval for division
diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.py
index 7ac3e439d..0c27b82ee 100644
--- a/manim/mobject/vector_field.py
+++ b/manim/mobject/vector_field.py
@@ -31,7 +31,6 @@ from ..utils.bezier import inverse_interpolate
from ..utils.bezier import interpolate
from ..utils.color import color_to_rgb, BLUE_E, GREEN, YELLOW, RED, BLUE, WHITE
from ..utils.color import rgb_to_color
-from ..utils.config_ops import digest_config
from ..utils.rate_functions import linear
from ..utils.simple_functions import sigmoid
from ..utils.space_ops import get_norm
@@ -139,19 +138,30 @@ def move_points_along_vector_field(mobject, func):
class VectorField(VGroup):
- CONFIG = {
- "delta_x": 0.5,
- "delta_y": 0.5,
- "min_magnitude": 0,
- "max_magnitude": 2,
- "colors": DEFAULT_SCALAR_FIELD_COLORS,
+ def __init__(
+ self,
+ func,
+ delta_x=0.5,
+ delta_y=0.5,
+ min_magnitude=0,
+ max_magnitude=2,
+ colors=DEFAULT_SCALAR_FIELD_COLORS,
# Takes in actual norm, spits out displayed norm
- "length_func": lambda norm: 0.45 * sigmoid(norm),
- "opacity": 1.0,
- "vector_config": {},
- }
-
- def __init__(self, func, **kwargs):
+ length_func=lambda norm: 0.45 * sigmoid(norm),
+ opacity=1.0,
+ vector_config=None,
+ **kwargs
+ ):
+ self.delta_x = delta_x
+ self.delta_y = delta_y
+ self.min_magnitude = min_magnitude
+ self.max_magnitude = max_magnitude
+ self.colors = colors
+ self.length_func = length_func
+ self.opacity = opacity
+ if vector_config is None:
+ vector_config = {}
+ self.vector_config = vector_config
VGroup.__init__(self, **kwargs)
self.x_min = int(np.floor(-config["frame_width"] / 2))
self.x_max = int(np.ceil(config["frame_width"] / 2))
@@ -185,43 +195,63 @@ class VectorField(VGroup):
class StreamLines(VGroup):
- CONFIG = {
- # TODO, this is an awkward way to inherit
- # defaults to a method.
- "start_points_generator_config": {},
+ def __init__(
+ self,
+ func,
+ start_points_generator_config={},
# Config for choosing start points
- "x_min": -8,
- "x_max": 8,
- "y_min": -5,
- "y_max": 5,
- "delta_x": 0.5,
- "delta_y": 0.5,
- "n_repeats": 1,
- "noise_factor": None,
+ x_min=-8,
+ x_max=8,
+ y_min=-5,
+ y_max=5,
+ delta_x=0.5,
+ delta_y=0.5,
+ n_repeats=1,
+ noise_factor=None,
# Config for drawing lines
- "dt": 0.05,
- "virtual_time": 3,
- "n_anchors_per_line": 100,
- "stroke_width": 1,
- "stroke_color": WHITE,
- "color_by_arc_length": True,
+ dt=0.05,
+ virtual_time=3,
+ n_anchors_per_line=100,
+ stroke_width=1,
+ stroke_color=WHITE,
+ color_by_arc_length=True,
# Min and max arc lengths meant to define
# the color range, should color_by_arc_length be True
- "min_arc_length": 0,
- "max_arc_length": 12,
- "color_by_magnitude": False,
+ min_arc_length=0,
+ max_arc_length=12,
+ color_by_magnitude=False,
# Min and max magnitudes meant to define
# the color range, should color_by_magnitude be True
- "min_magnitude": 0.5,
- "max_magnitude": 1.5,
- "colors": DEFAULT_SCALAR_FIELD_COLORS,
- "cutoff_norm": 15,
- }
-
- def __init__(self, func, **kwargs):
- VGroup.__init__(self, **kwargs)
+ min_magnitude=0.5,
+ max_magnitude=1.5,
+ colors=DEFAULT_SCALAR_FIELD_COLORS,
+ cutoff_norm=15,
+ **kwargs
+ ):
+ VGroup.__init__(
+ self, stroke_color=stroke_color, stroke_width=stroke_width, **kwargs
+ )
self.func = func
- dt = self.dt
+ self.start_points_generator_config = start_points_generator_config
+ self.x_min = x_min
+ self.x_max = x_max
+ self.y_min = y_min
+ self.y_max = y_max
+ self.delta_x = delta_x
+ self.delta_y = delta_y
+ self.n_repeats = n_repeats
+ self.noise_factor = noise_factor
+ self.dt = dt
+ self.virtual_time = virtual_time
+ self.n_anchors_per_line = n_anchors_per_line
+ self.color_by_arc_length = color_by_arc_length
+ self.min_arc_length = min_arc_length
+ self.max_arc_length = max_arc_length
+ self.color_by_magnitude = color_by_magnitude
+ self.min_magnitude = min_magnitude
+ self.max_magnitude = max_magnitude
+ self.colors = colors
+ self.cutoff_norm = cutoff_norm
start_points = self.get_start_points(**self.start_points_generator_config)
for point in start_points:
@@ -284,10 +314,10 @@ class StreamLines(VGroup):
# varying in response to a changing vector field, and still
# animate the resulting flow
class ShowPassingFlashWithThinningStrokeWidth(AnimationGroup):
- CONFIG = {"n_segments": 10, "time_width": 0.1, "remover": True}
-
- def __init__(self, vmobject, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, vmobject, n_segments=10, time_width=0.1, remover=True, **kwargs):
+ self.n_segments = n_segments
+ self.time_width = time_width
+ self.remover = remover
max_stroke_width = vmobject.get_stroke_width()
max_time_width = kwargs.pop("time_width", self.time_width)
AnimationGroup.__init__(
@@ -309,19 +339,23 @@ class ShowPassingFlashWithThinningStrokeWidth(AnimationGroup):
# TODO, this is untested after turning it from a
# ContinualAnimation into a VGroup
class AnimatedStreamLines(VGroup):
- CONFIG = {
- "lag_range": 4,
- "line_anim_class": ShowPassingFlash,
- "line_anim_config": {
+ def __init__(
+ self,
+ stream_lines,
+ lag_range=4,
+ line_anim_class=ShowPassingFlash,
+ line_anim_config={
"run_time": 4,
"rate_func": linear,
"time_width": 0.3,
},
- }
-
- def __init__(self, stream_lines, **kwargs):
+ **kwargs
+ ):
VGroup.__init__(self, **kwargs)
self.stream_lines = stream_lines
+ self.lag_range = lag_range
+ self.line_anim_class = line_anim_class
+ self.line_anim_config = line_anim_config
for line in stream_lines:
line.anim = self.line_anim_class(line, **self.line_anim_config)
line.anim.begin()
diff --git a/manim/renderer/cairo_renderer.py b/manim/renderer/cairo_renderer.py
index 98d0e881f..cb3bf18ca 100644
--- a/manim/renderer/cairo_renderer.py
+++ b/manim/renderer/cairo_renderer.py
@@ -54,22 +54,10 @@ class CairoRenderer:
def __init__(self, camera_class=None, skip_animations=False, **kwargs):
# All of the following are set to EITHER the value passed via kwargs,
# OR the value stored in the global config dict at the time of
- # _instance construction_. Before, they were in the CONFIG dict, which
- # is a class attribute and is defined at the time of _class
- # definition_. This did not allow for creating two Cameras with
- # different configurations in the same session.
+ # _instance construction_.
self.file_writer = None
- self.video_quality_config = {}
- for attr in [
- "pixel_height",
- "pixel_width",
- "frame_height",
- "frame_width",
- "frame_rate",
- ]:
- self.video_quality_config[attr] = kwargs.get(attr, config[attr])
camera_cls = camera_class if camera_class is not None else Camera
- self.camera = camera_cls(self.video_quality_config)
+ self.camera = camera_cls()
self.original_skipping_status = skip_animations
self.skip_animations = skip_animations
self.animations_hashes = []
@@ -79,7 +67,6 @@ class CairoRenderer:
def init(self, scene):
self.file_writer = SceneFileWriter(
self,
- self.video_quality_config,
scene.__class__.__name__,
)
diff --git a/manim/scene/graph_scene.py b/manim/scene/graph_scene.py
index 0ae87a7f8..afccf8795 100644
--- a/manim/scene/graph_scene.py
+++ b/manim/scene/graph_scene.py
@@ -7,12 +7,15 @@ Examples
:save_last_frame:
class FunctionPlotWithLabbeledYAxis(GraphScene):
- CONFIG = {
- "y_min": 0,
- "y_max": 100,
- "y_axis_config": {"tick_frequency": 10},
- "y_labeled_nums": np.arange(0, 100, 10)
- }
+ def __init__(self, **kwargs):
+ GraphScene.__init__(
+ self,
+ y_min=0,
+ y_max=100,
+ y_axis_config={"tick_frequency": 10},
+ y_labeled_nums=np.arange(0, 100, 10),
+ **kwargs
+ )
def construct(self):
self.setup_axes()
@@ -72,37 +75,69 @@ from ..utils.space_ops import angle_of_vector
class GraphScene(Scene):
- CONFIG = {
- "x_min": -1,
- "x_max": 10,
- "x_axis_width": 9,
- "x_leftmost_tick": None, # Change if different from x_min
- "x_labeled_nums": None,
- "x_axis_label": "$x$",
- "y_min": -1,
- "y_max": 10,
- "y_axis_height": 6,
- "y_bottom_tick": None, # Change if different from y_min
- "y_labeled_nums": None,
- "y_axis_label": "$y$",
- "axes_color": GREY,
- "graph_origin": 2.5 * DOWN + 4 * LEFT,
- "exclude_zero_label": True,
- "default_graph_colors": [BLUE, GREEN, YELLOW],
- "default_derivative_color": GREEN,
- "default_input_color": YELLOW,
- "default_riemann_start_color": BLUE,
- "default_riemann_end_color": GREEN,
- "area_opacity": 0.8,
- "num_rects": 50,
- "include_tip": False, # add tip at the end of the axes
- "x_axis_visibility": True, # show or hide the x axis
- "y_axis_visibility": True, # show or hide the y axis
- "x_label_position": UP + RIGHT, # where to place the label of the x axis
- "y_label_position": UP + RIGHT, # where to place the label of the y axis
- "x_axis_config": {},
- "y_axis_config": {},
- }
+ def __init__(
+ self,
+ x_min=-1,
+ x_max=10,
+ x_axis_width=9,
+ x_leftmost_tick=None, # Change if different from x_min
+ x_labeled_nums=None,
+ x_axis_label="$x$",
+ y_min=-1,
+ y_max=10,
+ y_axis_height=6,
+ y_bottom_tick=None, # Change if different from y_min
+ y_labeled_nums=None,
+ y_axis_label="$y$",
+ axes_color=GREY,
+ graph_origin=2.5 * DOWN + 4 * LEFT,
+ exclude_zero_label=True,
+ default_graph_colors=[BLUE, GREEN, YELLOW],
+ default_derivative_color=GREEN,
+ default_input_color=YELLOW,
+ default_riemann_start_color=BLUE,
+ default_riemann_end_color=GREEN,
+ area_opacity=0.8,
+ num_rects=50,
+ include_tip=False, # add tip at the end of the axes
+ x_axis_visibility=True, # show or hide the x axis
+ y_axis_visibility=True, # show or hide the y axis
+ x_label_position=UP + RIGHT, # where to place the label of the x axis
+ y_label_position=UP + RIGHT, # where to place the label of the y axis
+ x_axis_config={},
+ y_axis_config={},
+ **kwargs,
+ ):
+ self.x_min = x_min
+ self.x_max = x_max
+ self.x_axis_width = x_axis_width
+ self.x_leftmost_tick = x_leftmost_tick
+ self.x_labeled_nums = x_labeled_nums
+ self.x_axis_label = x_axis_label
+ self.y_min = y_min
+ self.y_max = y_max
+ self.y_axis_height = y_axis_height
+ self.y_bottom_tick = y_bottom_tick
+ self.y_labeled_nums = y_labeled_nums
+ self.y_axis_label = y_axis_label
+ self.axes_color = axes_color
+ self.graph_origin = graph_origin
+ self.exclude_zero_label = exclude_zero_label
+ self.default_graph_colors = default_graph_colors
+ self.default_derivative_color = default_derivative_color
+ self.default_input_color = default_input_color
+ self.default_riemann_start_color = default_riemann_start_color
+ self.default_riemann_end_color = default_riemann_end_color
+ self.area_opacity = area_opacity
+ self.num_rects = num_rects
+ self.include_tip = include_tip
+ self.x_axis_visibility = x_axis_visibility
+ self.y_axis_visibility = y_axis_visibility
+ self.x_label_position = x_label_position
+ self.y_label_position = y_label_position
+ self.x_axis_config = x_axis_config
+ self.y_axis_config = y_axis_config
+ super().__init__(**kwargs)
def setup(self):
"""
@@ -185,7 +220,6 @@ class GraphScene(Scene):
"leftmost_tick": self.y_bottom_tick,
"numbers_with_elongated_ticks": self.y_labeled_nums,
"color": self.axes_color,
- "line_to_number_vect": LEFT,
"label_direction": LEFT,
"include_tip": self.include_tip,
},
@@ -253,10 +287,13 @@ class GraphScene(Scene):
:save_last_frame:
class SequencePlot(GraphScene):
- CONFIG = {
- "y_axis_label": r"Concentration [\%]",
- "x_axis_label": "Time [s]",
- }
+ def __init__(self, **kwargs):
+ GraphScene.__init__(
+ self,
+ y_axis_label=r"Concentration [\\%]",
+ x_axis_label="Time [s]",
+ **kwargs
+ )
def construct(self):
data = [1, 2, 2, 4, 4, 1, 3]
diff --git a/manim/scene/moving_camera_scene.py b/manim/scene/moving_camera_scene.py
index 9d85e0178..ad4cafe4e 100644
--- a/manim/scene/moving_camera_scene.py
+++ b/manim/scene/moving_camera_scene.py
@@ -91,7 +91,8 @@ class MovingCameraScene(Scene):
:class:`.MovingCamera`
"""
- CONFIG = {"camera_class": MovingCamera}
+ def __init__(self, camera_class=MovingCamera, **kwargs):
+ Scene.__init__(self, camera_class=camera_class, **kwargs)
def setup(self):
"""
diff --git a/manim/scene/reconfigurable_scene.py b/manim/scene/reconfigurable_scene.py
index 7f5d3c21d..226bc3008 100644
--- a/manim/scene/reconfigurable_scene.py
+++ b/manim/scene/reconfigurable_scene.py
@@ -11,9 +11,9 @@ class ReconfigurableScene(Scene):
Note, this seems to no longer work as intented.
"""
- CONFIG = {
- "allow_recursion": True,
- }
+ def __init__(self, allow_recursion=True, **kwargs):
+ Scene.__init__(self, **kwargs)
+ self.allow_recursion = allow_recursion
def setup(self):
self.states = []
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index 23b2d3c21..feced94d6 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -53,14 +53,17 @@ class Scene(Container):
"""
- CONFIG = {
- "camera_class": Camera,
- "always_update_mobjects": False,
- "random_seed": 0,
- }
-
- def __init__(self, renderer=None, **kwargs):
- Container.__init__(self, **kwargs)
+ def __init__(
+ self,
+ renderer=None,
+ camera_class=Camera,
+ always_update_mobjects=False,
+ random_seed=0,
+ **kwargs,
+ ):
+ self.camera_class = camera_class
+ self.always_update_mobjects = always_update_mobjects
+ self.random_seed = random_seed
if renderer is None:
self.renderer = CairoRenderer(
camera_class=self.camera_class,
@@ -77,6 +80,8 @@ class Scene(Container):
random.seed(self.random_seed)
np.random.seed(self.random_seed)
+ Container.__init__(self, **kwargs)
+
@property
def camera(self):
return self.renderer.camera
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index 0804b86d7..2783e5854 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -15,7 +15,6 @@ from pathlib import Path
from .. import config, logger
from ..constants import FFMPEG_BIN, GIF_FILE_EXTENSION
-from ..utils.config_ops import digest_config
from ..utils.file_ops import guarantee_existence
from ..utils.file_ops import add_extension_if_not_present
from ..utils.file_ops import modify_atime
@@ -42,10 +41,8 @@ class SceneFileWriter(object):
"""
- def __init__(self, renderer, video_quality_config, scene_name, **kwargs):
- digest_config(self, kwargs)
+ def __init__(self, renderer, scene_name, **kwargs):
self.renderer = renderer
- self.video_quality_config = video_quality_config
self.stream_lock = False
self.init_output_directories(scene_name)
self.init_audio()
@@ -306,10 +303,13 @@ class SceneFileWriter(object):
"""
while self.stream_lock:
a = datetime.datetime.now()
- self.update_frame()
+ # self.update_frame()
+ self.renderer.update_frame()
n_frames = 1
- frame = self.get_frame()
- self.add_frame(*[frame] * n_frames)
+ # frame = self.get_frame()
+ frame = self.renderer.get_frame()
+ # self.add_frame(*[frame] * n_frames)
+ self.renderer.add_frame(*[frame] * n_frames)
b = datetime.datetime.now()
time_diff = (b - a).total_seconds()
frame_duration = 1 / config["frame_rate"]
diff --git a/manim/scene/three_d_scene.py b/manim/scene/three_d_scene.py
index b7a3119a0..613d5b335 100644
--- a/manim/scene/three_d_scene.py
+++ b/manim/scene/three_d_scene.py
@@ -14,7 +14,6 @@ from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.types.vectorized_mobject import VectorizedPoint
from ..mobject.value_tracker import ValueTracker
from ..scene.scene import Scene
-from ..utils.config_ops import digest_config
from ..utils.config_ops import merge_dicts_recursively
import numpy as np
@@ -25,14 +24,23 @@ class ThreeDScene(Scene):
make it suitable for Three Dimensional Scenes.
"""
- CONFIG = {
- "camera_class": ThreeDCamera,
- "ambient_camera_rotation": None,
- "default_angled_camera_orientation_kwargs": {
- "phi": 70 * DEGREES,
- "theta": -135 * DEGREES,
- },
- }
+ def __init__(
+ self,
+ camera_class=ThreeDCamera,
+ ambient_camera_rotation=None,
+ default_angled_camera_orientation_kwargs=None,
+ **kwargs,
+ ):
+ self.ambient_camera_rotation = ambient_camera_rotation
+ if default_angled_camera_orientation_kwargs is None:
+ default_angled_camera_orientation_kwargs = {
+ "phi": 70 * DEGREES,
+ "theta": -135 * DEGREES,
+ }
+ self.default_angled_camera_orientation_kwargs = (
+ default_angled_camera_orientation_kwargs
+ )
+ super().__init__(camera_class=camera_class, **kwargs)
def set_camera_orientation(self, phi=None, theta=None, distance=None, gamma=None):
"""
@@ -261,7 +269,9 @@ class ThreeDScene(Scene):
Some recognised kwargs are phi, theta, distance, gamma,
which have the same meaning as the parameters in set_camera_orientation.
"""
- config = dict(self.default_camera_orientation_kwargs)
+ config = dict(
+ self.default_camera_orientation_kwargs
+ ) # Where doe this come from?
config.update(kwargs)
self.set_camera_orientation(**config)
@@ -279,10 +289,11 @@ class SpecialThreeDScene(ThreeDScene):
"""
- CONFIG = {
- "cut_axes_at_radius": True,
- "camera_config": {"should_apply_shading": True, "exponential_projection": True},
- "three_d_axes_config": {
+ def __init__(
+ self,
+ cut_axes_at_radius=True,
+ camera_config={"should_apply_shading": True, "exponential_projection": True},
+ three_d_axes_config={
"num_axis_pieces": 1,
"axis_config": {
"unit_size": 2,
@@ -291,22 +302,26 @@ class SpecialThreeDScene(ThreeDScene):
"stroke_width": 2,
},
},
- "sphere_config": {"radius": 2, "resolution": (24, 48)},
- "default_angled_camera_position": {
+ sphere_config={"radius": 2, "resolution": (24, 48)},
+ default_angled_camera_position={
"phi": 70 * DEGREES,
"theta": -110 * DEGREES,
},
# When scene is extracted with -l flag, this
# configuration will override the above configuration.
- "low_quality_config": {
+ low_quality_config={
"camera_config": {"should_apply_shading": False},
"three_d_axes_config": {"num_axis_pieces": 1},
"sphere_config": {"resolution": (12, 24)},
},
- }
-
- def __init__(self, **kwargs):
- digest_config(self, kwargs)
+ **kwargs,
+ ):
+ self.cut_axes_at_radius = cut_axes_at_radius
+ self.camera_config = camera_config
+ self.three_d_axes_config = three_d_axes_config
+ self.sphere_config = sphere_config
+ self.default_angled_camera_position = default_angled_camera_position
+ self.low_quality_config = low_quality_config
if self.renderer.camera_config["pixel_width"] == config["pixel_width"]:
_config = {}
else:
diff --git a/manim/scene/vector_space_scene.py b/manim/scene/vector_space_scene.py
index 60fc34e4a..4d15d1466 100644
--- a/manim/scene/vector_space_scene.py
+++ b/manim/scene/vector_space_scene.py
@@ -49,7 +49,9 @@ Z_COLOR = BLUE_D
# Also, methods I would have thought of as getters, like coords_to_vector, are
# actually doing a lot of animating.
class VectorScene(Scene):
- CONFIG = {"basis_vector_stroke_width": 6}
+ def __init__(self, basis_vector_stroke_width=6, **kwargs):
+ Scene.__init__(self, **kwargs)
+ self.basis_vector_stroke_width = basis_vector_stroke_width
def add_plane(self, animate=False, **kwargs):
"""
@@ -514,10 +516,11 @@ class LinearTransformationScene(VectorScene):
especially suitable for showing Linear Transformations.
"""
- CONFIG = {
- "include_background_plane": True,
- "include_foreground_plane": True,
- "background_plane_kwargs": {
+ def __init__(
+ self,
+ include_background_plane=True,
+ include_foreground_plane=True,
+ background_plane_kwargs={
"color": GREY,
"axis_config": {
"stroke_color": LIGHT_GREY,
@@ -530,17 +533,28 @@ class LinearTransformationScene(VectorScene):
"stroke_width": 1,
},
},
- "show_coordinates": False,
- "show_basis_vectors": True,
- "basis_vector_stroke_width": 6,
- "i_hat_color": X_COLOR,
- "j_hat_color": Y_COLOR,
- "leave_ghost_vectors": False,
- "t_matrix": [[3, 0], [1, 2]],
- }
-
- def __init__(self, **kwargs):
+ show_coordinates=False,
+ show_basis_vectors=True,
+ basis_vector_stroke_width=6,
+ i_hat_color=X_COLOR,
+ j_hat_color=Y_COLOR,
+ leave_ghost_vectors=False,
+ t_matrix=[[3, 0], [1, 2]],
+ **kwargs
+ ):
VectorScene.__init__(self, **kwargs)
+
+ self.include_background_plane = include_background_plane
+ self.include_foreground_plane = include_foreground_plane
+ self.background_plane_kwargs = background_plane_kwargs
+ self.show_coordinates = show_coordinates
+ self.show_basis_vectors = show_basis_vectors
+ self.basis_vector_stroke_width = basis_vector_stroke_width
+ self.i_hat_color = i_hat_color
+ self.j_hat_color = j_hat_color
+ self.leave_ghost_vectors = leave_ghost_vectors
+ self.t_matrix = t_matrix
+
self.foreground_plane_kwargs = {
"x_max": config["frame_width"] / 2,
"x_min": -config["frame_width"] / 2,
diff --git a/manim/scene/zoomed_scene.py b/manim/scene/zoomed_scene.py
index 36fd37e87..fbe73cf20 100644
--- a/manim/scene/zoomed_scene.py
+++ b/manim/scene/zoomed_scene.py
@@ -18,15 +18,19 @@ Examples
.. manim:: ChangingZoomScale
class ChangingZoomScale(ZoomedScene):
- CONFIG = {
- "zoom_factor": 0.3,
- "zoomed_display_height": 1,
- "zoomed_display_width": 3,
- "image_frame_stroke_width": 20,
- "zoomed_camera_config": {
- "default_frame_stroke_width": 3,
- },
- }
+ def __init__(self, **kwargs):
+ ZoomedScene.__init__(
+ self,
+ zoom_factor=0.3,
+ zoomed_display_height=1,
+ zoomed_display_width=3,
+ image_frame_stroke_width=20,
+ zoomed_camera_config={
+ "default_frame_stroke_width": 3,
+ },
+ **kwargs
+ )
+
def construct(self):
dot = Dot().set_color(GREEN)
sq = Circle(fill_opacity=1, radius=0.2).next_to(dot, RIGHT)
@@ -63,23 +67,39 @@ class ZoomedScene(MovingCameraScene):
separately.
"""
- CONFIG = {
- "camera_class": MultiCamera,
- "zoomed_display_height": 3,
- "zoomed_display_width": 3,
- "zoomed_display_center": None,
- "zoomed_display_corner": UP + RIGHT,
- "zoomed_display_corner_buff": DEFAULT_MOBJECT_TO_EDGE_BUFFER,
- "zoomed_camera_config": {
+ def __init__(
+ self,
+ camera_class=MultiCamera,
+ zoomed_display_height=3,
+ zoomed_display_width=3,
+ zoomed_display_center=None,
+ zoomed_display_corner=UP + RIGHT,
+ zoomed_display_corner_buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER,
+ zoomed_camera_config={
"default_frame_stroke_width": 2,
"background_opacity": 1,
},
- "zoomed_camera_image_mobject_config": {},
- "zoomed_camera_frame_starting_position": ORIGIN,
- "zoom_factor": 0.15,
- "image_frame_stroke_width": 3,
- "zoom_activated": False,
- }
+ zoomed_camera_image_mobject_config={},
+ zoomed_camera_frame_starting_position=ORIGIN,
+ zoom_factor=0.15,
+ image_frame_stroke_width=3,
+ zoom_activated=False,
+ **kwargs
+ ):
+ self.zoomed_display_height = zoomed_display_height
+ self.zoomed_display_width = zoomed_display_width
+ self.zoomed_display_center = zoomed_display_center
+ self.zoomed_display_corner = zoomed_display_corner
+ self.zoomed_display_corner_buff = zoomed_display_corner_buff
+ self.zoomed_camera_config = zoomed_camera_config
+ self.zoomed_camera_image_mobject_config = zoomed_camera_image_mobject_config
+ self.zoomed_camera_frame_starting_position = (
+ zoomed_camera_frame_starting_position
+ )
+ self.zoom_factor = zoom_factor
+ self.image_frame_stroke_width = image_frame_stroke_width
+ self.zoom_activated = zoom_activated
+ MovingCameraScene.__init__(self, camera_class=camera_class, **kwargs)
def setup(self):
"""
@@ -88,7 +108,7 @@ class ZoomedScene(MovingCameraScene):
"""
MovingCameraScene.setup(self)
# Initialize camera and display
- zoomed_camera = MovingCamera({}, **self.zoomed_camera_config)
+ zoomed_camera = MovingCamera(**self.zoomed_camera_config)
zoomed_display = ImageMobjectFromCamera(
zoomed_camera, **self.zoomed_camera_image_mobject_config
)
diff --git a/manim/utils/config_ops.py b/manim/utils/config_ops.py
index cde690191..c3e6ac0c8 100644
--- a/manim/utils/config_ops.py
+++ b/manim/utils/config_ops.py
@@ -1,64 +1,14 @@
-"""Utilities required by manim's CONFIG attributes."""
+"""Utilities that mught be useful for configuration dictionaries."""
__all__ = [
- "get_all_descendent_classes",
- "filtered_locals",
- "digest_config",
"merge_dicts_recursively",
- "soft_dict_update",
- "digest_locals",
"DictAsObject",
]
-import inspect
import itertools as it
-def get_all_descendent_classes(Class):
- awaiting_review = [Class]
- result = []
- while awaiting_review:
- Child = awaiting_review.pop()
- awaiting_review += Child.__subclasses__()
- result.append(Child)
- return result
-
-
-def filtered_locals(caller_locals):
- result = caller_locals.copy()
- ignored_local_args = ["self", "kwargs"]
- for arg in ignored_local_args:
- result.pop(arg, caller_locals)
- return result
-
-
-def digest_config(obj, kwargs, caller_locals={}):
- """
- Sets init args and CONFIG values as local variables
-
- The purpose of this function is to ensure that all
- configuration of any object is inheritable, able to
- be easily passed into instantiation, and is attached
- as an attribute of the object.
- """
-
- # Assemble list of CONFIGs from all super classes
- classes_in_hierarchy = [obj.__class__]
- static_configs = []
- while len(classes_in_hierarchy) > 0:
- Class = classes_in_hierarchy.pop()
- classes_in_hierarchy += Class.__bases__
- if hasattr(Class, "CONFIG"):
- static_configs.append(Class.CONFIG)
-
- # Order matters a lot here, first dicts have higher priority
- caller_locals = filtered_locals(caller_locals)
- all_dicts = [kwargs, caller_locals, obj.__dict__]
- all_dicts += static_configs
- obj.__dict__ = merge_dicts_recursively(*reversed(all_dicts))
-
-
def merge_dicts_recursively(*dicts):
"""
Creates a dict whose keyset is the union of all the
@@ -79,24 +29,6 @@ def merge_dicts_recursively(*dicts):
return result
-def soft_dict_update(d1, d2):
- """
- Adds key values pairs of d2 to d1 only when d1 doesn't
- already have that key
- """
- for key, value in list(d2.items()):
- if key not in d1:
- d1[key] = value
-
-
-def digest_locals(obj, keys=None):
- caller_locals = filtered_locals(inspect.currentframe().f_back.f_locals)
- if keys is None:
- keys = list(caller_locals.keys())
- for key in keys:
- setattr(obj, key, caller_locals[key])
-
-
# Occasionally convenient in order to write dict.x instead of more laborious
# (and less in keeping with all other attr accesses) dict["x"]
diff --git a/manim/utils/rate_functions.py b/manim/utils/rate_functions.py
index d5e270c77..60870b10d 100644
--- a/manim/utils/rate_functions.py
+++ b/manim/utils/rate_functions.py
@@ -32,8 +32,8 @@ There are primarily 3 kinds of standard easing functions:
label3 = Tex("Ease In Out").next_to(line3, RIGHT)
self.play(
- FadeIn(VGroup(line1, line2, line3),
- FadeIn(VGroup(dot1, dot2, dot3))),
+ FadeIn(VGroup(line1, line2, line3)),
+ FadeIn(VGroup(dot1, dot2, dot3)),
Write(VGroup(label1, label2, label3)),
)
self.play(
diff --git a/manim/utils/tex.py b/manim/utils/tex.py
index 6f4218143..8301a6c16 100644
--- a/manim/utils/tex.py
+++ b/manim/utils/tex.py
@@ -209,7 +209,7 @@ class TexTemplate:
return begin, end
def get_texcode_for_expression_in_env(self, expression, environment):
- """Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}
+ r"""Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}
Parameters
----------
diff --git a/tests/test_graphical_units/test_axes.py b/tests/test_graphical_units/test_axes.py
index 45a23e162..6364b8989 100644
--- a/tests/test_graphical_units/test_axes.py
+++ b/tests/test_graphical_units/test_axes.py
@@ -6,30 +6,27 @@ from ..utils.GraphicalUnitTester import GraphicalUnitTester
class AxesTest(GraphScene):
- CONFIG = {
- "x_min": -5,
- "x_max": 5,
- "y_min": -3,
- "y_max": 3,
- "x_axis_config": {
+ def construct(self):
+ self.x_min = -5
+ self.x_max = 5
+ self.y_min = -3
+ self.y_max = 3
+ self.x_axis_config = {
"add_start": 0.5,
"add_end": 0.5,
"include_tip": True,
- },
- "y_axis_config": {
+ }
+ self.y_axis_config = {
"add_start": 0.25,
"add_end": 0.5,
"include_tip": True,
- },
- "x_axis_visibility": True,
- "y_axis_visibility": True,
- "y_label_position": UP,
- "x_label_position": RIGHT,
- "graph_origin": ORIGIN,
- "axes_color": WHITE,
- }
-
- def construct(self):
+ }
+ self.x_axis_visibility = True
+ self.y_axis_visibility = True
+ self.y_label_position = UP
+ self.x_label_position = RIGHT
+ self.graph_origin = ORIGIN
+ self.axes_color = WHITE
self.setup_axes(animate=True)
diff --git a/tests/test_graphical_units/test_graph.py b/tests/test_graphical_units/test_graph.py
index 9b14f5b3f..67e302e8c 100644
--- a/tests/test_graphical_units/test_graph.py
+++ b/tests/test_graphical_units/test_graph.py
@@ -6,12 +6,15 @@ from ..utils.GraphicalUnitTester import GraphicalUnitTester
class PlotFunctions(GraphScene):
- CONFIG = {
- "graph_origin": ORIGIN,
- "function_color": RED,
- "axes_color": GREEN,
- "x_labeled_nums": range(-10, 12, 2),
- }
+ def __init__(self, **kwargs):
+ GraphScene.__init__(
+ self,
+ graph_origin=ORIGIN,
+ function_color=RED,
+ axes_color=GREEN,
+ x_labeled_nums=range(-10, 12, 2),
+ **kwargs
+ )
def construct(self):
self.x_min = -10
diff --git a/tests/test_renderer.py b/tests/test_renderer.py
deleted file mode 100644
index 04458b2da..000000000
--- a/tests/test_renderer.py
+++ /dev/null
@@ -1,24 +0,0 @@
-import pytest
-from manim import CairoRenderer, Camera, tempconfig, config
-
-
-def test_renderer():
- """Test that CairoRenderer instances initialize to the correct config."""
- # by default, use the config
- assert (
- CairoRenderer(Camera).video_quality_config["frame_width"]
- == config["frame_width"]
- )
- # init args override config
- assert (
- CairoRenderer(Camera, frame_width=10).video_quality_config["frame_width"] == 10
- )
-
- # if config changes, reflect those changes
- with tempconfig({"frame_width": 100}):
- assert CairoRenderer(Camera).video_quality_config["frame_width"] == 100
- # ..init args still override new config
- assert (
- CairoRenderer(Camera, frame_width=10).video_quality_config["frame_width"]
- == 10
- )
diff --git a/tests/utils/GraphicalUnitTester.py b/tests/utils/GraphicalUnitTester.py
index e5680b9b1..3c191320a 100644
--- a/tests/utils/GraphicalUnitTester.py
+++ b/tests/utils/GraphicalUnitTester.py
@@ -113,6 +113,7 @@ class GraphicalUnitTester:
ax.set_title("Differences summary : (red = got, green = expected)")
plt.show()
+ plt.savefig(f"{self.scene}.png")
def test(self, show_diff=False):
"""Compare pre-rendered frame to the frame rendered during the test."""