@@ -2815,22 +2815,64 @@ def interpolate(
2815
2815
"""Turns this :class:`~.Mobject` into an interpolation between ``mobject1``
2816
2816
and ``mobject2``.
2817
2817
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
+
2818
2844
Examples
2819
2845
--------
2820
2846
2821
- .. manim:: DotInterpolation
2847
+ .. manim:: InterpolateExample
2822
2848
:save_last_frame:
2823
2849
2824
- class DotInterpolation (Scene):
2850
+ class InterpolateExample (Scene):
2825
2851
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`
2832
2875
2833
- self.add(dotL, dotR, dotMiddle)
2834
2876
"""
2835
2877
self .points = path_func (mobject1 .points , mobject2 .points , alpha )
2836
2878
self .interpolate_color (mobject1 , mobject2 , alpha )
0 commit comments