active

Canvas Particle System

Safe

HTML5 Canvas particle fountain with gravity, color palettes, and fade trails. Beginner-friendly visual demo.

@api/canvas-particle-system

gamedev
canvas
visual
particles
beginner

Canvas Particle System

Difficulty: Beginner | Runtime: HTML5 Canvas | Output: Visual animation

Teach an AI agent to generate a colorful particle fountain with gravity, fade trails, and configurable color palettes using the HTML5 Canvas API.

What You'll Build

A self-contained HTML file that renders an animated particle system:

  • Particles spray upward from the bottom center of the canvas
  • Gravity pulls particles back down in natural arcs
  • Each particle has a random color from a curated palette
  • Particles fade out as they age, creating trailing effects
  • The system runs at 60fps using requestAnimationFrame

Core Concepts

1. Particle Data Structure

Each particle tracks position, velocity, age, and color:

javascript
{
  x: number,       // horizontal position
  y: number,       // vertical position
  vx: number,      // horizontal velocity
  vy: number,      // vertical velocity
  life: number,    // remaining life (0-1)
  color: string,   // HSL color string
  size: number     // radius in pixels
}

2. Physics Update Loop

Every frame:

  1. Emit new particles at the source point
  2. Update each particle's position: x += vx, y += vy
  3. Apply gravity: vy += GRAVITY
  4. Age particles: life -= decay
  5. Remove dead particles (life <= 0)
  6. Render each particle as a filled circle with alpha = life

3. Color Palettes

Use HSL color space for vibrant, varied particles:

  • Fire: hues 0-60 (red → yellow)
  • Ocean: hues 180-240 (cyan → blue)
  • Forest: hues 90-150 (green spectrum)
  • Rainbow: random hue 0-360

Instructions

  1. Create an HTML file with a full-viewport <canvas>
  2. Set up the animation loop with requestAnimationFrame
  3. Implement the particle emitter at bottom-center
  4. Add gravity and fade effects
  5. Use semi-transparent background fills for trail effects

Parameters

ParameterDefaultDescription
PARTICLE_COUNT5Particles emitted per frame
GRAVITY0.15Downward acceleration
SPEED4Initial velocity magnitude
DECAY0.012Life reduction per frame
TRAIL_ALPHA0.08Background clear opacity (lower = longer trails)
Dormant$0/mo

$20 more to next tier

Info

Created February 11, 2026
Version 1.0.0
User-invoked
HTML sandbox

Demo

Interactive sandbox

Embed

Add this skill card to any webpage.

<iframe src="https://skillslap.com/skill/428c22af-467c-4b0c-9b47-bc40e2e667d0/embed"
        width="400" height="200"
        style="border:none;border-radius:12px;"
        title="SkillSlap Skill: Canvas Particle System">
</iframe>