Thursday, August 16, 2012

Program to generate various random line on display screen in Computer Graphics using C/C++

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<time.h>
#include<stdlib.h>
#include<dos.h>
int main(void)
{
/* request auto detection */
int gdriver=DETECT,gmode,errorcode;
int xmax,ymax;
int x=420,y=420;
/*initialize graphics and local variable*/
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
/*read result of intialization */
errorcode=graphresult();
/* an error occured */
if(errorcode!=grOk)
{
printf("graphics error:%s \n",grapherrormsg(errorcode));
printf("press any key to halt:");
getch();
exit(1);
}
while(!kbhit())
{
setcolor(random(getmaxcolor()));   //to set current drawing color
xmax=getmaxx();   //maximum x co-ordinate 
ymax=getmaxy();   //maximum y co-ordinate 
/*to draw a digonal line */
line(random(x),random(y),random(xmax),random(ymax));
delay(80);
}
//clean up
getch();
closegraph();
return 0;
}


No comments:

Post a Comment