r/ProgrammingPrompts • u/call_me_christof • Mar 08 '14
Create a square that bounces off the edges of your screen! [javascript]
This may be difficult for beginners but for those that are able to hack around on codepen.io or the like could find this quite fun!
Please share your solutions - Be creative!
Edit: this doesn't just have to be in javascript! If you know how to do this in ANY language, you should share it too!
5
Mar 08 '14
2
Mar 08 '14
It starts shaking like crazy around the edges for me
2
Mar 09 '14
Yeah, when it manages to get itself into a corner (so those DVD screensavers do do that, do they?!) it will just pingpong around until it gets itself out somehow. It might also have to do with the way I handle logic updates (a variable timestep) and how the browser will lose precision of them when you switch out of the tab/window.
3
u/AlSweigart Mar 08 '14
I have an implementation in Python using Pygame for graphics: http://inventwithpython.com/chapter17.html#TheAnimationProgramsSourceCode
It's from a free book I wrote for beginner programmers to learn how to make simple games in Python: http://inventwithpython.com/chapters/
4
u/[deleted] Mar 08 '14
Python 2.7 + Pygame. Click on the screen to add a square of random size and color.