0% found this document useful (0 votes)
13 views

Bouncing Ball: #Include #Include #Include #Include

This C program uses graphics functions to simulate a bouncing red ball. It initializes the graphics screen and sets the color to red. It then uses a for loop and delay to repeatedly clear the screen, draw a filled red circle at changing x and y coordinates, representing the ball's position. The y coordinate is increased or decreased on each iteration to simulate bouncing, with conditions to reverse direction when it reaches the top or bottom borders.

Uploaded by

Mayur Odedra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Bouncing Ball: #Include #Include #Include #Include

This C program uses graphics functions to simulate a bouncing red ball. It initializes the graphics screen and sets the color to red. It then uses a for loop and delay to repeatedly clear the screen, draw a filled red circle at changing x and y coordinates, representing the ball's position. The y coordinate is increased or decreased on each iteration to simulate bouncing, with conditions to reverse direction when it reaches the top or bottom borders.

Uploaded by

Mayur Odedra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

www.cglabprograms.

com

Dipin Krishna

Bouncing Ball
#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
c
t
}
if (y
c
y = y

>= 400) {
= 0;
-= 20;
<= (400 - t))
= 1;
+ (c ? 15 : -15);

}
getch();
}

www.cglabprograms.com

Dipin Krishna

You might also like