mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Kill CONFIG in brace.py
This commit is contained in:
parent
aac320aa98
commit
2a89e84538
1 changed files with 22 additions and 22 deletions
|
@ -2,11 +2,12 @@ from __future__ import annotations
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import copy
|
import copy
|
||||||
|
from os import DirEntry
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from manimlib.constants import DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, SMALL_BUFF
|
from manimlib.constants import DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, SMALL_BUFF
|
||||||
from manimlib.constants import DOWN, LEFT, ORIGIN, RIGHT, UP
|
from manimlib.constants import DOWN, LEFT, ORIGIN, RIGHT, UP, DL, DR, UL
|
||||||
from manimlib.constants import PI
|
from manimlib.constants import PI
|
||||||
from manimlib.animation.composition import AnimationGroup
|
from manimlib.animation.composition import AnimationGroup
|
||||||
from manimlib.animation.fading import FadeIn
|
from manimlib.animation.fading import FadeIn
|
||||||
|
@ -15,6 +16,7 @@ from manimlib.mobject.svg.tex_mobject import SingleStringTex
|
||||||
from manimlib.mobject.svg.tex_mobject import Tex
|
from manimlib.mobject.svg.tex_mobject import Tex
|
||||||
from manimlib.mobject.svg.tex_mobject import TexText
|
from manimlib.mobject.svg.tex_mobject import TexText
|
||||||
from manimlib.mobject.svg.text_mobject import Text
|
from manimlib.mobject.svg.text_mobject import Text
|
||||||
|
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.iterables import listify
|
from manimlib.utils.iterables import listify
|
||||||
|
@ -28,30 +30,29 @@ if TYPE_CHECKING:
|
||||||
from manimlib.animation.animation import Animation
|
from manimlib.animation.animation import Animation
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
|
|
||||||
|
from manimlib.constants import ManimColor, np_vector
|
||||||
|
|
||||||
|
|
||||||
class Brace(SingleStringTex):
|
class Brace(SingleStringTex):
|
||||||
CONFIG = {
|
|
||||||
"buff": 0.2,
|
|
||||||
"tex_string": r"\underbrace{\qquad}"
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
mobject: Mobject,
|
mobject: Mobject,
|
||||||
direction: np.ndarray = DOWN,
|
direction: np_vector = DOWN,
|
||||||
|
buff: float = 0.2,
|
||||||
|
tex_string: str = R"\underbrace{\qquad}",
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
digest_config(self, kwargs, locals())
|
super().__init__(tex_string, **kwargs)
|
||||||
|
|
||||||
angle = -math.atan2(*direction[:2]) + PI
|
angle = -math.atan2(*direction[:2]) + PI
|
||||||
mobject.rotate(-angle, about_point=ORIGIN)
|
mobject.rotate(-angle, about_point=ORIGIN)
|
||||||
left = mobject.get_corner(DOWN + LEFT)
|
left = mobject.get_corner(DL)
|
||||||
right = mobject.get_corner(DOWN + RIGHT)
|
right = mobject.get_corner(DR)
|
||||||
target_width = right[0] - left[0]
|
target_width = right[0] - left[0]
|
||||||
|
|
||||||
super().__init__(self.tex_string, **kwargs)
|
|
||||||
self.tip_point_index = np.argmin(self.get_all_points()[:, 1])
|
self.tip_point_index = np.argmin(self.get_all_points()[:, 1])
|
||||||
self.set_initial_width(target_width)
|
self.set_initial_width(target_width)
|
||||||
self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)
|
self.shift(left - self.get_corner(UL) + buff * DOWN)
|
||||||
for mob in mobject, self:
|
for mob in mobject, self:
|
||||||
mob.rotate(angle, about_point=ORIGIN)
|
mob.rotate(angle, about_point=ORIGIN)
|
||||||
|
|
||||||
|
@ -110,23 +111,24 @@ class Brace(SingleStringTex):
|
||||||
|
|
||||||
|
|
||||||
class BraceLabel(VMobject):
|
class BraceLabel(VMobject):
|
||||||
CONFIG = {
|
label_constructor: type = Tex
|
||||||
"label_constructor": Tex,
|
|
||||||
"label_scale": 1,
|
|
||||||
"label_buff": DEFAULT_MOBJECT_TO_MOBJECT_BUFFER
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
obj: VMobject | list[VMobject],
|
obj: VMobject | list[VMobject],
|
||||||
text: str | Iterable[str],
|
text: str | Iterable[str],
|
||||||
brace_direction: np.ndarray = DOWN,
|
brace_direction: np.ndarray = DOWN,
|
||||||
|
label_scale: float = 1.0,
|
||||||
|
label_buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER,
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
VMobject.__init__(self, **kwargs)
|
super().__init__(**kwargs)
|
||||||
self.brace_direction = brace_direction
|
self.brace_direction = brace_direction
|
||||||
|
self.label_scale = label_scale
|
||||||
|
self.label_buff = label_buff
|
||||||
|
|
||||||
if isinstance(obj, list):
|
if isinstance(obj, list):
|
||||||
obj = VMobject(*obj)
|
obj = VGroup(*obj)
|
||||||
self.brace = Brace(obj, brace_direction, **kwargs)
|
self.brace = Brace(obj, brace_direction, **kwargs)
|
||||||
|
|
||||||
self.label = self.label_constructor(*listify(text), **kwargs)
|
self.label = self.label_constructor(*listify(text), **kwargs)
|
||||||
|
@ -174,6 +176,4 @@ class BraceLabel(VMobject):
|
||||||
|
|
||||||
|
|
||||||
class BraceText(BraceLabel):
|
class BraceText(BraceLabel):
|
||||||
CONFIG = {
|
label_constructor: type = TexText
|
||||||
"label_constructor": TexText
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue