Kill CONFIG in dot_cloud.py

This commit is contained in:
Grant Sanderson 2022-12-15 09:37:32 -08:00
parent a715a5bc3f
commit b373e33a22
2 changed files with 52 additions and 42 deletions

View file

@ -12,6 +12,8 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
import numpy.typing as npt
from typing import Sequence, Tuple
from manimlib.constants import ManimColor, np_vector
DEFAULT_DOT_RADIUS = 0.05
@ -19,24 +21,35 @@ DEFAULT_GLOW_DOT_RADIUS = 0.2
DEFAULT_GRID_HEIGHT = 6
DEFAULT_BUFF_RATIO = 0.5
class DotCloud(PMobject):
CONFIG = {
"color": GREY_C,
"opacity": 1,
"radius": DEFAULT_DOT_RADIUS,
"glow_factor": 0,
"shader_folder": "true_dot",
"render_primitive": moderngl.POINTS,
"shader_dtype": [
('point', np.float32, (3,)),
('radius', np.float32, (1,)),
('color', np.float32, (4,)),
],
}
shader_folder: str = "true_dot"
render_primitive: int = moderngl.POINTS
shader_dtype: Sequence[Tuple[str, type, Tuple[int]]] = [
('point', np.float32, (3,)),
('radius', np.float32, (1,)),
('color', np.float32, (4,)),
]
def __init__(
self,
points: Sequence[np_vector] | None = None,
color: ManimColor = GREY_C,
opacity: float = 1.0,
radius: float = DEFAULT_DOT_RADIUS,
glow_factor: float = 0.0,
**kwargs
):
self.radius = radius
self.glow_factor = glow_factor
print(kwargs)
super().__init__(
color=color,
opacity=opacity,
**kwargs
)
def __init__(self, points: npt.ArrayLike = None, **kwargs):
super().__init__(**kwargs)
if points is not None:
self.set_points(points)
@ -145,11 +158,21 @@ class TrueDot(DotCloud):
class GlowDots(DotCloud):
CONFIG = {
"glow_factor": 2,
"radius": DEFAULT_GLOW_DOT_RADIUS,
"color": YELLOW,
}
def __init__(
self,
points: Sequence[np_vector] | None = None,
color: ManimColor = YELLOW,
radius: float = DEFAULT_GLOW_DOT_RADIUS,
glow_factor: float = 2.0,
**kwargs,
):
super().__init__(
points,
color=color,
radius=radius,
glow_factor=glow_factor,
**kwargs,
)
class GlowDot(GlowDots, TrueDot):

View file

@ -13,16 +13,12 @@ from manimlib.utils.iterables import resize_with_interpolation
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Callable
from typing import Callable, Sequence
import numpy.typing as npt
from manimlib.constants import ManimColor
from manimlib.constants import ManimColor, np_vector
class PMobject(Mobject):
CONFIG = {
"opacity": 1.0,
}
def resize_points(
self,
size: int,
@ -36,7 +32,7 @@ class PMobject(Mobject):
self.data[key] = resize_func(self.data[key], size)
return self
def set_points(self, points: npt.ArrayLike):
def set_points(self, points: np_vector):
if len(points) == 0:
points = np.zeros((0, 3))
super().set_points(points)
@ -45,8 +41,8 @@ class PMobject(Mobject):
def add_points(
self,
points: npt.ArrayLike,
rgbas: np.ndarray | None = None,
points: Sequence[np_vector],
rgbas: np_vector | None = None,
color: ManimColor | None = None,
opacity: float | None = None
):
@ -67,7 +63,7 @@ class PMobject(Mobject):
self.data["rgbas"][-len(rgbas):] = rgbas
return self
def add_point(self, point, rgba=None, color=None, opacity=None):
def add_point(self, point: np_vector, rgba=None, color=None, opacity=None):
rgbas = None if rgba is None else [rgba]
self.add_points([point], rgbas, color, opacity)
return self
@ -94,7 +90,7 @@ class PMobject(Mobject):
mob.data[key] = mob.data[key][to_keep]
return self
def sort_points(self, function: Callable[[np.ndarray]] = lambda p: p[0]):
def sort_points(self, function: Callable[[np_vector], None] = lambda p: p[0]):
"""
function is any map from R^3 to R
"""
@ -132,14 +128,5 @@ class PGroup(PMobject):
def __init__(self, *pmobs: PMobject, **kwargs):
if not all([isinstance(m, PMobject) for m in pmobs]):
raise Exception("All submobjects must be of type PMobject")
super().__init__(*pmobs, **kwargs)
class Point(PMobject):
CONFIG = {
"color": BLACK,
}
def __init__(self, location: np.ndarray = ORIGIN, **kwargs):
super().__init__(**kwargs)
self.add_points([location])
self.add(*pmobs)