mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Add DieFace to drawings.py
This commit is contained in:
parent
847c27ad23
commit
8ce5dc7e84
1 changed files with 52 additions and 2 deletions
|
@ -27,16 +27,19 @@ from manimlib.constants import OUT
|
||||||
from manimlib.constants import PI
|
from manimlib.constants import PI
|
||||||
from manimlib.constants import RED
|
from manimlib.constants import RED
|
||||||
from manimlib.constants import RIGHT
|
from manimlib.constants import RIGHT
|
||||||
from manimlib.constants import RIGHT
|
|
||||||
from manimlib.constants import SMALL_BUFF
|
from manimlib.constants import SMALL_BUFF
|
||||||
from manimlib.constants import SMALL_BUFF
|
from manimlib.constants import SMALL_BUFF
|
||||||
from manimlib.constants import UP
|
from manimlib.constants import UP
|
||||||
from manimlib.constants import UP
|
from manimlib.constants import UL
|
||||||
|
from manimlib.constants import UR
|
||||||
|
from manimlib.constants import DL
|
||||||
|
from manimlib.constants import DR
|
||||||
from manimlib.constants import WHITE
|
from manimlib.constants import WHITE
|
||||||
from manimlib.constants import YELLOW
|
from manimlib.constants import YELLOW
|
||||||
from manimlib.mobject.boolean_ops import Difference
|
from manimlib.mobject.boolean_ops import Difference
|
||||||
from manimlib.mobject.geometry import Arc
|
from manimlib.mobject.geometry import Arc
|
||||||
from manimlib.mobject.geometry import Circle
|
from manimlib.mobject.geometry import Circle
|
||||||
|
from manimlib.mobject.geometry import Dot
|
||||||
from manimlib.mobject.geometry import Line
|
from manimlib.mobject.geometry import Line
|
||||||
from manimlib.mobject.geometry import Polygon
|
from manimlib.mobject.geometry import Polygon
|
||||||
from manimlib.mobject.geometry import Rectangle
|
from manimlib.mobject.geometry import Rectangle
|
||||||
|
@ -577,3 +580,50 @@ class Piano3D(VGroup):
|
||||||
if piano_2d[i] in piano_2d.black_keys:
|
if piano_2d[i] in piano_2d.black_keys:
|
||||||
key.shift(black_key_shift * OUT)
|
key.shift(black_key_shift * OUT)
|
||||||
key.set_color(BLACK)
|
key.set_color(BLACK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DieFace(VGroup):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
value: int,
|
||||||
|
side_length: float = 1.0,
|
||||||
|
corner_radius: float = 0.15,
|
||||||
|
stroke_color: ManimColor = WHITE,
|
||||||
|
stroke_width: float = 2.0,
|
||||||
|
fill_color: ManimColor = GREY_E,
|
||||||
|
dot_radius: float = 0.08,
|
||||||
|
dot_color: ManimColor = BLUE_B,
|
||||||
|
dot_coalesce_factor: float = 0.5
|
||||||
|
):
|
||||||
|
dot = Dot(radius=dot_radius, fill_color=dot_color)
|
||||||
|
square = Square(
|
||||||
|
side_length=side_length,
|
||||||
|
stroke_color=stroke_color,
|
||||||
|
stroke_width=stroke_width,
|
||||||
|
fill_color=fill_color,
|
||||||
|
fill_opacity=1.0,
|
||||||
|
)
|
||||||
|
square.round_corners(corner_radius)
|
||||||
|
|
||||||
|
if not (1 <= value <= 6):
|
||||||
|
raise Exception("DieFace only accepts integer inputs between 1 and 6")
|
||||||
|
|
||||||
|
edge_group = [
|
||||||
|
(ORIGIN,),
|
||||||
|
(UL, DR),
|
||||||
|
(UL, ORIGIN, DR),
|
||||||
|
(UL, UR, DL, DR),
|
||||||
|
(UL, UR, ORIGIN, DL, DR),
|
||||||
|
(UL, UR, LEFT, RIGHT, DL, DR),
|
||||||
|
][value - 1]
|
||||||
|
|
||||||
|
arrangement = VGroup(*(
|
||||||
|
dot.copy().move_to(square.get_bounding_box_point(vect))
|
||||||
|
for vect in edge_group
|
||||||
|
))
|
||||||
|
arrangement.space_out_submobjects(dot_coalesce_factor)
|
||||||
|
|
||||||
|
super().__init__(square, arrangement)
|
||||||
|
self.value = value
|
||||||
|
self.index = value
|
||||||
|
|
Loading…
Add table
Reference in a new issue