Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added Axes Tip Resize Functionality according to Axes documentation (#2661)

WillSoltasce4ac5162b62
diff --git a/manim/mobject/geometry/arc.py b/manim/mobject/geometry/arc.py
index a15debefe..894ca3d02 100644
--- a/manim/mobject/geometry/arc.py
+++ b/manim/mobject/geometry/arc.py
@@ -101,13 +101,15 @@ class TipableVMobject(VMobject, metaclass=ConvertToOpenGL):
# Adding, Creating, Modifying tips
- def add_tip(self, tip=None, tip_shape=None, tip_length=None, at_start=False):
+ def add_tip(
+ self, tip=None, tip_shape=None, tip_length=None, tip_width=None, at_start=False
+ ):
"""Adds a tip to the TipableVMobject instance, recognising
that the endpoints might need to be switched if it's
a 'starting tip' or not.
"""
if tip is None:
- tip = self.create_tip(tip_shape, tip_length, at_start)
+ tip = self.create_tip(tip_shape, tip_length, tip_width, at_start)
else:
self.position_tip(tip, at_start)
self.reset_endpoints_based_on_tip(tip, at_start)
@@ -115,26 +117,36 @@ class TipableVMobject(VMobject, metaclass=ConvertToOpenGL):
self.add(tip)
return self
- def create_tip(self, tip_shape=None, tip_length=None, at_start=False):
+ def create_tip(
+ self, tip_shape=None, tip_length=None, tip_width=None, at_start=False
+ ):
"""Stylises the tip, positions it spatially, and returns
the newly instantiated tip to the caller.
"""
- tip = self.get_unpositioned_tip(tip_shape, tip_length)
+ tip = self.get_unpositioned_tip(tip_shape, tip_length, tip_width)
self.position_tip(tip, at_start)
return tip
- def get_unpositioned_tip(self, tip_shape=None, tip_length=None):
+ def get_unpositioned_tip(self, tip_shape=None, tip_length=None, tip_width=None):
"""Returns a tip that has been stylistically configured,
but has not yet been given a position in space.
"""
from manim.mobject.geometry.tips import ArrowTriangleFilledTip
+ style = {}
+
if tip_shape is None:
tip_shape = ArrowTriangleFilledTip
+
+ if tip_shape is ArrowTriangleFilledTip:
+ if tip_width is None:
+ tip_width = self.get_default_tip_length()
+ style.update({"width": tip_width})
if tip_length is None:
tip_length = self.get_default_tip_length()
+
color = self.get_color()
- style = {"fill_color": color, "stroke_color": color}
+ style.update({"fill_color": color, "stroke_color": color})
style.update(self.tip_style)
tip = tip_shape(length=tip_length, **style)
return tip
diff --git a/manim/mobject/geometry/tips.py b/manim/mobject/geometry/tips.py
index 30f71ceb9..b25a5a538 100644
--- a/manim/mobject/geometry/tips.py
+++ b/manim/mobject/geometry/tips.py
@@ -185,6 +185,7 @@ class ArrowTriangleTip(ArrowTip, Triangle):
fill_opacity=0,
stroke_width=3,
length=DEFAULT_ARROW_TIP_LENGTH,
+ width=DEFAULT_ARROW_TIP_LENGTH,
start_angle=PI,
**kwargs,
):
@@ -195,8 +196,10 @@ class ArrowTriangleTip(ArrowTip, Triangle):
start_angle=start_angle,
**kwargs,
)
- self.width = length
- self.stretch_to_fit_height(length)
+ self.width = width
+
+ self.stretch_to_fit_width(length)
+ self.stretch_to_fit_height(width)
class ArrowTriangleFilledTip(ArrowTriangleTip):
diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.py
index c7676a6b2..78f61e4b6 100644
--- a/manim/mobject/graphing/number_line.py
+++ b/manim/mobject/graphing/number_line.py
@@ -138,8 +138,8 @@ class NumberLine(Line):
stroke_width: float = 2.0,
# tip
include_tip: bool = False,
- tip_width: float = 0.25,
- tip_height: float = 0.25,
+ tip_width: float = DEFAULT_ARROW_TIP_LENGTH,
+ tip_height: float = DEFAULT_ARROW_TIP_LENGTH,
# numbers/labels
include_numbers: bool = False,
font_size: float = 36,
@@ -217,7 +217,7 @@ class NumberLine(Line):
self.center()
if self.include_tip:
- self.add_tip()
+ self.add_tip(tip_length=self.tip_height, tip_width=self.tip_width)
self.tip.set_stroke(self.stroke_color, self.stroke_width)
if self.include_ticks:
diff --git a/tests/test_graphical_units/control_data/plot/axis_tip_custom_width_height.npz b/tests/test_graphical_units/control_data/plot/axis_tip_custom_width_height.npz
new file mode 100644
index 000000000..6e0eaae86
Binary files /dev/null and b/tests/test_graphical_units/control_data/plot/axis_tip_custom_width_height.npz differ
diff --git a/tests/test_graphical_units/control_data/plot/axis_tip_default_width_height.npz b/tests/test_graphical_units/control_data/plot/axis_tip_default_width_height.npz
new file mode 100644
index 000000000..91a3e67dc
Binary files /dev/null and b/tests/test_graphical_units/control_data/plot/axis_tip_default_width_height.npz differ
diff --git a/tests/test_graphical_units/test_axes.py b/tests/test_graphical_units/test_axes.py
index 0683a4682..20843f1da 100644
--- a/tests/test_graphical_units/test_axes.py
+++ b/tests/test_graphical_units/test_axes.py
@@ -67,6 +67,30 @@ def test_get_y_axis_label(scene):
scene.add(ax, y_label)
+@frames_comparison
+def test_axis_tip_default_width_height(scene):
+ ax = Axes(
+ x_range=(0, 4),
+ y_range=(0, 4),
+ axis_config={"include_numbers": True, "include_tip": True},
+ )
+
+ scene.add(ax)
+
+
+@frames_comparison
+def test_axis_tip_custom_width_height(scene):
+ ax = Axes(
+ x_range=(0, 4),
+ y_range=(0, 4),
+ axis_config={"include_numbers": True, "include_tip": True},
+ x_axis_config={"tip_width": 1, "tip_height": 0.1},
+ y_axis_config={"tip_width": 0.1, "tip_height": 1},
+ )
+
+ scene.add(ax)
+
+
@frames_comparison
def test_plot_derivative_graph(scene):
ax = NumberPlane(y_range=[-1, 7], background_line_style={"stroke_opacity": 0.4})