2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.constants import *
|
|
|
|
from manimlib.mobject.geometry import Line
|
|
|
|
from manimlib.mobject.geometry import Rectangle
|
|
|
|
from manimlib.mobject.types.vectorized_mobject import VGroup
|
|
|
|
from manimlib.mobject.types.vectorized_mobject import VMobject
|
|
|
|
from manimlib.utils.color import Color
|
2021-01-15 10:20:50 -10:00
|
|
|
from manimlib.utils.customization import get_customization
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.utils.config_ops import digest_config
|
2018-03-31 18:05:02 -07:00
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 18:05:02 -07:00
|
|
|
class SurroundingRectangle(Rectangle):
|
|
|
|
CONFIG = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"color": YELLOW,
|
|
|
|
"buff": SMALL_BUFF,
|
2018-03-31 18:05:02 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 18:05:02 -07:00
|
|
|
def __init__(self, mobject, **kwargs):
|
|
|
|
digest_config(self, kwargs)
|
2018-04-06 13:58:59 -07:00
|
|
|
kwargs["width"] = mobject.get_width() + 2 * self.buff
|
|
|
|
kwargs["height"] = mobject.get_height() + 2 * self.buff
|
2018-03-31 18:05:02 -07:00
|
|
|
Rectangle.__init__(self, **kwargs)
|
|
|
|
self.move_to(mobject)
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 18:05:02 -07:00
|
|
|
class BackgroundRectangle(SurroundingRectangle):
|
|
|
|
CONFIG = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"stroke_width": 0,
|
2019-03-24 11:34:07 -07:00
|
|
|
"stroke_opacity": 0,
|
2018-04-06 13:58:59 -07:00
|
|
|
"fill_opacity": 0.75,
|
|
|
|
"buff": 0
|
2018-03-31 18:05:02 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2021-01-15 10:20:50 -10:00
|
|
|
def __init__(self, mobject, color=None, **kwargs):
|
|
|
|
if color is None:
|
|
|
|
color = get_customization()['style']['background_color']
|
|
|
|
SurroundingRectangle.__init__(self, mobject, color=color, **kwargs)
|
2018-03-31 18:05:02 -07:00
|
|
|
self.original_fill_opacity = self.fill_opacity
|
|
|
|
|
|
|
|
def pointwise_become_partial(self, mobject, a, b):
|
2018-04-06 13:58:59 -07:00
|
|
|
self.set_fill(opacity=b * self.original_fill_opacity)
|
2018-03-31 18:05:02 -07:00
|
|
|
return self
|
|
|
|
|
2018-04-16 14:18:00 -07:00
|
|
|
def set_style_data(self,
|
|
|
|
stroke_color=None,
|
|
|
|
stroke_width=None,
|
|
|
|
fill_color=None,
|
|
|
|
fill_opacity=None,
|
|
|
|
family=True
|
|
|
|
):
|
|
|
|
# Unchangable style, except for fill_opacity
|
|
|
|
VMobject.set_style_data(
|
|
|
|
self,
|
|
|
|
stroke_color=BLACK,
|
|
|
|
stroke_width=0,
|
|
|
|
fill_color=BLACK,
|
|
|
|
fill_opacity=fill_opacity
|
|
|
|
)
|
2018-03-31 18:05:02 -07:00
|
|
|
return self
|
|
|
|
|
|
|
|
def get_fill_color(self):
|
|
|
|
return Color(self.color)
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 18:05:02 -07:00
|
|
|
class Cross(VGroup):
|
|
|
|
CONFIG = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"stroke_color": RED,
|
|
|
|
"stroke_width": 6,
|
2018-03-31 18:05:02 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 18:05:02 -07:00
|
|
|
def __init__(self, mobject, **kwargs):
|
2018-04-06 13:58:59 -07:00
|
|
|
VGroup.__init__(self,
|
|
|
|
Line(UP + LEFT, DOWN + RIGHT),
|
|
|
|
Line(UP + RIGHT, DOWN + LEFT),
|
|
|
|
)
|
|
|
|
self.replace(mobject, stretch=True)
|
2018-03-31 18:05:02 -07:00
|
|
|
self.set_stroke(self.stroke_color, self.stroke_width)
|
2019-12-10 13:38:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
class Underline(Line):
|
|
|
|
CONFIG = {
|
|
|
|
"buff": SMALL_BUFF,
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, mobject, **kwargs):
|
2019-12-12 14:40:08 -08:00
|
|
|
super().__init__(LEFT, RIGHT, **kwargs)
|
2019-12-10 13:38:30 -08:00
|
|
|
self.match_width(mobject)
|
|
|
|
self.next_to(mobject, DOWN, buff=self.buff)
|