Add VPrism, and refactor VCube

This commit is contained in:
Grant Sanderson 2022-03-29 20:34:14 -07:00
parent 2a7a7ac518
commit 0f8d7ed597

View file

@ -206,6 +206,13 @@ class Cube(SGroup):
return Square3D(resolution=self.square_resolution)
class Prism(Cube):
def __init__(self, width: float = 3.0, height: float = 2.0, depth: float = 1.0, **kwargs):
super().__init__(**kwargs)
for dim, value in enumerate([width, height, depth]):
self.rescale_to_fit(value, dim, stretch=True)
class VCube(VGroup):
CONFIG = {
"fill_color": BLUE_D,
@ -213,18 +220,25 @@ class VCube(VGroup):
"stroke_width": 0,
"gloss": 0.5,
"shadow": 0.5,
"joint_type": "round",
}
def __init__(self, side_length: int = 2, **kwargs):
super().__init__(**kwargs)
def __init__(self, side_length: float = 2.0, **kwargs):
face = Square(side_length=side_length)
face.get_triangulation()
self.add(*Cube.square_to_cube_faces(face))
super().__init__(*Cube.square_to_cube_faces(face), **kwargs)
self.init_colors()
self.set_joint_type(self.joint_type)
self.apply_depth_test()
self.refresh_unit_normal()
class VPrism(VCube):
def __init__(self, width: float = 3.0, height: float = 2.0, depth: float = 1.0, **kwargs):
super().__init__(**kwargs)
for dim, value in enumerate([width, height, depth]):
self.rescale_to_fit(value, dim, stretch=True)
class Dodecahedron(VGroup):
CONFIG = {
"fill_color": BLUE_E,
@ -272,20 +286,9 @@ class Dodecahedron(VGroup):
# self.add(pentagon2.copy().apply_matrix(matrix, about_point=ORIGIN))
class Prism(Cube):
CONFIG = {
"dimensions": [3, 2, 1]
}
def init_points(self) -> None:
Cube.init_points(self)
for dim, value in enumerate(self.dimensions):
self.rescale_to_fit(value, dim, stretch=True)
class Prismify(VGroup):
CONFIG = {
"apply_depth_test": True
"apply_depth_test": True,
}
def __init__(self, vmobject, depth=1.0, direction=IN, **kwargs):