@@ -224,6 +224,19 @@ <h1 class="hero-title">Wizard Loop</h1>
224224 let width = window . innerWidth ;
225225 let height = window . innerHeight ;
226226 let particles = [ ] ;
227+ // Mouse/finger tracking for particle repulsion
228+ let mouse = { x : width / 2 , y : height / 2 } ;
229+ function handleMove ( e ) {
230+ if ( e . touches && e . touches . length ) {
231+ mouse . x = e . touches [ 0 ] . clientX ;
232+ mouse . y = e . touches [ 0 ] . clientY ;
233+ } else {
234+ mouse . x = e . clientX ;
235+ mouse . y = e . clientY ;
236+ }
237+ }
238+ window . addEventListener ( 'mousemove' , handleMove ) ;
239+ window . addEventListener ( 'touchmove' , handleMove ) ;
227240 function resize ( ) {
228241 width = window . innerWidth ;
229242 height = window . innerHeight ;
@@ -281,6 +294,16 @@ <h1 class="hero-title">Wizard Loop</h1>
281294 p . y += p . dy ;
282295 if ( p . x < 0 || p . x > width ) p . dx *= - 1 ;
283296 if ( p . y < 0 || p . y > height ) p . dy *= - 1 ;
297+ // Repel from mouse/finger
298+ let dist = Math . hypot ( p . x - mouse . x , p . y - mouse . y ) ;
299+ if ( dist < 120 ) {
300+ let angle = Math . atan2 ( p . y - mouse . y , p . x - mouse . x ) ;
301+ p . dx += Math . cos ( angle ) * 0.3 ;
302+ p . dy += Math . sin ( angle ) * 0.3 ;
303+ }
304+ // Limit speed
305+ p . dx = Math . max ( Math . min ( p . dx , 2 ) , - 2 ) ;
306+ p . dy = Math . max ( Math . min ( p . dy , 2 ) , - 2 ) ;
284307 }
285308 }
286309 function animate ( ) {
0 commit comments