Movement & direction

Away

Click or tap to set a source point. The circle moves away from it, increasing distance each frame.

Fig. 1 Outward vector — distance from the source increases over time

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

Open in p5 Web Editor Fork and experiment with this sketch

Concept

AWAY means moving in the opposite direction from a reference point. Use the vector from source to object, then continue outward along it.

Translation strategy

Ways to express away in a sketch:

  • Outward vector: Subtract source from object position to get direction
  • Step each frame: Add the normalized vector times speed
  • Boundaries: Use constrain() or wrap at canvas edges
Key p5.js methods
Key methods

Vector math
dist() — distance from source
constrain() — keep the object on screen

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

1. Store mover and source
let mover = { x: 200, y: 150, speed: 2 };
let source = { x: 100, y: 100 };

2. Find outward direction
let dx = mover.x - source.x;
let dy = mover.y - source.y;
let d = dist(mover.x, mover.y, source.x, source.y);

3. Step away
if (d > 0) {
  mover.x += (dx / d) * mover.speed;
  mover.y += (dy / d) * mover.speed;
}

4. Set source on click
source.x = mouseX; source.y = mouseY;