mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
update example_scenes for AnimatingMethods
This commit is contained in:
parent
3dc0c7b0cb
commit
1253c18c54
3 changed files with 51 additions and 21 deletions
BIN
docs/source/_static/example_scenes/AnimatingMethods.mp4
Normal file
BIN
docs/source/_static/example_scenes/AnimatingMethods.mp4
Normal file
Binary file not shown.
Binary file not shown.
|
@ -28,22 +28,51 @@ SquareToCircle
|
||||||
This scene is what we wrote in :doc:`quickstart`.
|
This scene is what we wrote in :doc:`quickstart`.
|
||||||
No more explanation here
|
No more explanation here
|
||||||
|
|
||||||
WarpSquare
|
AnimatingMethods
|
||||||
----------
|
----------------
|
||||||
|
|
||||||
.. manim-example:: WarpSquare
|
.. manim-example:: AnimatingMethods
|
||||||
:media: ../_static/example_scenes/WarpSquare.mp4
|
:media: ../_static/example_scenes/AnimatingMethods.mp4
|
||||||
|
|
||||||
class WarpSquare(Scene):
|
class AnimatingMethods(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
square = Square()
|
grid = Tex(r"\pi").get_grid(10, 10, height=4)
|
||||||
self.play(square.apply_complex_function, np.exp)
|
self.add(grid)
|
||||||
|
|
||||||
|
# If you pass in a mobject method to the scene's "play" function,
|
||||||
|
# it will apply an animation interpolating between the mobject's
|
||||||
|
# initial state and whatever happens when you apply that method.
|
||||||
|
# For example, calling grid.shift(2 * LEFT) would shift it two units
|
||||||
|
# to the left, but the following line animates that motion.
|
||||||
|
self.play(grid.shift, 2 * LEFT)
|
||||||
|
# The same applies for any method, including those setting colors.
|
||||||
|
self.play(grid.set_submobject_colors_by_gradient, BLUE, GREEN)
|
||||||
|
self.play(grid.set_height, TAU - MED_SMALL_BUFF)
|
||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
The new usage in this scene is ``self.play(square.apply_complex_function, np.exp)``,
|
# The method Mobject.apply_complex_function lets you apply arbitrary
|
||||||
which shows an animation of applying a complex function :math:`f(z)=e^z` to a square.
|
# complex functions, treating the points defining the mobject as
|
||||||
It is equivalent to transforming the original square into the result after
|
# complex numbers.
|
||||||
applying a function.
|
self.play(grid.apply_complex_function, np.exp, run_time=5)
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
# Even more generally, you could apply Mobject.apply_function,
|
||||||
|
# which takes in functions form R^3 to R^3
|
||||||
|
self.play(
|
||||||
|
grid.apply_function,
|
||||||
|
lambda p: [
|
||||||
|
p[0] + 0.5 * math.sin(p[1]),
|
||||||
|
p[1] + 0.5 * math.sin(p[0]),
|
||||||
|
p[2]
|
||||||
|
],
|
||||||
|
run_time=5,
|
||||||
|
)
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
The new usage in this scene is ``.get_grid()`` and ``self.play(mob.method, args)``.
|
||||||
|
|
||||||
|
- ``.get_grid()`` method will return a new mobject containing multiple copies of this one arranged in a grid.
|
||||||
|
- ``self.play(mob.method, args)`` animate the method, and the details are in the comments above.
|
||||||
|
|
||||||
TextExample
|
TextExample
|
||||||
-----------
|
-----------
|
||||||
|
@ -289,10 +318,11 @@ UpdatersExample
|
||||||
)
|
)
|
||||||
self.wait(4 * PI)
|
self.wait(4 * PI)
|
||||||
|
|
||||||
The new classes and usage in this scene are ``DecimalNumber``, ``.to_edge()``,
|
The new classes and usage in this scene are ``always_redraw()``, ``DecimalNumber``, ``.to_edge()``,
|
||||||
``.center()``, ``always_become()``, ``always()``, ``f_always()``, ``.set_y()`` and ``.add_updater()``.
|
``.center()``, ``always()``, ``f_always()``, ``.set_y()`` and ``.add_updater()``.
|
||||||
|
|
||||||
- ``DecimalNumber`` is a variable number, speed it up by breaking it into ``Tex`` characters.
|
- ``always_redraw()`` function create a new mobject every frame.
|
||||||
|
- ``DecimalNumber`` is a variable number, speed it up by breaking it into ``Text`` characters.
|
||||||
- ``.to_edge()`` means to place the object on the edge of the screen.
|
- ``.to_edge()`` means to place the object on the edge of the screen.
|
||||||
- ``.center()`` means to place the object in the center of the screen.
|
- ``.center()`` means to place the object in the center of the screen.
|
||||||
- ``always(f, x)`` means that a certain function (``f(x)``) is executed every frame.
|
- ``always(f, x)`` means that a certain function (``f(x)``) is executed every frame.
|
||||||
|
|
Loading…
Add table
Reference in a new issue