Time-based relationship
After
Click or tap to launch toward the impact point. Particles scatter after the collision.
Try it — drag, click, or tap inside the figure.
Open in p5 Web Editor Fork and experiment with this sketchConcept
AFTER means following a reference event. Trigger secondary effects once the primary event has occurred.
Translation strategy
Ways to express after in code:
- Event trigger: Detect collision or arrival, then change phase
- Consequences: Spawn particles, sounds, or state changes afterward
- Phases: Separate logic for before, during, and after the event
Key p5.js methods
Code pattern
Code pattern
1. Setup projectile and impact point
2. Move until collision
3. Run after-effects
4. Damp particle velocity over time
1. Setup projectile and impact point
let shot = { x: 50, y: 150, moving: false };let impact = { x: 200, y: 150, happened: false };2. Move until collision
if (dist(shot.x, shot.y, impact.x, impact.y) < threshold) { impact.happened = true;}3. Run after-effects
if (impact.happened) { /* spawn / move particles */ }4. Damp particle velocity over time
particle.vx *= 0.98; particle.vy *= 0.98;