GET KTU B.TECH RESULTS ON MAIL

Subscribe to our mailing list and get KTU results in your mail box. CLICK HERE

BOUNCING BALL - Computer Graphics Lab Programs in C Programming Language

Computer Graphics Lab Programs in C Programming Language -BOUNCING BALL


AIM
Write a program to implement bouncing of a ball over a horizontal plane.

ALGORITHM
Step 1: Start
Step 2: Draw the line in which it represents the floor using the line function.
line(0,310,650,310)
Step 3: Draw the circle representing the ball using the circle function.
Step 4: Enter into the loop for showing the movement of the ball.
Step 5: if(i%2==0) then make the ball bounce upward else make the ball bouce downwards.
Step 6: Stop.

PROGRAM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
intgd=DETECT,gm,i;
initgraph(&gd,&gm,"D:\\TC\\BGI");
for(i=0;i<600;i++)
{
line(0,410,750,410);
if(i%2==0)
{
circle(45+i,310,15);
setcolor(WHITE);
}

else
{
circle(60+i,395,15);
i=i+70;
}
delay(400);
cleardevice();
if(kbhit())
{
break;
}
}
getch();

}

OUTPUT
BOUNCING BALL - Computer Graphics Lab Programs in C Programming Language

Previous
Next Post »