mirror of
https://github.com/3b1b/manim.git
synced 2025-07-29 21:12:35 +08:00
Refactor many definitions out of topics and into folders within mobject
This commit is contained in:
56
mobject/shape_matchers.py
Normal file
56
mobject/shape_matchers.py
Normal file
@ -0,0 +1,56 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from constants import *
|
||||
|
||||
from mobject.geometry import Rectangle
|
||||
from mobject.geometry import Line
|
||||
from mobject.types.vectorized_mobject import VGroup
|
||||
from utils.config_ops import digest_config
|
||||
from utils.color import Color
|
||||
|
||||
class SurroundingRectangle(Rectangle):
|
||||
CONFIG = {
|
||||
"color" : YELLOW,
|
||||
"buff" : SMALL_BUFF,
|
||||
}
|
||||
def __init__(self, mobject, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
kwargs["width"] = mobject.get_width() + 2*self.buff
|
||||
kwargs["height"] = mobject.get_height() + 2*self.buff
|
||||
Rectangle.__init__(self, **kwargs)
|
||||
self.move_to(mobject)
|
||||
|
||||
class BackgroundRectangle(SurroundingRectangle):
|
||||
CONFIG = {
|
||||
"color" : BLACK,
|
||||
"stroke_width" : 0,
|
||||
"fill_opacity" : 0.75,
|
||||
"buff" : 0
|
||||
}
|
||||
def __init__(self, mobject, **kwargs):
|
||||
SurroundingRectangle.__init__(self, mobject, **kwargs)
|
||||
self.original_fill_opacity = self.fill_opacity
|
||||
|
||||
def pointwise_become_partial(self, mobject, a, b):
|
||||
self.set_fill(opacity = b*self.original_fill_opacity)
|
||||
return self
|
||||
|
||||
def set_color(self):
|
||||
# Can't be changin' me!
|
||||
return self
|
||||
|
||||
def get_fill_color(self):
|
||||
return Color(self.color)
|
||||
|
||||
class Cross(VGroup):
|
||||
CONFIG = {
|
||||
"stroke_color" : RED,
|
||||
"stroke_width" : 6,
|
||||
}
|
||||
def __init__(self, mobject, **kwargs):
|
||||
VGroup.__init__(self,
|
||||
Line(UP+LEFT, DOWN+RIGHT),
|
||||
Line(UP+RIGHT, DOWN+LEFT),
|
||||
)
|
||||
self.replace(mobject, stretch = True)
|
||||
self.set_stroke(self.stroke_color, self.stroke_width)
|
Reference in New Issue
Block a user