movement¶
- class janim.anims.movement.Homotopy(item: Item, homotopy: Callable[[float, float, float, float], Vect], *, duration: float = 3.0, root_only: bool = False, **kwargs)¶
基类:
DataUpdater一个从 (x, y, z, t) 到 (x’, y’, z’) 的函数
t 的取值范围是 [0, 1],表示动画进度
HomotopyExample ¶
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)
- class janim.anims.movement.ComplexHomotopy(item: Item, complex_homotopy: Callable[[complex, float], complex], **kwargs)¶
基类:
Homotopy与 Homotopy 类似,区别是用复数描述坐标
ComplexHomotopyExample ¶
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)
- class janim.anims.movement.MoveAlongPath(item: Item, path: VItem, *, root_only: bool = False, **kwargs)¶
基类:
DataUpdater
MoveAlongPathExample ¶
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)