A community-maintained Python framework for creating mathematical animations.
Added :meth:`~.Mobject.match_points` (#1364)
Darylgoldenab1023b1358a
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex a2a766384..7cdb7c854 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -2274,8 +2274,8 @@ class Mobject(Container):class BecomeScene(Scene):def construct(self):- circ = Circle(fill_color=RED)- square = Square(fill_color=BLUE)+ circ = Circle(fill_color=RED, fill_opacity=0.8)+ square = Square(fill_color=BLUE, fill_opacity=0.2)self.add(circ)self.wait(0.5)circ.become(square)@@ -2287,6 +2287,28 @@ class Mobject(Container):sm1.interpolate_color(sm1, sm2, 1)return self+ def match_points(self, mobject: "Mobject", copy_submobjects: bool = True):+ """Edit points, positions, and submobjects to be identical+ to another :class:`~.Mobject`, while keeping the style unchanged.++ Examples+ --------+ .. manim:: MatchPointsScene++ class MatchPointsScene(Scene):+ def construct(self):+ circ = Circle(fill_color=RED, fill_opacity=0.8)+ square = Square(fill_color=BLUE, fill_opacity=0.2)+ self.add(circ)+ self.wait(0.5)+ self.play(circ.animate.match_points(square))+ self.wait(0.5)+ """+ self.align_data(mobject)+ for sm1, sm2 in zip(self.get_family(), mobject.get_family()):+ sm1.points = np.array(sm2.points)+ return self+# Errorsdef throw_error_if_no_points(self):if config.renderer == "opengl":diff --git a/tests/control_data/graphical_units_data/transform/MatchPointsScene.npz b/tests/control_data/graphical_units_data/transform/MatchPointsScene.npznew file mode 100644index 000000000..2e5ef8841Binary files /dev/null and b/tests/control_data/graphical_units_data/transform/MatchPointsScene.npz differdiff --git a/tests/test_graphical_units/test_transform.py b/tests/test_graphical_units/test_transform.pyindex 6df8fa1bc..5e4a8fdf8 100644--- a/tests/test_graphical_units/test_transform.py+++ b/tests/test_graphical_units/test_transform.py@@ -132,6 +132,13 @@ class FadeInAndOutTest(Scene):self.play(FadeOut(square))+class MatchPointsScene(Scene):+ def construct(self):+ circ = Circle(fill_color=RED, fill_opacity=0.8)+ square = Square(fill_color=BLUE, fill_opacity=0.2)+ self.play(circ.animate.match_points(square))++class AnimationBuilderTest(Scene):def construct(self):self.play(Square().animate.shift(RIGHT).rotate(PI / 4))