diff --git a/demo-02/README.md b/demo-02/README.md new file mode 100644 index 0000000..b01ae22 --- /dev/null +++ b/demo-02/README.md @@ -0,0 +1,8 @@ +# Demo 2: Fixing an Issue, Adding a new Feature + +- `demo-01.index.html` has the output of a former run of `../demo1` +- There is an issue where the background flickers as the last few particles + fade out. Smooth out the rapid color change. +- Add a new feature: clicking should cause a burst of particles as well as + a shift in the overall hue. +- The output of a previous plan is in `old-plan.md`. diff --git a/demo-02/demo-01.index.html b/demo-02/demo-01.index.html new file mode 100644 index 0000000..0a6115f --- /dev/null +++ b/demo-02/demo-01.index.html @@ -0,0 +1,227 @@ + + + + + + Particle Trail Effect + + + + + +
+

Particle Trail

+

Move your cursor to create the magic

+
+ + + + diff --git a/demo-02/old-plan.md b/demo-02/old-plan.md new file mode 100644 index 0000000..a8f5762 --- /dev/null +++ b/demo-02/old-plan.md @@ -0,0 +1,56 @@ +# Particle Burst Feature Plan + +## Overview +Add a click interaction that creates a radial burst of particles and shifts the color palette. + +## Implementation Details + +### 1. Global State Addition +Add a `hueOffset` variable to track the current color shift: +```javascript +let hueOffset = 0; // Shifts the particle color palette +``` + +### 2. Click Event Handler +Add to the script (after the mousemove listener): +```javascript +canvas.addEventListener('click', (e) => { + const clickX = e.clientX; + const clickY = e.clientY; + + // Shift hue for variety + hueOffset += 15 + Math.random() * 15; // Shift by 15-30 degrees + + // Create burst of particles + const burstCount = 40; + for (let i = 0; i < burstCount; i++) { + particles.push(new BurstParticle(clickX, clickY, hueOffset)); + } +}); +``` + +### 3. BurstParticle Class (or extend Particle) +Create particles with radial velocity: +- Position: click coordinates +- Angle: random 0 to 2π +- Speed: random range (e.g., 2-8) for varying distances +- Size: slightly larger than normal particles (6-12px) +- Decay: slightly faster for quick burst effect + +### 4. Particle Constructor Update +Modify the `Particle` constructor to accept an optional hue offset: +```javascript +constructor(x, y, hueShift = 0) { + // ... existing code ... + const hue = Math.random() * 60 + 180 + hueShift; // Blue-cyan + shift + this.color = `hsla(${hue}, 100%, 70%,`; +} +``` + +## File Changes +- **index.html**: Add click listener, hueOffset variable, and optional hueShift parameter to Particle + +## Visual Effect +- Each click creates an explosion of blue-cyan particles at the cursor +- Subsequent clicks shift the color palette gradually (e.g., cyan → green → yellow) +- Trail effect continues to work with the new particles