Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import types
import warnings
from functools import reduce
from functools import partialmethod, reduce
from math import ceil
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -94,6 +94,7 @@ def __init_subclass__(cls, **kwargs):
Callable[["Mobject"], "Animation"],
] = {}
cls._add_intrinsic_animation_overrides()
cls._original__init__ = cls.__init__

def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0):
self.color = Color(color) if color else None
Expand Down Expand Up @@ -180,6 +181,51 @@ def add_animation_override(
f"{override_func.__qualname__}.",
)

@classmethod
def change_default(cls, **kwargs):
"""Changes the default values of keyword arguments.

If this method is called without any additional keyword
arguments, the original default values of the initialization
method of this class are restored.

Parameters
----------

kwargs
Passing any keyword argument will update the default
values of the keyword arguments of the initialization
function of this class.

Examples
--------

::

>>> from manim import Square, GREEN
>>> Square.change_default(color=GREEN, fill_opacity=0.25)
>>> s = Square(); s.color, s.fill_opacity
(<Color #83c167>, 0.25)
>>> Square.change_default()
>>> s = Square(); s.color, s.fill_opacity
(<Color white>, 0.0)

.. manim:: ChangedDefaultTextcolor
:save_last_frame:

config.background_color = WHITE

class ChangedDefaultTextcolor(Scene):
def construct(self):
Text.change_default(color=BLACK)
self.add(Text("Changing default values is easy!"))

"""
if kwargs:
cls.__init__ = partialmethod(cls.__init__, **kwargs)
else:
cls.__init__ = cls._original__init__

@property
def animate(self):
"""Used to animate the application of a method.
Expand Down
14 changes: 13 additions & 1 deletion manim/mobject/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import itertools as it
import random
import sys
from functools import wraps
from functools import partialmethod, wraps
from math import ceil
from typing import Iterable, Optional, Tuple, Union

Expand Down Expand Up @@ -121,6 +121,18 @@ def __init__(
if self.depth_test:
self.apply_depth_test()

@classmethod
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
cls._original__init__ = cls.__init__

@classmethod
def change_default(cls, **kwargs):
if kwargs:
cls.__init__ = partialmethod(cls.__init__, **kwargs)
else:
cls.__init__ = cls._original__init__

def __str__(self):
return self.__class__.__name__

Expand Down