mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Add Dartboard
This commit is contained in:
parent
f01b990c2e
commit
63f6e9d84f
1 changed files with 50 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import itertools as it
|
||||||
|
|
||||||
from manimlib.animation.composition import AnimationGroup
|
from manimlib.animation.composition import AnimationGroup
|
||||||
from manimlib.animation.rotation import Rotating
|
from manimlib.animation.rotation import Rotating
|
||||||
|
@ -14,6 +15,7 @@ from manimlib.constants import DOWN
|
||||||
from manimlib.constants import FRAME_WIDTH
|
from manimlib.constants import FRAME_WIDTH
|
||||||
from manimlib.constants import GREEN
|
from manimlib.constants import GREEN
|
||||||
from manimlib.constants import GREEN_SCREEN
|
from manimlib.constants import GREEN_SCREEN
|
||||||
|
from manimlib.constants import GREEN_E
|
||||||
from manimlib.constants import GREY
|
from manimlib.constants import GREY
|
||||||
from manimlib.constants import GREY_A
|
from manimlib.constants import GREY_A
|
||||||
from manimlib.constants import GREY_B
|
from manimlib.constants import GREY_B
|
||||||
|
@ -26,6 +28,7 @@ from manimlib.constants import ORIGIN
|
||||||
from manimlib.constants import OUT
|
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 RED_E
|
||||||
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
|
||||||
|
@ -36,6 +39,7 @@ from manimlib.constants import DL
|
||||||
from manimlib.constants import DR
|
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.constants import TAU
|
||||||
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
|
||||||
|
@ -44,6 +48,7 @@ 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
|
||||||
from manimlib.mobject.geometry import Square
|
from manimlib.mobject.geometry import Square
|
||||||
|
from manimlib.mobject.geometry import AnnularSector
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.mobject.numbers import Integer
|
from manimlib.mobject.numbers import Integer
|
||||||
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
from manimlib.mobject.svg.svg_mobject import SVGMobject
|
||||||
|
@ -579,7 +584,6 @@ class Piano3D(VGroup):
|
||||||
key.set_color(BLACK)
|
key.set_color(BLACK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DieFace(VGroup):
|
class DieFace(VGroup):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -590,7 +594,7 @@ class DieFace(VGroup):
|
||||||
stroke_width: float = 2.0,
|
stroke_width: float = 2.0,
|
||||||
fill_color: ManimColor = GREY_E,
|
fill_color: ManimColor = GREY_E,
|
||||||
dot_radius: float = 0.08,
|
dot_radius: float = 0.08,
|
||||||
dot_color: ManimColor = BLUE_B,
|
dot_color: ManimColor = WHITE,
|
||||||
dot_coalesce_factor: float = 0.5
|
dot_coalesce_factor: float = 0.5
|
||||||
):
|
):
|
||||||
dot = Dot(radius=dot_radius, fill_color=dot_color)
|
dot = Dot(radius=dot_radius, fill_color=dot_color)
|
||||||
|
@ -625,3 +629,47 @@ class DieFace(VGroup):
|
||||||
self.dots = arrangement
|
self.dots = arrangement
|
||||||
self.value = value
|
self.value = value
|
||||||
self.index = value
|
self.index = value
|
||||||
|
|
||||||
|
|
||||||
|
class Dartboard(VGroup):
|
||||||
|
radius = 3
|
||||||
|
n_sectors = 20
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
n_sectors = self.n_sectors
|
||||||
|
angle = TAU / n_sectors
|
||||||
|
|
||||||
|
segments = VGroup(*[
|
||||||
|
VGroup(*[
|
||||||
|
AnnularSector(
|
||||||
|
inner_radius=in_r,
|
||||||
|
outer_radius=out_r,
|
||||||
|
start_angle=n * angle,
|
||||||
|
angle=angle,
|
||||||
|
fill_color=color,
|
||||||
|
)
|
||||||
|
for n, color in zip(
|
||||||
|
range(n_sectors),
|
||||||
|
it.cycle(colors)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
for colors, in_r, out_r in [
|
||||||
|
([GREY_B, GREY_E], 0, 1),
|
||||||
|
([GREEN_E, RED_E], 0.5, 0.55),
|
||||||
|
([GREEN_E, RED_E], 0.95, 1),
|
||||||
|
]
|
||||||
|
])
|
||||||
|
segments.rotate(-angle / 2)
|
||||||
|
bullseyes = VGroup(*[
|
||||||
|
Circle(radius=r)
|
||||||
|
for r in [0.07, 0.035]
|
||||||
|
])
|
||||||
|
bullseyes.set_fill(opacity=1)
|
||||||
|
bullseyes.set_stroke(width=0)
|
||||||
|
bullseyes[0].set_color(GREEN_E)
|
||||||
|
bullseyes[1].set_color(RED_E)
|
||||||
|
|
||||||
|
self.bullseye = bullseyes[1]
|
||||||
|
self.add(*segments, *bullseyes)
|
||||||
|
self.scale(self.radius)
|
||||||
|
|
Loading…
Add table
Reference in a new issue