Used to animate the application of any method of :code:`self`. Any method called on :code:`animate` is converted to an animation of applying that method on the mobject itself. For example, :code:`square.set_fill(WHITE)` sets the fill color of a square, while :code:`
(self)
| 296 | |
| 297 | @property |
| 298 | def animate(self) -> _AnimationBuilder | Self: |
| 299 | """Used to animate the application of any method of :code:`self`. |
| 300 | |
| 301 | Any method called on :code:`animate` is converted to an animation of applying |
| 302 | that method on the mobject itself. |
| 303 | |
| 304 | For example, :code:`square.set_fill(WHITE)` sets the fill color of a square, |
| 305 | while :code:`square.animate.set_fill(WHITE)` animates this action. |
| 306 | |
| 307 | Multiple methods can be put in a single animation once via chaining: |
| 308 | |
| 309 | :: |
| 310 | |
| 311 | self.play(my_mobject.animate.shift(RIGHT).rotate(PI)) |
| 312 | |
| 313 | .. warning:: |
| 314 | |
| 315 | Passing multiple animations for the same :class:`Mobject` in one |
| 316 | call to :meth:`~.Scene.play` is discouraged and will most likely |
| 317 | not work properly. Instead of writing an animation like |
| 318 | |
| 319 | :: |
| 320 | |
| 321 | self.play( |
| 322 | my_mobject.animate.shift(RIGHT), my_mobject.animate.rotate(PI) |
| 323 | ) |
| 324 | |
| 325 | make use of method chaining. |
| 326 | |
| 327 | Keyword arguments that can be passed to :meth:`.Scene.play` can be passed |
| 328 | directly after accessing ``.animate``, like so:: |
| 329 | |
| 330 | self.play(my_mobject.animate(rate_func=linear).shift(RIGHT)) |
| 331 | |
| 332 | This is especially useful when animating simultaneous ``.animate`` calls that |
| 333 | you want to behave differently:: |
| 334 | |
| 335 | self.play( |
| 336 | mobject1.animate(run_time=2).rotate(PI), |
| 337 | mobject2.animate(rate_func=there_and_back).shift(RIGHT), |
| 338 | ) |
| 339 | |
| 340 | .. seealso:: |
| 341 | |
| 342 | :func:`override_animate` |
| 343 | |
| 344 | |
| 345 | Examples |
| 346 | -------- |
| 347 | |
| 348 | .. manim:: AnimateExample |
| 349 | |
| 350 | class AnimateExample(Scene): |
| 351 | def construct(self): |
| 352 | s = Square() |
| 353 | self.play(Create(s)) |
| 354 | self.play(s.animate.shift(RIGHT)) |
| 355 | self.play(s.animate.scale(2)) |