Skip to content

Commit 5164d27

Browse files
committed
Improve docstring for .interpolate() in Mobject
1 parent 3c6a1ee commit 5164d27

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

manim/animation/transform.py

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def make_arc_path(start, end, arc_angle):
123123
124124
self.play(*anims, run_time=2)
125125
self.wait()
126+
127+
See also
128+
--------
129+
:class:`~.ReplacementTransform`, :meth:`~.Mobject.interpolate`, :meth:`~.Mobject.align_data`
130+
126131
"""
127132

128133
def __init__(

manim/mobject/mobject.py

+51-9
Original file line numberDiff line numberDiff line change
@@ -2815,22 +2815,64 @@ def interpolate(
28152815
"""Turns this :class:`~.Mobject` into an interpolation between ``mobject1``
28162816
and ``mobject2``.
28172817
2818+
The interpolation is applied to the points and color of the mobject.
2819+
2820+
Parameters
2821+
----------
2822+
mobject1
2823+
The starting Mobject
2824+
mobject2
2825+
The target Mobject
2826+
alpha
2827+
Interpolation factor between 0 (at mobject1) and 1 (at mobject2)
2828+
path_func
2829+
The function defining the interpolation path. Defaults to a straight path.
2830+
2831+
Returns
2832+
-------
2833+
:class:`Mobject`
2834+
``self``
2835+
2836+
2837+
.. note::
2838+
2839+
- Both mobjects must have the same number of points. If not, this will raise an error.
2840+
Use :meth:`~.VMobject.align_points` to match point counts beforehand if needed.
2841+
- This method is used internally by the :class:`~.Transform` animation
2842+
to interpolate between two mobjects during a transformation.
2843+
28182844
Examples
28192845
--------
28202846
2821-
.. manim:: DotInterpolation
2847+
.. manim:: InterpolateExample
28222848
:save_last_frame:
28232849
2824-
class DotInterpolation(Scene):
2850+
class InterpolateExample(Scene):
28252851
def construct(self):
2826-
dotR = Dot(color=DARK_GREY)
2827-
dotR.shift(2 * RIGHT)
2828-
dotL = Dot(color=WHITE)
2829-
dotL.shift(2 * LEFT)
2830-
2831-
dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
2852+
# No need for point alignment:
2853+
dotL = Dot(color=DARK_GREY).to_edge(LEFT)
2854+
dotR = Dot(color=YELLOW).scale(10).to_edge(RIGHT)
2855+
dotMid1 = VMobject().interpolate(dotL, dotR, alpha=0.1)
2856+
dotMid2 = VMobject().interpolate(dotL, dotR, alpha=0.25)
2857+
dotMid3 = VMobject().interpolate(dotL, dotR, alpha=0.5)
2858+
dotMid4 = VMobject().interpolate(dotL, dotR, alpha=0.75)
2859+
dots = VGroup(dotL, dotR, dotMid1, dotMid2, dotMid3, dotMid4)
2860+
2861+
# Needs point alignment:
2862+
line = Line(ORIGIN, UP).to_edge(LEFT)
2863+
sq = Square(color=RED, fill_opacity=1, stroke_color=BLUE).to_edge(RIGHT)
2864+
line.align_points(sq)
2865+
mid1 = VMobject().interpolate(line, sq, alpha=0.1)
2866+
mid2 = VMobject().interpolate(line, sq, alpha=0.25)
2867+
mid3 = VMobject().interpolate(line, sq, alpha=0.5)
2868+
mid4 = VMobject().interpolate(line, sq, alpha=0.75)
2869+
linesquares = VGroup(line, sq, mid1, mid2, mid3, mid4)
2870+
2871+
self.add(VGroup(dots, linesquares).arrange(DOWN, buff=1))
2872+
See also
2873+
--------
2874+
:class:`~.Transform`, :meth:`~.VMobject.align_points`, :meth:`~.VMobject.interpolate_color`
28322875
2833-
self.add(dotL, dotR, dotMiddle)
28342876
"""
28352877
self.points = path_func(mobject1.points, mobject2.points, alpha)
28362878
self.interpolate_color(mobject1, mobject2, alpha)

manim/mobject/types/vectorized_mobject.py

+5
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,11 @@ def align_points(self, vmobject: VMobject) -> Self:
17201720
-------
17211721
:class:`VMobject`
17221722
``self``
1723+
1724+
See also
1725+
--------
1726+
:meth:`~.Mobject.interpolate`, :meth:`~.Mobject.align_data`
1727+
17231728
"""
17241729
self.align_rgbas(vmobject)
17251730
# TODO: This shortcut can be a bit over eager. What if they have the same length, but different subpath lengths?

0 commit comments

Comments
 (0)