Skip to content

Move a ball along a curve

Use MotionPath and MoveAlong for a curved trajectory. A quadratic Bézier control point pulls the trajectory toward it. In this example the ball starts at (100, 320), lands at (600, 220) after 0.45 seconds, then returns to (120, 360).

from manifest import Circle, MotionPath, MoveAlong, Video2d

def build(seq, frame):
    ball = Circle(frame, (100, 320), 10, fill=(230, 240, 100))
    ball.name = 'Ball'
    serve = MotionPath.from_svg_path('M 100 320 Q 330 40 600 220')
    return_shot = MotionPath.from_svg_path('M 600 220 Q 360 60 120 360')
    seq.show(MoveAlong(ball, serve, time=0.45, relative=False))
    seq.show(MoveAlong(ball, return_shot, time=0.35, relative=False))
    seq.show(0.25)

def make_video():
    return Video2d(build, resolution=(800, 450), fps=60)

Coordinates are in the ball's parent coordinate system. relative=False uses the path's absolute coordinates. Reuse the trajectory builder for serve and return motions, and compose player movement alongside ball motion with Bundle. At 60 fps, inspect frames 0, 27, and 48 to see the start and both landings. Frames 48 through 63 hold the final position.