Edit points, colors and submobjects to be identical to another :class:`~.Mobject` .. note:: If both match_height and match_width are ``True`` then the transformed :class:`~.Mobject` will match the height first and then the width. Parameters
(
self,
mobject: Mobject,
match_height: bool = False,
match_width: bool = False,
match_depth: bool = False,
match_center: bool = False,
stretch: bool = False,
)
| 3080 | raise NotImplementedError("Please override in a child class.") |
| 3081 | |
| 3082 | def become( |
| 3083 | self, |
| 3084 | mobject: Mobject, |
| 3085 | match_height: bool = False, |
| 3086 | match_width: bool = False, |
| 3087 | match_depth: bool = False, |
| 3088 | match_center: bool = False, |
| 3089 | stretch: bool = False, |
| 3090 | ) -> Self: |
| 3091 | """Edit points, colors and submobjects to be identical |
| 3092 | to another :class:`~.Mobject` |
| 3093 | |
| 3094 | .. note:: |
| 3095 | |
| 3096 | If both match_height and match_width are ``True`` then the transformed :class:`~.Mobject` |
| 3097 | will match the height first and then the width. |
| 3098 | |
| 3099 | Parameters |
| 3100 | ---------- |
| 3101 | match_height |
| 3102 | Whether or not to preserve the height of the original |
| 3103 | :class:`~.Mobject`. |
| 3104 | match_width |
| 3105 | Whether or not to preserve the width of the original |
| 3106 | :class:`~.Mobject`. |
| 3107 | match_depth |
| 3108 | Whether or not to preserve the depth of the original |
| 3109 | :class:`~.Mobject`. |
| 3110 | match_center |
| 3111 | Whether or not to preserve the center of the original |
| 3112 | :class:`~.Mobject`. |
| 3113 | stretch |
| 3114 | Whether or not to stretch the target mobject to match the |
| 3115 | the proportions of the original :class:`~.Mobject`. |
| 3116 | |
| 3117 | Examples |
| 3118 | -------- |
| 3119 | .. manim:: BecomeScene |
| 3120 | |
| 3121 | class BecomeScene(Scene): |
| 3122 | def construct(self): |
| 3123 | circ = Circle(fill_color=RED, fill_opacity=0.8) |
| 3124 | square = Square(fill_color=BLUE, fill_opacity=0.2) |
| 3125 | self.add(circ) |
| 3126 | self.wait(0.5) |
| 3127 | circ.become(square) |
| 3128 | self.wait(0.5) |
| 3129 | |
| 3130 | |
| 3131 | The following examples illustrate how mobject measurements |
| 3132 | change when using the ``match_...`` and ``stretch`` arguments. |
| 3133 | We start with a rectangle that is 2 units high and 4 units wide, |
| 3134 | which we want to turn into a circle of radius 3:: |
| 3135 | |
| 3136 | >>> from manim import Rectangle, Circle |
| 3137 | >>> import numpy as np |
| 3138 | >>> rect = Rectangle(height=2, width=4) |
| 3139 | >>> circ = Circle(radius=3) |