Skip to content

Instantly share code, notes, and snippets.

@mdrost
Created May 16, 2025 14:07
Show Gist options
  • Save mdrost/df558cea7f6d7d538c263318e841a7dd to your computer and use it in GitHub Desktop.
Save mdrost/df558cea7f6d7d538c263318e841a7dd to your computer and use it in GitHub Desktop.
from manim import *
class BigStealthTip(ArrowTip):
def __init__(
self,
fill_opacity: float = 1,
stroke_width: float = 3,
length: float = DEFAULT_ARROW_TIP_LENGTH / 2,
start_angle: float = PI,
**kwargs,
):
self.start_angle = start_angle
VMobject.__init__(
self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
)
self.set_points_as_corners(
np.array(
[
[2, 0, 0], # tip
[-1.2, 7.6, 0], # modified
[0, 0, 0], # base
[-1.2, -7.6, 0], # modified
[2, 0, 0], # close path, back to tip
]
)
)
self.scale(length / self.length)
@property
def length(self) -> float:
"""The length of the arrow tip.
In this case, the length is computed as the height of
the triangle encompassing the stealth tip (otherwise,
the tip is scaled too large).
"""
return float(np.linalg.norm(self.vector) * 1.6)
class HalfStealthTip(ArrowTip):
def __init__(
self,
fill_opacity: float = 1,
stroke_width: float = 3,
length: float = DEFAULT_ARROW_TIP_LENGTH / 2,
start_angle: float = PI,
**kwargs,
):
self.start_angle = start_angle
VMobject.__init__(
self, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
)
self.set_points_as_corners(
np.array(
[
[2, 0, 0], # tip
[-1.2, 1.6, 0],
[0, 0, 0], # base
[-1.2, -7.6, 0], # modified
[2, 0, 0], # close path, back to tip
]
)
)
self.scale(length / self.length)
@property
def length(self) -> float:
"""The length of the arrow tip.
In this case, the length is computed as the height of
the triangle encompassing the stealth tip (otherwise,
the tip is scaled too large).
"""
return float(np.linalg.norm(self.vector) * 1.6)
class TipTest(Scene):
def construct(self):
fineArrowWithBigTip = Arrow(start=RIGHT, end=LEFT, tip_shape=BigStealthTip)
badArrowWithAsymmetricTip = Arrow(start=RIGHT, end=LEFT, tip_shape=HalfStealthTip)
badArrowWithAsymmetricTip.next_to(fineArrowWithBigTip, DOWN)
self.play(
Create(fineArrowWithBigTip),
Create(badArrowWithAsymmetricTip),
)
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment