I was using an AI assistant to help me create an infinitely scrolling grid animation where the speed and direction of the animation were dependent on the mouse cursor position.
Now, while this animation is sorta kinda fine as it is, there are some big and small issues that we should address in order to call this ready for prime time. Can you spot what some of those issues are?
Or to put it differently, if you were someone who was well versed in web animation techniques, what are some things that you would add or do differently?
Seems like there are some sharp lines and DPI issues that make the grid blurry.
You’d probably want a mouseout event to hide the crosshairs when you leave the grid.
In Safari at least, you’re not going to get >60 FPS updates unless you disable Prefer Page Rendering Updates near 60fps.
Ideally you’d ease between animation directions; like if your mouse moves instantly from 0, 0 to 1000, 1000, the direction and speed will statelessly update to the new value.
There are a bunch of useless semicolons cluttering up the JS.
Negative offsets grow forever when moving leftwards or upwards, which could make the loop draw thousands of lines per frame and kill performance.
Crosshair gets drawn twice, once on mousemove and again in requestAnimationFrame. As a result, the event draw is pointless since the frame loop handles it anyway.
requestAnimationFrame(animate) runs continuously, even if velocityX and velocityY are both zero and the grid isn’t moving.
Motion should ideally have some acceleration, currently it’s purely linear.