ArrowTip¶
Qualified name: manim.mobject.geometry.tips.ArrowTip
- class ArrowTip(*args, **kwargs)[source]¶
Bases:
VMobjectBase class for arrow tips.
See also
ArrowTriangleTipArrowTriangleFilledTipArrowCircleTipArrowCircleFilledTipArrowSquareTipArrowSquareFilledTipStealthTipExamples
Cannot be used directly, only intended for inheritance:
>>> tip = ArrowTip() Traceback (most recent call last): ... NotImplementedError: Has to be implemented in inheriting subclasses.
Instead, use one of the pre-defined ones, or make a custom one like this:
Example: CustomTipExample ¶
from manim import * >>> from manim import RegularPolygon, Arrow >>> class MyCustomArrowTip(ArrowTip, RegularPolygon): ... def __init__(self, length=0.35, **kwargs): ... RegularPolygon.__init__(self, n=5, **kwargs) ... self.width = length ... self.stretch_to_fit_height(length) >>> arr = Arrow( ... np.array([-2, -2, 0]), np.array([2, 2, 0]), tip_shape=MyCustomArrowTip ... ) >>> isinstance(arr.tip, RegularPolygon) True >>> from manim import Scene, Create >>> class CustomTipExample(Scene): ... def construct(self): ... self.play(Create(arr))
>>> from manim import RegularPolygon, Arrow >>> class MyCustomArrowTip(ArrowTip, RegularPolygon): ... def __init__(self, length=0.35, **kwargs): ... RegularPolygon.__init__(self, n=5, **kwargs) ... self.width = length ... self.stretch_to_fit_height(length) >>> arr = Arrow( ... np.array([-2, -2, 0]), np.array([2, 2, 0]), tip_shape=MyCustomArrowTip ... ) >>> isinstance(arr.tip, RegularPolygon) True >>> from manim import Scene, Create >>> class CustomTipExample(Scene): ... def construct(self): ... self.play(Create(arr))
Using a class inherited from
ArrowTipto get a non-filled tip is a shorthand to manually specifying the arrow tip style as follows:>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]), ... tip_style={'fill_opacity': 0, 'stroke_width': 3})
The following example illustrates the usage of all of the predefined arrow tips.
Example: ArrowTipsShowcase ¶
from manim import * class ArrowTipsShowcase(Scene): def construct(self): tip_names = [ 'Default (YELLOW)', 'ArrowTriangleTip', 'Default', 'ArrowSquareTip', 'ArrowSquareFilledTip', 'ArrowCircleTip', 'ArrowCircleFilledTip', 'StealthTip' ] big_arrows = [ Arrow(start=[-4, 3.5, 0], end=[2, 3.5, 0], color=YELLOW), Arrow(start=[-4, 2.5, 0], end=[2, 2.5, 0], tip_shape=ArrowTriangleTip), Arrow(start=[-4, 1.5, 0], end=[2, 1.5, 0]), Arrow(start=[-4, 0.5, 0], end=[2, 0.5, 0], tip_shape=ArrowSquareTip), Arrow([-4, -0.5, 0], [2, -0.5, 0], tip_shape=ArrowSquareFilledTip), Arrow([-4, -1.5, 0], [2, -1.5, 0], tip_shape=ArrowCircleTip), Arrow([-4, -2.5, 0], [2, -2.5, 0], tip_shape=ArrowCircleFilledTip), Arrow([-4, -3.5, 0], [2, -3.5, 0], tip_shape=StealthTip) ] small_arrows = ( arrow.copy().scale(0.5, scale_tips=True).next_to(arrow, RIGHT) for arrow in big_arrows ) labels = ( Text(tip_names[i], font='monospace', font_size=20, color=BLUE).next_to(big_arrows[i], LEFT) for i in range(len(big_arrows)) ) self.add(*big_arrows, *small_arrows, *labels)
class ArrowTipsShowcase(Scene): def construct(self): tip_names = [ 'Default (YELLOW)', 'ArrowTriangleTip', 'Default', 'ArrowSquareTip', 'ArrowSquareFilledTip', 'ArrowCircleTip', 'ArrowCircleFilledTip', 'StealthTip' ] big_arrows = [ Arrow(start=[-4, 3.5, 0], end=[2, 3.5, 0], color=YELLOW), Arrow(start=[-4, 2.5, 0], end=[2, 2.5, 0], tip_shape=ArrowTriangleTip), Arrow(start=[-4, 1.5, 0], end=[2, 1.5, 0]), Arrow(start=[-4, 0.5, 0], end=[2, 0.5, 0], tip_shape=ArrowSquareTip), Arrow([-4, -0.5, 0], [2, -0.5, 0], tip_shape=ArrowSquareFilledTip), Arrow([-4, -1.5, 0], [2, -1.5, 0], tip_shape=ArrowCircleTip), Arrow([-4, -2.5, 0], [2, -2.5, 0], tip_shape=ArrowCircleFilledTip), Arrow([-4, -3.5, 0], [2, -3.5, 0], tip_shape=StealthTip) ] small_arrows = ( arrow.copy().scale(0.5, scale_tips=True).next_to(arrow, RIGHT) for arrow in big_arrows ) labels = ( Text(tip_names[i], font='monospace', font_size=20, color=BLUE).next_to(big_arrows[i], LEFT) for i in range(len(big_arrows)) ) self.add(*big_arrows, *small_arrows, *labels)Methods
Attributes
alwaysCall a method on a mobject every frame.
animateUsed to animate the application of any method of
self.animation_overridesThe base point of the arrow tip.
colordepthThe depth of the mobject.
fill_colorIf there are multiple colors (for gradient) this returns the first one
heightThe height of the mobject.
The length of the arrow tip.
n_points_per_curvesheen_factorstroke_colorThe angle of the arrow tip.
The tip point of the arrow tip.
The vector pointing from the base point to the tip point.
widthThe width of the mobject.
- Parameters:
args (Any)
kwargs (Any)
- _original__init__(*args, **kwargs)¶
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
None
- property base: Point3D¶
The base point of the arrow tip.
This is the point connecting to the arrow line.
Examples
>>> from manim import Arrow >>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 0, 0]), buff=0) >>> arrow.tip.base.round(2) + 0. # add 0. to avoid negative 0 in output array([1.65, 0. , 0. ])
- property length: float¶
The length of the arrow tip.
Examples
>>> from manim import Arrow >>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 2, 0])) >>> round(arrow.tip.length, 3) 0.35
- property tip_angle: float¶
The angle of the arrow tip.
Examples
>>> from manim import Arrow >>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]), buff=0) >>> bool(round(arrow.tip.tip_angle, 5) == round(PI/4, 5)) True