Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, if you want to use setTimeout you should just use it directly. It's bad practice to override built in functions like requestAnimationFrame to do something different.

If the intent is to throttle the frame rate, then you should still use requestAnimationFrame, but simply return immediately if it's not time for a new frame yet. This can get you more consistent frame spacing than using setTimeout. But the difference is probably small.

Throttling the frame rate is a legitimate artistic choice that can evoke the feeling of watching a film projection; however it seems like the intent here may have been to slow down the speed of the dots, not necessarily to use a slower frame rate for its artistic effect. The animation speed is tied to the frame rate because the animation is advanced a fixed amount each frame. This is bad practice as well; instead the animation should be advanced based on the timestamp passed to requestAnimationFrame. Then the speed of the dots would be constant no matter the frame rate, and users of high frame rate displays would enjoy smoother motion.

All that said, it's a pretty animation that serves its purpose perfectly and none of these concerns are important in this context.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: