@@ -2840,22 +2840,64 @@ def interpolate(
2840
2840
"""Turns this :class:`~.Mobject` into an interpolation between ``mobject1``
2841
2841
and ``mobject2``.
2842
2842
2843
+ The interpolation is applied to the points and color of the mobject.
2844
+
2845
+ Parameters
2846
+ ----------
2847
+ mobject1
2848
+ The starting Mobject.
2849
+ mobject2
2850
+ The target Mobject.
2851
+ alpha
2852
+ Interpolation factor between 0 (at ``mobject1``) and 1 (at ``mobject2``).
2853
+ path_func
2854
+ The function defining the interpolation path. Defaults to a straight path.
2855
+
2856
+ Returns
2857
+ -------
2858
+ :class:`Mobject`
2859
+ ``self``
2860
+
2861
+
2862
+ .. note::
2863
+
2864
+ - Both mobjects must have the same number of points. If not, this will raise an error.
2865
+ Use :meth:`~.VMobject.align_points` to match point counts beforehand if needed.
2866
+ - This method is used internally by the :class:`~.Transform` animation
2867
+ to interpolate between two mobjects during a transformation.
2868
+
2843
2869
Examples
2844
2870
--------
2845
2871
2846
- .. manim:: DotInterpolation
2872
+ .. manim:: InterpolateExample
2847
2873
:save_last_frame:
2848
2874
2849
- class DotInterpolation (Scene):
2875
+ class InterpolateExample (Scene):
2850
2876
def construct(self):
2851
- dotR = Dot(color=DARK_GREY)
2852
- dotR.shift(2 * RIGHT)
2853
- dotL = Dot(color=WHITE)
2854
- dotL.shift(2 * LEFT)
2855
-
2856
- dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
2877
+ # No need for point alignment:
2878
+ dotL = Dot(color=DARK_GREY).to_edge(LEFT)
2879
+ dotR = Dot(color=YELLOW).scale(10).to_edge(RIGHT)
2880
+ dotMid1 = VMobject().interpolate(dotL, dotR, alpha=0.1)
2881
+ dotMid2 = VMobject().interpolate(dotL, dotR, alpha=0.25)
2882
+ dotMid3 = VMobject().interpolate(dotL, dotR, alpha=0.5)
2883
+ dotMid4 = VMobject().interpolate(dotL, dotR, alpha=0.75)
2884
+ dots = VGroup(dotL, dotR, dotMid1, dotMid2, dotMid3, dotMid4)
2885
+
2886
+ # Needs point alignment:
2887
+ line = Line(ORIGIN, UP).to_edge(LEFT)
2888
+ sq = Square(color=RED, fill_opacity=1, stroke_color=BLUE).to_edge(RIGHT)
2889
+ line.align_points(sq)
2890
+ mid1 = VMobject().interpolate(line, sq, alpha=0.1)
2891
+ mid2 = VMobject().interpolate(line, sq, alpha=0.25)
2892
+ mid3 = VMobject().interpolate(line, sq, alpha=0.5)
2893
+ mid4 = VMobject().interpolate(line, sq, alpha=0.75)
2894
+ linesquares = VGroup(line, sq, mid1, mid2, mid3, mid4)
2895
+
2896
+ self.add(VGroup(dots, linesquares).arrange(DOWN, buff=1))
2897
+ See also
2898
+ --------
2899
+ :class:`~.Transform`, :meth:`~.VMobject.align_points`, :meth:`~.VMobject.interpolate_color`
2857
2900
2858
- self.add(dotL, dotR, dotMiddle)
2859
2901
"""
2860
2902
self .points = path_func (mobject1 .points , mobject2 .points , alpha )
2861
2903
self .interpolate_color (mobject1 , mobject2 , alpha )
0 commit comments