C Program for Bouncing Ball Animation Using C Graphics

In this article, we will write a C program for Bouncing Ball Animation using C Graphics.

Program

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main() {
	int gd = DETECT, gm = DETECT;
	int x, y = 0, j, t = 400, c = 1;
	initgraph(&gd, &gm, "");
	setcolor(RED);
	setfillstyle(SOLID_FILL, RED);
	for (x = 40; x < 602; x++) {
		cleardevice();
		circle(x, y, 30);
		floodfill(x, y, RED);
		delay(40);
		if (y >= 400) {
			c = 0;
			t -= 20;
		}
		if (y <= (400 - t))
			    c = 1;
		y = y + (c ? 15 : -15);
	}
	getch();
}

Output

Related Programs

  • Computer Architecture Syllabus for BCA

    Computer Architecture Syllabus for BCA

  • C Program to check leap year using Ternary Operator.

    C Program to check leap year using Ternary Operator.

  • C# Program to Remove Duplicate Characters from a String

    C# Program to Remove Duplicate Characters from a String

  • Create a Prime Number Pyramid in C#

    Create a Prime Number Pyramid in C#

Similar Posts

Leave a Reply

Your email address will not be published.