Movement & direction

Along

Click or tap to start the circle moving along the curved path.

Fig. 1 Path following — position sampled along connected waypoints

Try it — drag, click, or tap inside the figure.

Open in p5 Web Editor Fork and experiment with this sketch

Concept

ALONG means following the length, edge, or course of something—not crossing it.

Translation strategy

Ways to express along in a sketch:

  • Waypoints: Store an ordered list of path points
  • Progress index: Move between consecutive points over time
  • Curves: Use vertices, Bézier points, or parametric math for smooth paths
Key p5.js methods
Key methods

Path
• Arrays of points; lerp() between them
beginShape(), vertex() — draw the route

Pointer input
mousePressed() — start motion or set a target
mouseX, mouseY — click position
Code pattern
Code pattern

1. Define the path
let path = [{x:50,y:150},{x:150,y:100},{x:250,y:200},{x:350,y:150}];

2. Track progress along segments
let progress = 0; // 0 … path.length - 1

3. Interpolate between two points
let a = path[floor(progress)];
let b = path[ceil(progress)];
let t = progress - floor(progress);
let x = lerp(a.x, b.x, t);

4. Advance each frame
if (isMoving) progress += speed;