Bouncing balls in a box – JavaScript

bouncing balls

screen shot

As it is clear from the title, this post is about creating a box with balls bouncing after hitting the walls using JavaScript and HTML5 canvas. More precisely the box is initially empty, balls are added eventually by clicking the surface of box. Apparently i can’t embed JS in the wordpress post, so check this plunk to visualize it. I will go through the code briefly here.


Create a canvas element with onclick event handler, add some styles to it.



Brief explanation is given in the fiddle.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s