mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Kill CONFIG in dot_cloud.py
This commit is contained in:
parent
a715a5bc3f
commit
b373e33a22
2 changed files with 52 additions and 42 deletions
|
@ -12,6 +12,8 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
from typing import Sequence, Tuple
|
||||||
|
from manimlib.constants import ManimColor, np_vector
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_DOT_RADIUS = 0.05
|
DEFAULT_DOT_RADIUS = 0.05
|
||||||
|
@ -19,24 +21,35 @@ DEFAULT_GLOW_DOT_RADIUS = 0.2
|
||||||
DEFAULT_GRID_HEIGHT = 6
|
DEFAULT_GRID_HEIGHT = 6
|
||||||
DEFAULT_BUFF_RATIO = 0.5
|
DEFAULT_BUFF_RATIO = 0.5
|
||||||
|
|
||||||
|
|
||||||
class DotCloud(PMobject):
|
class DotCloud(PMobject):
|
||||||
CONFIG = {
|
shader_folder: str = "true_dot"
|
||||||
"color": GREY_C,
|
render_primitive: int = moderngl.POINTS
|
||||||
"opacity": 1,
|
shader_dtype: Sequence[Tuple[str, type, Tuple[int]]] = [
|
||||||
"radius": DEFAULT_DOT_RADIUS,
|
|
||||||
"glow_factor": 0,
|
|
||||||
"shader_folder": "true_dot",
|
|
||||||
"render_primitive": moderngl.POINTS,
|
|
||||||
"shader_dtype": [
|
|
||||||
('point', np.float32, (3,)),
|
('point', np.float32, (3,)),
|
||||||
('radius', np.float32, (1,)),
|
('radius', np.float32, (1,)),
|
||||||
('color', np.float32, (4,)),
|
('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:
|
if points is not None:
|
||||||
self.set_points(points)
|
self.set_points(points)
|
||||||
|
|
||||||
|
@ -145,11 +158,21 @@ class TrueDot(DotCloud):
|
||||||
|
|
||||||
|
|
||||||
class GlowDots(DotCloud):
|
class GlowDots(DotCloud):
|
||||||
CONFIG = {
|
def __init__(
|
||||||
"glow_factor": 2,
|
self,
|
||||||
"radius": DEFAULT_GLOW_DOT_RADIUS,
|
points: Sequence[np_vector] | None = None,
|
||||||
"color": YELLOW,
|
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):
|
class GlowDot(GlowDots, TrueDot):
|
||||||
|
|
|
@ -13,16 +13,12 @@ from manimlib.utils.iterables import resize_with_interpolation
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Callable
|
from typing import Callable, Sequence
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
from manimlib.constants import ManimColor
|
from manimlib.constants import ManimColor, np_vector
|
||||||
|
|
||||||
|
|
||||||
class PMobject(Mobject):
|
class PMobject(Mobject):
|
||||||
CONFIG = {
|
|
||||||
"opacity": 1.0,
|
|
||||||
}
|
|
||||||
|
|
||||||
def resize_points(
|
def resize_points(
|
||||||
self,
|
self,
|
||||||
size: int,
|
size: int,
|
||||||
|
@ -36,7 +32,7 @@ class PMobject(Mobject):
|
||||||
self.data[key] = resize_func(self.data[key], size)
|
self.data[key] = resize_func(self.data[key], size)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def set_points(self, points: npt.ArrayLike):
|
def set_points(self, points: np_vector):
|
||||||
if len(points) == 0:
|
if len(points) == 0:
|
||||||
points = np.zeros((0, 3))
|
points = np.zeros((0, 3))
|
||||||
super().set_points(points)
|
super().set_points(points)
|
||||||
|
@ -45,8 +41,8 @@ class PMobject(Mobject):
|
||||||
|
|
||||||
def add_points(
|
def add_points(
|
||||||
self,
|
self,
|
||||||
points: npt.ArrayLike,
|
points: Sequence[np_vector],
|
||||||
rgbas: np.ndarray | None = None,
|
rgbas: np_vector | None = None,
|
||||||
color: ManimColor | None = None,
|
color: ManimColor | None = None,
|
||||||
opacity: float | None = None
|
opacity: float | None = None
|
||||||
):
|
):
|
||||||
|
@ -67,7 +63,7 @@ class PMobject(Mobject):
|
||||||
self.data["rgbas"][-len(rgbas):] = rgbas
|
self.data["rgbas"][-len(rgbas):] = rgbas
|
||||||
return self
|
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]
|
rgbas = None if rgba is None else [rgba]
|
||||||
self.add_points([point], rgbas, color, opacity)
|
self.add_points([point], rgbas, color, opacity)
|
||||||
return self
|
return self
|
||||||
|
@ -94,7 +90,7 @@ class PMobject(Mobject):
|
||||||
mob.data[key] = mob.data[key][to_keep]
|
mob.data[key] = mob.data[key][to_keep]
|
||||||
return self
|
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
|
function is any map from R^3 to R
|
||||||
"""
|
"""
|
||||||
|
@ -132,14 +128,5 @@ class PGroup(PMobject):
|
||||||
def __init__(self, *pmobs: PMobject, **kwargs):
|
def __init__(self, *pmobs: PMobject, **kwargs):
|
||||||
if not all([isinstance(m, PMobject) for m in pmobs]):
|
if not all([isinstance(m, PMobject) for m in pmobs]):
|
||||||
raise Exception("All submobjects must be of type PMobject")
|
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)
|
super().__init__(**kwargs)
|
||||||
self.add_points([location])
|
self.add(*pmobs)
|
||||||
|
|
Loading…
Add table
Reference in a new issue