Wednesday, April 24, 2013

Bouncing Balls Program Using C Graphics

Drawing curves, animated programs in C Graphics is fun. This article shows a demo of "Bouncing Balls" Program using C Graphics. I have also provided the source code. The logic here is to draw a circle at given (x,y) point. For each step increase X and Y position. Do this in a loop it looks like a moving ball. To make the ball bounce when the ball crosses or hits any of the boundary of the screen, then add logic to reverse the direction. If ball hits right or left boundary reverse the direction of X step. If the ball crosses the bottom or top, then reverse the direction of Y. This program has two important macros using which the number of balls and speed of the animation can be controlled.

Modify this macro to increase or decrease number of balls to draw. The below source code is tested and works perfectly when this count is between 1 to 44.

Modify value of this macro to increase or decrease animation or ball movement.
This value is supplied to delay() function in the program.

 I will be posting more such graphics programs, keep visiting this site and encourage us by liking our page at facebook.


Source code:
For More C Graphics example click here

Pin It
Related Posts Plugin for WordPress, Blogger...