|
11 | 11 | import sys |
12 | 12 | import types |
13 | 13 | import warnings |
14 | | -from functools import reduce |
| 14 | +from functools import partialmethod, reduce |
15 | 15 | from math import ceil |
16 | 16 | from pathlib import Path |
17 | 17 | from typing import ( |
@@ -89,6 +89,7 @@ def __init_subclass__(cls, **kwargs): |
89 | 89 | Callable[["Mobject"], "Animation"], |
90 | 90 | ] = {} |
91 | 91 | cls._add_intrinsic_animation_overrides() |
| 92 | + cls._original__init__ = cls.__init__ |
92 | 93 |
|
93 | 94 | def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0): |
94 | 95 | self.color = Color(color) if color else None |
@@ -175,6 +176,51 @@ def add_animation_override( |
175 | 176 | f"{override_func.__qualname__}.", |
176 | 177 | ) |
177 | 178 |
|
| 179 | + @classmethod |
| 180 | + def set_default(cls, **kwargs): |
| 181 | + """Sets the default values of keyword arguments. |
| 182 | +
|
| 183 | + If this method is called without any additional keyword |
| 184 | + arguments, the original default values of the initialization |
| 185 | + method of this class are restored. |
| 186 | +
|
| 187 | + Parameters |
| 188 | + ---------- |
| 189 | +
|
| 190 | + kwargs |
| 191 | + Passing any keyword argument will update the default |
| 192 | + values of the keyword arguments of the initialization |
| 193 | + function of this class. |
| 194 | +
|
| 195 | + Examples |
| 196 | + -------- |
| 197 | +
|
| 198 | + :: |
| 199 | +
|
| 200 | + >>> from manim import Square, GREEN |
| 201 | + >>> Square.set_default(color=GREEN, fill_opacity=0.25) |
| 202 | + >>> s = Square(); s.color, s.fill_opacity |
| 203 | + (<Color #83c167>, 0.25) |
| 204 | + >>> Square.set_default() |
| 205 | + >>> s = Square(); s.color, s.fill_opacity |
| 206 | + (<Color white>, 0.0) |
| 207 | +
|
| 208 | + .. manim:: ChangedDefaultTextcolor |
| 209 | + :save_last_frame: |
| 210 | +
|
| 211 | + config.background_color = WHITE |
| 212 | +
|
| 213 | + class ChangedDefaultTextcolor(Scene): |
| 214 | + def construct(self): |
| 215 | + Text.set_default(color=BLACK) |
| 216 | + self.add(Text("Changing default values is easy!")) |
| 217 | +
|
| 218 | + """ |
| 219 | + if kwargs: |
| 220 | + cls.__init__ = partialmethod(cls.__init__, **kwargs) |
| 221 | + else: |
| 222 | + cls.__init__ = cls._original__init__ |
| 223 | + |
178 | 224 | @property |
179 | 225 | def animate(self): |
180 | 226 | """Used to animate the application of a method. |
|
0 commit comments