Try It

Click to watch the circle move across the room from one wall to the other.

Concept

ACROSS means moving from one side of something to the other side, typically crossing over or through a barrier, space, or boundary.

Translation Strategy

To create "across" relationships on screen:

Key P5.js Methods

Linear Movement:
lerp(start, stop, amount) - Smooth interpolation between start and end points
• Calculate progress: progress += speed where speed is small increment

Path Planning:
• Define waypoints for complex crossing paths
• Use arrays to store multiple crossing points

Drawing Elements:
ellipse(x, y, width, height) - Draw moving objects
rect(x, y, width, height) - Draw barriers to cross
line(x1, y1, x2, y2) - Draw crossing paths

State Management:
• Track crossing progress and completion
• Use boolean flags for different crossing states

Mouse Interaction:
mousePressed() - Start or reset crossing animation
• Button-based controls for animation

Code Structure

Basic Pattern for "Across":

1. Define crossing path: Set start and end points
let startPoint = {x: 50, y: 150};
let endPoint = {x: 350, y: 150};
let barrier = {x: 180, y: 50, width: 40, height: 200};

2. Track progress: Use interpolation for smooth movement
let progress = 0; // 0 to 1
let currentX = lerp(startPoint.x, endPoint.x, progress);
let currentY = lerp(startPoint.y, endPoint.y, progress);

3. Update animation: Increment progress each frame
if (isMoving && progress < 1) {
  progress += 0.02; // Speed of crossing
}

4. Detect crossing completion: Check when movement is done
if (progress >= 1) { isMoving = false; hasCrossed = true; }