diff --git a/doc/source/_static/videos/ComplexHomotopyExample.mp4 b/doc/source/_static/videos/ComplexHomotopyExample.mp4 new file mode 100644 index 0000000..eef6734 Binary files /dev/null and b/doc/source/_static/videos/ComplexHomotopyExample.mp4 differ diff --git a/doc/source/_static/videos/HomotopyExample.mp4 b/doc/source/_static/videos/HomotopyExample.mp4 new file mode 100644 index 0000000..e06384d Binary files /dev/null and b/doc/source/_static/videos/HomotopyExample.mp4 differ diff --git a/doc/source/_static/videos/MoveAlongPathExample.mp4 b/doc/source/_static/videos/MoveAlongPathExample.mp4 new file mode 100644 index 0000000..d68112e Binary files /dev/null and b/doc/source/_static/videos/MoveAlongPathExample.mp4 differ diff --git a/doc/source/janim/anims/movement.rst b/doc/source/janim/anims/movement.rst index 13e3059..c8755c2 100644 --- a/doc/source/janim/anims/movement.rst +++ b/doc/source/janim/anims/movement.rst @@ -1,8 +1,75 @@ movement ======== -.. automodule:: janim.anims.movement - :members: - :undoc-members: - :show-inheritance: +.. autoclass:: janim.anims.movement.Homotopy + :show-inheritance: +.. janim-example:: HomotopyExample + :media: ../../_static/videos/HomotopyExample.mp4 + + from janim.imports import * + + class HomotopyExample(Timeline): + def construct(self): + def homotopy_func(x, y, z, t): + return [x * t, y * t, z] + + square = Square() + self.play(Homotopy(square, homotopy_func)) + self.forward(0.3) + +.. autoclass:: janim.anims.movement.ComplexHomotopy + :show-inheritance: + +.. janim-example:: ComplexHomotopyExample + :media: ../../_static/videos/ComplexHomotopyExample.mp4 + + from janim.imports import * + + class ComplexHomotopyExample(Timeline): + def construct(self): + def complex_func(z: complex, t: float) -> complex: + return interpolate(z, z**3, t) + + group = Group( + Text('Text'), + Square(side_length=1), + ) + group.points.arrange(RIGHT, buff=2) + + self.play( + *[ComplexHomotopy( + item, + complex_func + ) for item in group] + ) + self.forward(0.3) + +.. autoclass:: janim.anims.movement.MoveAlongPath + :show-inheritance: + +.. janim-example:: MoveAlongPathExample + :media: ../../_static/videos/MoveAlongPathExample.mp4 + + from janim.imports import * + + class MoveAlongPathExample(Timeline): + def construct(self) -> None: + line = Line(ORIGIN, RIGHT * Config.get.frame_width, buff=1) + dot1 = Dot(color=YELLOW) + + curve = ParametricCurve( + lambda t: [math.cos(t) * t * 0.2, math.sin(t) * t * 0.2, 0], + (0, 10, 0.1) + ) + dot2 = Dot(color=YELLOW) + + group = Group(line, curve).show() + group.points.arrange(DOWN) + + self.play( + MoveAlongPath(dot1, line), + MoveAlongPath(dot2, curve), + duration=2 + ) + self.forward(0.3) diff --git a/janim/anims/movement.py b/janim/anims/movement.py index a7159f8..5842cf6 100644 --- a/janim/anims/movement.py +++ b/janim/anims/movement.py @@ -12,6 +12,11 @@ class Homotopy(DataUpdater): + ''' + 一个从 (x, y, z, t) 到 (x’, y’, z’) 的函数 + + t 的取值范围是 [0, 1],表示动画进度 + ''' def __init__( self, item: Item, @@ -21,11 +26,6 @@ def __init__( root_only: bool = False, **kwargs ): - ''' - 一个从 (x, y, z, t) 到 (x’, y’, z’) 的函数 - - t 的取值范围是 [0, 1],表示动画进度 - ''' self.homotopy = homotopy super().__init__( item, @@ -47,15 +47,15 @@ def fn(point: np.ndarray) -> Vect: class ComplexHomotopy(Homotopy): + ''' + 与 Homotopy 类似,区别是用复数描述坐标 + ''' def __init__( self, item: Item, complex_homotopy: Callable[[complex, float], complex], **kwargs ): - ''' - 与 Homotopy 类似,区别是用复数描述坐标 - ''' def homotopy(x, y, z, t): c = complex_homotopy(complex(x, y), t) return (c.real, c.imag, z)