示例#1
0
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "C:\\Turboc3\\BGI");

   /* read result of initialization */
   errorcode = graphresult();
   /* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }

   setcolor(getmaxcolor());
   //xmax = getmaxx();
  // ymax = getmaxy();
   line(50,50,100,50);
   line(100,50,100,100);
   line(100,100,50,100);
   line(50,50,50,100);
   //printf("%d",getpixel(70,70));
   boundaryFill(70,70,getmaxcolor());
   getch();
   closegraph();
   return 0;
}
void  draw()
{
 setfillstyle(1,getmaxcolor());
   int a=getmaxcolor();
   bar(550,450,600,460);
   bar(450,450,500,460);
   setcolor(5);
   settextstyle(3,0,1);
   outtextxy(550,440," exit ");
   outtextxy(450,440," next ");

   setcolor(a);
   settextstyle(0,0,0);

}
示例#3
0
int main()
{
	/*request autodetection*/
	int gdriver=DETECT, gmode, errcode;
	int midx, midy;
	int stangle=4, endangle=135;
	int radius=100;

	/* intialize graphics and local variables */
	initgraph(&gdriver,&gmode, NULL);
	/* read result of initialization */
	errcode=graphresult();
	if (errcode!=grOK) {
	printf("Graphs error");
	getch();
	exit(1);
	}
	midx=getmaxx()/2;
	midy=getmaxy()/2;
	setcolor(getmaxcolor());

	arc(midx,midy,stangle,endangle,radius);
	getch();
	closegraph();
	return 0;
}
示例#4
0
main()
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   /* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }

   setcolor(getmaxcolor());
   xmax = 10;
   ymax = 10;

   /* draw a diagonal line */
   line(0, 0, xmax, ymax);

   /* clean up */
   getch();
  // closegraph();
   return 0;
}
示例#5
0
int main() {
	int unidad = 0,modo,i;
	char s[10];

	initgraph (&unidad,&modo,"c:\\bc\\bgi");
	if (graphresult() != 0) {
		cout << "Error al tratar de pasar al modo grafico\n";
		getch();
		return 1;
	}

	outtext ("UNIVERSIDAD");
	getch();
	setpalette (15,YELLOW);				// Cambia de color a UNIVERSIDAD
	getch();
	i = getmaxcolor();         		// Almacena en i 15
	itoa (i,s,10);
	outtextxy (0,10,s);     			// Escribe 15
	getch();
	i = i - 4;
	setcolor (--i);						// Cambia el calor a LIGHTGREEN  (10)
												// Pero no cambia nada sobre el video

	outtextxy (0,20,"UNIVERSIDAD");	// Escribe UNIVERSIDAD en LIGHTGREEN
	getch();
	return 0;
}
示例#6
0
文件: INITSVGA.C 项目: cout/sfdemo
/* Returns the color for white */
long WhitePixel()
{
  switch(getmaxcolor()) {
    case 32768: return 0x7fffL;
    case 65535: return 0xffffL;
    case 16777: return 0xffffffL;
    default   : return 15;
  };
}
示例#7
0
void drawParticles(PARTICLE * ps) {
  int i;
  int w = getmaxx() / 2;
  int h = getmaxy() / 2;
  for(i = 0; i != PARTICLE_NUMBER; i++) {
    setcolor((i % getmaxcolor()) + 1);
    circle(w + ps[i].position.x + orgX, h - ps[i].position.y - orgY, PARTICLE_RADIUS);
  }
}
void main()
{
    int gd,gm,x,y,z,o,x1,x2,y1,y2;
    detectgraph(&gd,&gm);
    initgraph(&gd,&gm,"e:\tc\bgi");

    setfillstyle(0,getmaxcolor());
    maxx=getmaxx();
    maxy=getmaxy();
    midx=maxx/2;
    midy=maxy/2;

    axis();

    bar3d(midx+50,midy-100,midx+60,midy-90,5,1);

    printf("Enter translation factor");
    scanf("%d%d",&x,&y);
    axis();
    printf("\nAfter translation: ");
    bar3d(midx+x+50,midy-(y+100),midx+x+60,midy-(y+90),5,1);

    axis();
    bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
    printf("\nEnter scaling factors: " );
    scanf("%d%d%d", &x,&y,&z);

    axis();
    printf("After scaling: ");
    bar3d(midx+(x*50),midy-(y*100),midx+(x*60),midy-(y*90),5*z,1);
    axis();


    bar3d(midx+50,midy-100,midx+60,midy-90,5,1);

    printf("\nEnter rotating angle: " );
    scanf("%d",&o);
    x1=50*cos(o*3.14/180)-100*sin(o*3.14/180);
    y1=50*sin(o*3.14/180)+100*cos(o*3.14/180);
    x2=60*cos(o*3.14/180)-90*sin(o*3.14/180);
    y2=60*sin(o*3.14/180)+90*cos(o*3.14/180);

    axis();
    printf("After rotation about z axis");
    bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1);
    axis();

    printf("\nAfter rotation  about x axis: ");
    bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1);

    axis();
    printf("\nAfter rotation about yaxis: ");
    bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1);
    getch();
    closegraph();
}
示例#9
0
void rtltrot()
{
	int driver=DETECT,mode,i,j=1,k,a[thala],b[thala],c[thala],d[thala],u,v,m,n,flag=0;
	initgraph(&driver,&mode,"d:\\tc\\bgi");
    for(i=265;i<360;i++,j++)
    {
     arc(300,150,i-1,i,100);
     getarccoords(&t);
     a[thala-j]=t.xend;
     b[thala-j]=t.yend;
    }
   for(i=85,j=1;i<180;i++,j++)
    {
     arc(300,150,i-1,i,100);
     getarccoords(&boss);
     c[thala-j]=boss.xend;
     d[thala-j]=boss.yend;
    }
  // cleardevice();
  setfillstyle(1,BLACK);
  bar(0,0,getmaxx(),getmaxy());
    line(200,150,400,150);
    line(200,250,400,250);
    line(200,350,400,350);
    while(flag==0)
    {
    a: for(i=0;i<thala;i++)
       {
       outtextxy(200,50,"  3D ROTATING RECTANGLE");
	line(a[i]-i,b[i]-i,c[i]+i,d[i]+i);
	u=(b[i]-i)-150;
	v=150-(d[i]+i);
	line(a[i]-i,350-u,c[i]+i,350+v);
	line(a[i]-i,b[i]-i,a[i]-i,350-u);
	line(c[i]+i,d[i]+i,c[i]+i,350+v);
	setfillstyle(1,2);
	floodfill(300,250,getmaxcolor());
	delay(100);
       //cleardevice();
	setfillstyle(1,BLACK);
	bar(100,100,500,400);
       }
       if(!kbhit())goto a;
       if(kbhit())	{
				flag=1;
			}
  }
 getch();
 rotmain();
}
示例#10
0
void updnrot()
{
int driver=DETECT,mode,i,j=0,k=0,a[95],b[95],c[95],d[95],u,v,h,flag=0;
initgraph(&driver,&mode,"d:\\tc\\bgi");
   for(i=90;i<185;i++,j++)
    {
     arc(400,230,i-1,i,100);
     getarccoords(&t);
     a[j]=t.xend;
     b[j]=t.yend;
     }

    for(i=270;i<365;i++,k++)
     {
      arc(400,230,i-1,i,100);
      getarccoords(&boss);
      c[k]=boss.xend;
      d[k]=boss.yend;
     }
  cleardevice();

  while(flag==0)
   {
  a: for(i=0;i<95;i+=5)
       {
	outtextxy(200,50,"  3D ROTATING RECTANGLE");
	putpixel(400,230,YELLOW);
	line(a[i]+i,b[i]+i,c[i]-i,d[i]-i);
	u=(400-(a[i]+i))+200;
	v=200-((c[i]-i)-400);
	line(u,b[i]+i,v,d[i]-i);
	line(a[i]+i,b[i]+i,u,b[i]+i);
	line(c[i]-i,d[i]-i,v,d[i]-i);
	setfillstyle(1,2);
	floodfill(370,230,getmaxcolor());
	delay(100);
	setfillstyle(1,BLACK);
	bar(100,100,500,400);
      }
      if(!kbhit())goto a;
  else if(kbhit())	{
				flag=1;
			}

  }

getch();
rotmain();
}
示例#11
0
void settime2( int hrs,int min, int sec)
{static float h,m,s;
setcolor(0);setlinestyle(1,1,0);
line(midx,midy,midx+RSEC*cos(s),midy+RSEC*sin(s));setlinestyle(0,1,2);
line(midx,midy,midx+RMIN*cos(m),midy+RMIN*sin(m));setlinestyle(0,1,3);
line(midx,midy,midx+RHRS*cos(h),midy+RHRS*sin(h));
h= (float)(hrs+(float)min/60+(float)sec/3600)*30-90;
m= (float)(min+(float)sec/60)*6-90;
s= (float)sec*6-90;
h*=RAD;m*=RAD;s*=RAD;
setcolor(getmaxcolor());setlinestyle(1,1,0);
line(midx,midy,midx+RSEC*cos(s),midy+RSEC*sin(s));setlinestyle(0,1,2);
line(midx,midy,midx+RMIN*cos(m),midy+RMIN*sin(m));setlinestyle(0,1,3);
line(midx,midy,midx+RHRS*cos(h),midy+RHRS*sin(h));
}
示例#12
0
void cInterface::drawFrame(int right,int bottom)			 // draw CUI
	{
	 setcolor(11);
	 setlinestyle(SOLID_LINE,1,NORM_WIDTH);
	 rectangle(2,2,right-2,bottom-2);	 		 //outer rectangle
	 rectangle(9,9,right-9,57);             	 //rectangle covering Heading
	 setlinestyle(SOLID_LINE,1,THICK_WIDTH);
	 rectangle(6,6,right-6,bottom-6);      		 //Innner recangle
	 line(6,60,right-6,60);                		 //makes upper line for Menu display
	 line(6,90,right-6,90);                		 //makes bottom line for menu display
	 line(6,440,right-6,440);              		 //makes line for selection section
	 
	 /* Plot some "stars"  for a sky like enviornment*/
	 for (int j=0 ; j<1000; ++j )
		{
		 putpixel(random(getmaxx()), random(getmaxy()), random( getmaxcolor()-1 )+1);
		} 
	}
示例#13
0
void DrawStar(void)
{
  int seed=2000;
  int i,dotx,doty,height,width,color,maxcolor;
  maxcolor=getmaxcolor();
  width=getmaxx();
  height=getmaxy();
  for(i=0;i<250;i++)
  {
    dotx=i+random(width-1);
    doty=i+random(height-1);
    color=random(maxcolor);
    setcolor(color);
    putpixel(dotx,doty,color);
    circle(dotx+1,doty+1,1);
  }
  srand(seed);
}
示例#14
0
unsigned
getpixel (int x, int y)
{
  gint i, maxi, ClosestS, s;
  XColor Color;
  unsigned RetVal = 0;
  XImage *Image;
  // Convert to viewport coordinates.
  x += TcViewLeft;
  y += TcViewTop;
  // Now do the interrogating.
  XLockDisplay (TcDisplay);
  Image = XGetImage (TcDisplay, TcPixmaps[TcVisualPage], x, y, 1, 1, 
  		     ~0L, XYPixmap);
  if (Image != NULL)
    {
      Color.pixel = XGetPixel (Image, 0, 0);
      XDestroyImage (Image);  
      // Look up the rgb components of the raw pixel we've read back.
      XQueryColor (TcDisplay, TcColormap, &Color);
      XUnlockDisplay (TcDisplay);
      // Find the closest-match color in our current palette.  Since the
      // colors in our palette are generally so far apart from each other,
      // we can save a lot of execution time by using a taxi-cab metric
      // rather than a Euclidean metric.
      ClosestS = 1000000;
      maxi = getmaxcolor ();
      for (i = 0; i <= maxi; i++)
        {
	  s = abs (Color.red - TcColors[i].r) + abs (Color.green - TcColors[i].g)
	      + abs (Color.blue - TcColors[i].b);
	  if (s < ClosestS)
	    {
	      RetVal = i;
	      ClosestS = s;
	    } 
	  if (s == 0)
	    break;   
	}
    }		     
  else  
    XUnlockDisplay (TcDisplay);
  return (RetVal);  
}
示例#15
0
int pacova::inicializa_modo_grafico()
{

  GraphDriver = VGA; 	     	/* Request auto-detection */
  GraphMode = VGAHI;
  initgraph(&GraphDriver, &GraphMode, "");
  ErrorCode = graphresult();		/* Read result of initialization */

  if(ErrorCode != grOk )		/* Error occured during init  */
	return ErrorCode;

  getpalette(&palette);			/* Read the palette from board*/
  max_cores = getmaxcolor() + 1;	/* Numero M�ximo de Cores */

  max_x = getmaxx();
  max_y = getmaxy();		     	/* Tamanho da Tela		  		*/

  return ErrorCode;
}
示例#16
0
main()
{   int ch,gd=DETECT,gm,h;
	while(1)
	{	menu();
		scanf("%d",&ch);
		switch(ch)
		{   case 1:  printf("\n ENTER THE NUMBER YOU WANT TO INSERT");
			  scanf("%d",&no);
			  if(root==NULL)
			  {   temp=(struct tree *)malloc(sizeof(struct tree));
				  temp->left=NULL;
				  temp->right=NULL;
				  temp->data=no;
				  root=temp;}
			  else
				 insert(root);
			  break;
			case 2:
			  if(root==NULL)
				 printf("\n THE TREE IS EMPTY ");
			  else
			   { initgraph(&gd,&gm,"E:\\tc\\BGI");
				 display(root,1,getmaxx()+1,15,1);  // 640 is the getmaxx
				 setcolor(14);
				 outtextxy(370,15,"<--- ROOT");
				 setcolor(4);
				 settextstyle(4,0,3);
				 outtextxy(200,430,"Fig :-  BINARY TREE ");
				 setcolor(getmaxcolor());
				 getch();
				 closegraph();
			   } break;
			case 3:
			    printf("\n THE LEAF NODES ARE");
			    tree(root);
			    display(root,1,getmaxx()+1,15,1);
			    printf("\n THE HEIGHT IS %d ",k);
			    break;
		case 4:
		exit(0);
}	}	}
示例#17
0
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy, i;

   /* initialize graphics, local variables*/
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error
       occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with error code */
   }

   midx = getmaxx() / 2;
   midy = getmaxy() / 2;

   /* loop through the fill patterns */
   for (i=EMPTY_FILL; i<USER_FILL; i++)
   {
      /* set the fill style */
      setfillstyle(i, getmaxcolor());

      /* draw the 3-d bar */
      bar3d(50, 50, 350,90, 10, 1);

      getch();
   }

   /* clean up */
   closegraph();
   return 0;
}
示例#18
0
void Initialize(void)
{
  int xasp, yasp;			/* Used to read the aspect ratio*/

  int driver = DETECT; 		/* Request auto-detection	*/
  int mode;
	initgraph( &driver, &mode,"e:\\tc\\bgi");
  ErrorCode = graphresult();		/* Read result of initialization*/
  if( ErrorCode != grOk ){		/* Error occured during init	*/
	printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
	exit( 1 );
  }

	getpalette( &palette );		/* Read the palette from board	*/
  MaxColors = getmaxcolor() + 1;	/* Read maximum number of colors*/

  MaxXX = getmaxx();
  MaxYY = getmaxy();			/* Read size of screen		*/

  getaspectratio( &xasp, &yasp );	/* read the hardware aspect	*/
  AspectRatio = (double)xasp / (double)yasp; /* Get correction factor	*/

}
示例#19
0
/*this function pops/displays values from stack and moves value  untill doesn't get posiotion to Inside value's box */
void pop() 
{ 
   int a=120, b ; 
   //Update row , from where next value is to be poped 
   y = y + 40   ; 
   b = y        ; 
   moveto(120,y); 
   /*-------------------------------------------------------------*/
   /* This loop displayes the arrows towards the stack's box from where , value is to be poped */
   for(int j=0 ;j<6 ; j++) 
    { 
     outtext("®"); 
     delay(100); 
     setfillstyle(0, getmaxcolor()); 
     bar(getx()-3 ,gety() ,getx() ,gety()+8); 
     delay(100); 
    } 
   /*-------------------------------------------------------------*/
   // Remove last displayed arrow 
   delay(100); 
   setfillstyle(0, getmaxcolor()); 
   bar(getx()-48 ,gety() ,getx() ,gety()+8); 
   delay(200); 
   moveto(60,gety()); 
   setfillstyle(0, getmaxcolor()); 
   bar(getx()-10 ,gety()-3 ,getx()+20 ,gety()+8); 
   /*-------------------------------------------------------------*/
   /*This loop will display the value untill poped value is not positioned in values box column  */ 
   delay(500); 
   while(getx()!=178) 
     { 
      setfillstyle(0, getmaxcolor()); 
      circle(a+6,b+3,12); 
      moveto(a,gety()); 
      itoa(arr[count-1],string,10); 
      outtext(string); 
      delay(10); 
      setfillstyle(0, getmaxcolor()); 
      bar(getx()-25 ,gety()-10 ,getx()+30 ,gety()+20); 
      a++; 
     } 
   /*-------------------------------------------------------------*/
   /*This loop will display the value untill poped value is not positioned in values box Row */ 
   delay(500); 
   while(gety()!=430) 
     { 
      setfillstyle(0, getmaxcolor()); 
      circle(a+21,b+3,7); 
      moveto(178,b); 
      itoa(arr[count-1],string,10); 
      outtext(string); 
      delay(10); 
      setfillstyle(0, getmaxcolor()); 
      bar(getx()-30 ,gety()-10 ,getx()+20 ,gety()+9); 
      b++; 
     } 
   /*-------------------------------------------------------------*/
   // These statements displyes poped values in vlaue box 
     delay(10); 
     moveto(178,447); 
     bar(170,446,208,455); 
     count--; 
     moveto(178,447); 
     itoa(arr[count],string,10); 
     outtext(string); 
     size++; 
   /*-------------------------------------------------------------*/ 
} 
示例#20
0
/******************************************************************************
* Interpret the command line and scan the given GIF file.		      *
******************************************************************************/
void main(int argc, char **argv)
{
    int	i, j, k, Error, NumFiles, Size, Row, Col, Width, Height, ExtCode,
	Count, ColorMapSize, GraphDriver, GraphMode, Sum,
	HelpFlag = FALSE,
	BGIPathFlag = FALSE,
	BGIUserDriverFlag = FALSE,
	ZoomFlag = FALSE;
    GifRecordType RecordType;
    GifByteType *Extension;
    char Str[80], *BGIUserDriverNameMode,
	**FileName = NULL;
    GifRowType *ScreenBuffer;
    GifFileType *GifFile;
    struct text_info TextInfo;      /* So we can restore starting text mode. */

    if ((Error = GAGetArgs(argc, argv, CtrlStr,
		&GifQuitePrint, &BGIPathFlag, &BGIPath,
		&BGIUserDriverFlag, &BGIUserDriverNameMode,
		&ZoomFlag, &ZoomFactor,
		&BeepsDisabled, &HelpFlag,
		&NumFiles, &FileName)) != FALSE ||
		(NumFiles > 1 && !HelpFlag)) {
	if (Error)
	    GAPrintErrMsg(Error);
	else if (NumFiles > 1)
	    GIF_MESSAGE("Error in command line parsing - one GIF file please.");
	GAPrintHowTo(CtrlStr);
	exit(1);
    }

    if (HelpFlag) {
	fprintf(stderr, VersionStr);
	GAPrintHowTo(CtrlStr);
	exit(0);
    }

    if (BGIUserDriverFlag) {
	/* Use the driver supplied by the user! */
        BGIInstallUserDriver(BGIUserDriverNameMode);
        installuserdriver(BGIUserDriverName, detectVGA);
	GraphDriver = BGI_USER_INSTALL;
    }
    else {
        /* Sense type of display we have and attempt to load right driver. */
        detectgraph(&GraphDriver, &GraphMode);
        if (GraphDriver < 0)
	    GIF_EXIT("BGI Auto detect: No graphics device detected.");
    }

    /* Put in the following any graphic driver specific setup: */
    switch (GraphDriver) {
	case CGA:
	    GraphMode = CGAHI;
	    break;
	case EGA:
	    GraphMode = EGAHI;
	    break;
	case EGA64:
	    GraphMode = EGA64HI;
	    break;
	case EGAMONO:
	    GraphMode = EGAMONOHI;
	    break;
	case HERCMONO:
	    GraphMode = HERCMONOHI;
	    break;
	case VGA:
	    GraphMode = VGAHI;
	    break;
	case BGI_USER_INSTALL:
	    GraphDriver = DETECT;
	    GraphMode = BGIUserDriverMode;
	    break;
	default:
	    GIF_EXIT("Requested graphic device is not supported.");
	    break;
    }

    if (NumFiles == 1) {
	GifFileName = *FileName;
	if ((GifFile = DGifOpenFileName(*FileName)) == NULL) {
	    PrintGifError();
	    exit(-1);
	}
    }
    else {
	/* Use the stdin instead: */
	GifFileName = "Stdin";
	setmode(0, O_BINARY);
	if ((GifFile = DGifOpenFileHandle(0)) == NULL) {
	    PrintGifError();
	    exit(-1);
	}
    }

    /* Allocate the screen as vector of column of rows. We cannt allocate    */
    /* the all screen at once, as this broken minded CPU can allocate up to  */
    /* 64k at a time and our image can be bigger than that:		     */
    /* Note this screen is device independent - its the screen as defined by */
    /* the GIF file parameters itself.					     */
    if ((ScreenBuffer = (GifRowType *)
	malloc(GifFile -> SHeight * sizeof(GifRowType *))) == NULL)
	    GIF_EXIT("Failed to allocate memory required, aborted.");

    Size = GifFile -> SWidth * sizeof(GifPixelType);/* Size in bytes of one row.*/
    if ((ScreenBuffer[0] = (GifRowType) malloc(Size)) == NULL)    /* First row. */
	GIF_EXIT("Failed to allocate memory required, aborted.");

    for (i = 0; i < GifFile -> SWidth; i++)  /* Set its color to BackGround. */
	ScreenBuffer[0][i] = GifFile -> SBackGroundColor;
    MaximumScreenHeight = GifFile -> SHeight - 1;
    for (i = 1; i < GifFile -> SHeight; i++) {
	/* Allocate the other rows, and set their color to background too: */
	if ((ScreenBuffer[i] = (GifRowType) malloc(Size)) == NULL) {
	    if (i > 30) {
		/* Free some memory for the BGI driver and auxilary. */
		for (j = 1; j < 28; j++)
	    	    free((char *) ScreenBuffer[i - j]);
	    	MaximumScreenHeight = i - 28;
	    	fprintf(stderr, "\n%s: Failed to allocate all memory required, last line %d.\n",
			PROGRAM_NAME, MaximumScreenHeight);
	    	break;
	    }
	    else
		GIF_EXIT("Failed to allocate memory required, aborted.");
	}

	memcpy(ScreenBuffer[i], ScreenBuffer[0], Size);
    }

    /* Scan the content of the GIF file and load the image(s) in: */
    do {
	if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR) {
	    PrintGifError();
	    break;
	}
	switch (RecordType) {
	    case IMAGE_DESC_RECORD_TYPE:
		if (DGifGetImageDesc(GifFile) == GIF_ERROR) {
		    PrintGifError();
		    exit(-1);
		}

		Row = GifFile -> ITop; /* Image Position relative to Screen. */
		Col = GifFile -> ILeft;
		Width = GifFile -> IWidth;
		Height = GifFile -> IHeight;
		GifQprintf("\n%s: Image %d at (%d, %d) [%dx%d]:     ",
		    PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height);
		if (GifFile -> ILeft + GifFile -> IWidth > GifFile -> SWidth ||
		   GifFile -> ITop + GifFile -> IHeight > GifFile -> SHeight) {
		    fprintf(stderr, "Image %d is not confined to screen dimension, aborted.\n");
		    exit(-2);
		}
		if (GifFile -> IInterlace) {
		    /* Need to perform 4 passes on the images: */
		    for (Count = i = 0; i < 4; i++)
			for (j = Row + InterlacedOffset[i]; j < Row + Height;
						 j += InterlacedJumps[i]) {
			    GifQprintf("\b\b\b\b%-4d", Count++);
			    if (DGifGetLine(GifFile,
				&ScreenBuffer[MIN(j, MaximumScreenHeight)][Col],
				Width) == GIF_ERROR) {
				PrintGifError();
				exit(-1);
			    }
			}
		}
		else {
		    for (i = 0; i < Height; i++, Row++) {
			GifQprintf("\b\b\b\b%-4d", i);
			if (DGifGetLine(GifFile, &ScreenBuffer[MIN(Row, MaximumScreenHeight)][Col],
				Width) == GIF_ERROR) {
			    PrintGifError();
			    MaximumScreenHeight = MIN(i - 1, MaximumScreenHeight);
			}
		    }
		}
		break;
	    case EXTENSION_RECORD_TYPE:
		/* Skip any extension blocks in file: */
		if (DGifGetExtension(GifFile, &ExtCode, &Extension) == GIF_ERROR) {
		    PrintGifError();
		    exit(-1);
		}
		while (Extension != NULL) {
		    if (DGifGetExtensionNext(GifFile, &Extension) == GIF_ERROR) {
			PrintGifError();
			exit(-1);
		    }
		}
		break;
	    case TERMINATE_RECORD_TYPE:
		break;
	    default:		    /* Should be traps by DGifGetRecordType. */
		break;
	}
    }
    while (RecordType != TERMINATE_RECORD_TYPE);

    /* Lets display it - set the global variables required and do it: */
    BackGround = GifFile -> SBackGroundColor;
    ColorMap = (GifFile -> IColorMap ? GifFile -> IColorMap :
				       GifFile -> SColorMap);
    ColorMapSize = 1 << (GifFile -> IColorMap ? GifFile -> IBitsPerPixel :
						GifFile -> SBitsPerPixel);

    gettextinfo(&TextInfo);	     /* Save current mode so we can recover. */

    initgraph(&GraphDriver, &GraphMode, BGIPath);
    if (graphresult() != grOk)	 	       /* Error occured during init. */
	GIF_EXIT("Graphics System Error, failed to initialize driver.");

    if (getmaxcolor() + 1 < ColorMapSize) {
	sprintf(Str, "GIF Image color map (%d) is too big for device (%d).\n",
					      ColorMapSize, getmaxcolor() + 1);
	closegraph();
	GIF_EXIT(Str);
    }

    /* Initialize hardware pallete and also select fore/background color.    */
    BackGround = ForeGround = 1;
    Sum = ((int) ColorMap[1].Red) +
	  ((int) ColorMap[1].Green) +
	  ((int) ColorMap[1].Blue);
    j = k = Sum;
    for (i = 0; i < ColorMapSize; i++) {
	setrgbpalette(i, ColorMap[i].Red >> 2,
			 ColorMap[i].Green >> 2,
			 ColorMap[i].Blue >> 2);

	Sum = ((int) ColorMap[i].Red) +
	      ((int) ColorMap[i].Green) +
	      ((int) ColorMap[i].Blue);
	if (i != 0 && Sum > j) {			/* Dont use color 0. */
	    ForeGround = i;
	    j = Sum;
	}
	if (i != 0 && Sum <= k) {			/* Dont use color 0. */
	    BackGround = i;
	    k = Sum;
	}
    }

    DeviceMaxX = getmaxx();		    /* Read size of physical screen. */
    DeviceMaxY = getmaxy();
    ScreenWidth = GifFile -> SWidth;
    ScreenHeight = MIN(GifFile -> SHeight, MaximumScreenHeight);

    Tone(500, 10);
    DisplayScreen(ScreenBuffer, GifFile);

    if (DGifCloseFile(GifFile) == GIF_ERROR) {
	PrintGifError();
	closegraph();
	exit(-1);
    }

    closegraph();

    textmode(TextInfo.currmode);
}
void cover(char *vertices,int no,int *x)
{ int midx,midy,maxx,maxy,maxcol;
int deg1[20],m=1,i,t,j,k;
char vset[20],eset[200];
char *pvset=vset;
char *peset=eset;

 for(i=0;i<20;i++)
 {
  vset[i]='0';
  deg1[i]=0;
 }
 for(i=0;i<200;i++)
 {
 eset[i]='0';
 }
 vset[0]=vertices[0];
 for(i=0,t=0;t<no;t++)
 {
  for(j=0;j<no;j++)
  {
   if(*(x+i*20+j)==1)
   {
    deg1[i]++;
    deg1[j]++;
    if(deg1[j]==2)
     {
     *(x+i*20+j)=-1;
     *(x+j*20+i)=-1;
     deg1[i]--;
     deg1[j]--;
     continue;
     }
     *(x+i*20+j)=-1;
     *(x+j*20+i)=-1;

     pvset++;
     *(pvset)=vertices[j];
     *(peset)=vertices[i];
     peset++;
     *peset='-';
     peset++;
     *peset=vertices[j];
     peset++;
     *peset=',';
     peset++;

   }
  }
   for(j=0;j<no;j++)
   {
    if(vset[m]==vertices[j])
    {
     m++;
     i=j;
     break;
    }
   }

 }
 peset--;
 *peset='0';


midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 maxx = getmaxx();
 maxy = getmaxy();
 maxcol= getmaxcolor();

setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;


settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 4);

outtextxy(325,130,"COVERING");
settextstyle(2, HORIZ_DIR, 5);
	  outtextxy(330,170,"(It represnt the set of edges that are ");
	  outtextxy(330,185,"covering every vertex in G");

gotoxy(30,15);
 for(k=0;eset[k]!='0';k++)
  printf("%c ",eset[k]);
 for(i=0;i<no;i++)
 {
 for(j=0;j<no;j++)
  {
   if((*(x+i*20+j))==-1)
    {
    (*(x+i*20+j))=1;
    (*(x+j*20+i))=1;
   }
   }
   }

 }
void main()
{

 int gdriver = DETECT, gmode, errorcode;
 char stylestr[40];
  int adja[20][20],diff[20],t=0;
 int i=0,j,row,col,counter=0,no=0;
 int count1=0,count2=0,f=0,r=0,z=0;
 int u=0,h=0;
 char vertices[20],ch;
 char edges[200],gr;
 /* p is a pointer used to access every element of edges array */
 char *p;
 int k=0;
 int deg[20],arr[20][20];
 int midx,midy,maxx,maxy,maxcol;

 /* initialize graphics and local variables */
 initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  /* read result of initialization */
 errorcode = graphresult();

 if (errorcode != grOk)  /* an error occurred */
  {
   printf("Graphics error: %s\n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
   exit(1); /* terminate with an error code */
  }



/* edges array takes a set of edges as input,
   adja is used for adjacency matrix, counter contains the no. of edges in
   the graph, vertices array consists of the vertices in the graph */




 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 maxx = getmaxx();
 maxy = getmaxy();
 maxcol= getmaxcolor();

clrscr();
 /*vertices array initialised to character '0' so that it doesn't contain
   any garbage value */

for(i=0;i<20;i++)
{
 vertices[i]='0';
}

/* adja array is initialised to 0
   so that it doesn't contain any garbage value */

for(i=0;i<20;i++)
{
 for(j=0;j<20;j++)
 {
  adja[i][j]=0;
 }
}
for(i=0;i<20;i++)
{
 diff[i]=0;

}

intro();

 getch();
 clrscr();

setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 3);

 outtextxy(250,100,"Enter the set of edges....");
 settextstyle(2, HORIZ_DIR, 5);
 outtextxy(330,125,"(as in following manner..{a-b,b-c,c-d,d-a,a-c})");
 outtextxy(330,137,"(please ensure the small letters, comma,");
 outtextxy(330,149,"bar between letters and curly braces.)");
 gotoxy(15,13);
 gets(edges);
 settextstyle(1, HORIZ_DIR, 1);
 outtextxy(230,242,"Is it a directed graph?") ;
 gotoxy(50,16) ;
 scanf("%c",&gr);

 getch();
 clrscr();

p=&edges[1];
i=0;
j=0;



 /*entering vertices in vertices array after scanning the set of edges
  and simultaniously making adjacency matrix */

while(1)
 {
  if(('a'<=(*p))&&((*p)<='z'))
  {
   while(vertices[i]!='0')
   {
    i++;
   }
   vertices[i]=*p;
   row=i;
   for(j=0;j<i;j++)
   {
    if(vertices[j]==vertices[i])
    {
     vertices[i]='0';
     row=j;
     break;
    }
   }

   i=0;
   p=p+2;
   while(vertices[i]!='0')
   {
    i++;
   }
   vertices[i]=*p;
   col=i;
   for(j=0;j<i;j++)
   {
    if(vertices[j]==vertices[i])
    {
     vertices[i]='0';
     col=j;
     break;
    }
   }
  if(gr=='y')
  adja[row][col]=1;

  if(gr=='n')
  {
   adja[row][col]=1;
   adja[col][row]=1;
   }
  counter=counter+1;

  }
  p=p+1;
  if(*p==',')
  {

   p=p+1;

   continue;
  }
  if(*p=='}')
  break;
 }
 /* finished the task of making adjacency matrix and vertices array */
for(i=0;i<20;i++)
{
 if(vertices[i]!='0')
  {
   no=no+1;
  }
 }
 setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;

 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 2);
 outtextxy(330,129,"Your graph has   vertices and   edges.");
 settextstyle(2, HORIZ_DIR, 5);
 outtextxy(330,179,"Do you wish to continue to have a look of adjancy matrix?");
 gotoxy(38,9);
 printf("%d",no);
 gotoxy(57,9);
 printf("%d",counter);


 getch();
 clrscr();

 setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-15,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+25,7*midy/4-15)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+20,7*midy/4-20)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+25,7*midy/4-15)  ;

 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 3);
 outtextxy(330,110,"THE ADJACENCY MATRIX ");

gotoxy(24,15);
for(i=0;i<no;i++)
  {
  u=u+3;
  gotoxy(24,10+u);
  printf("%c",vertices[i]);
  }
  for(i=0;i<no;i++)
  {
  h=h+5 ;
  gotoxy(24+h,10);
  printf("%c",vertices[i]);
  }
  u=0;

for(i=0;i<no;i++)
{
  h=0;
  u=u+3;
  gotoxy(29,5+u);
  for(j=0;j<no;j++)
  {

   gotoxy(29+h,10+u);
   printf("%d",adja[i][j]);
   h=h+5;
  }
 }
 getch();
 clrscr();

 /* checking whether the graph is directed or not */
 if(gr=='y')
 {

  /* calculating the outgoing degree of every vertex in count1
    and incoming degree of every vertex in count2*/

   for(i=0;i<no;i++)
  {
   count1=0;
   count2=0;
   for(j=0;j<no;j++)
   {
    if(adja[i][j]==1)
     {

     count1=count1+1;
     }

   }
   for(j=0;j<no;j++)
   {
    if(adja[j][i]==1)
     count2=count2+1;
   }

     /* diff[] array consists of the difference of the incoming and
      outgoing degree of every vertex */

    diff[i]=count1-count2;

  }
  /* if the diff. of incoming  and outgoing degree of every vertex is 0
     euler circuit exists */
  for(i=0;i<no;i++)
  {
   if(diff[i]==0)
    {
     /* f is used for calculating the no. of vertices with 0
    difference in outgoing and incoming degree*/

     f=f+1;

    }
   }
   for(i=0;i<no;i++)
   {

    /* difference is 1 and -1 for 2 vertices and all the diff. are 0
     euler path exists */

   if(diff[i]==1)
   {
    r=r+1;
    k=i;

   }
   if(diff[i]==-1)
   {
   z=z+1;
   }
   }
  setfillstyle(10, maxcol);
    /* fill the screen with the pattern */
    bar(0, 0,maxx, midy/4-5);
    bar(0, 0,midx/4-15, maxy);
    bar(0, 7*midy/4-25,maxx, maxy);
    bar(7*midx/4+15, 0,maxx, maxy);
    setfillstyle(0, maxcol);
    bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
    rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
    rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;

    settextjustify(CENTER_TEXT, CENTER_TEXT);
    settextstyle(1, HORIZ_DIR, 2);
    outtextxy(330,129,"and the degree of vertices are...");

  u=0;
  for(i=0;i<no;i++)
  {
  u=u+2;
  gotoxy(30,10+u);
  printf("%c",vertices[i]);

  gotoxy(45,10+u);
  printf("%d",diff[i]);

  }
 getch();
 clrscr();


  setfillstyle(10, maxcol);
  /* fill the screen with the pattern */
  bar(0, 0,maxx, midy/4-5);
  bar(0, 0,midx/4-15, maxy);
  bar(0, 7*midy/4-25,maxx, maxy);
  bar(7*midx/4+15, 0,maxx, maxy);
  setfillstyle(0, maxcol);
  bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
  rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
  rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
  settextjustify(CENTER_TEXT, CENTER_TEXT);
  settextstyle(1, HORIZ_DIR, 2);


 if(f==no)
 {
  outtextxy(330,170,"EULER CIRCUIT EXISTS!!!");

 /* t is an indicator showing whether a euler circuit or path
   exists or not */
 t=1;
 }
 if((r==1)&&(f==(no-2))&&(z==1))
 {
  outtextxy(330,170,"EULER PATH EXISTS!!!");
 t=1;
 }
 if(t==0)
 {
  outtextxy(330,200,"NEITHER EULER CIRCUIT NOR EULER PATH EXISTS");
 }


 if(t==1)
 {
  /* function for finding the euler path or circuit if exists */

  euler_path(&adja[0][0],counter,no,k,vertices,gr);
  }
 }
r=0;
f=0;

 /* finding euler path or circuit for undirected graph */

if(gr=='n')
{
 for(i=0;i<no;i++)
 {

  count1=0;
  for(j=0;j<no;j++)
  {
   if(adja[j][i]==1)
   {
    count1=count1+1;
   }
  }
   deg[i]=count1;
  if((count1%2)==0)
  {
  f=f+1;
  }
  else
  {
   r=r+1;

  }
 }
setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;

 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 2);

 if(f==no)
  {
  t=1;
      outtextxy(330,170,"EULER CIRCUIT EXISTS!!!");
  }
 if((r==2)&&(f==(no-2)))
 {
 t=1;
  outtextxy(330,170,"EULER PATH EXISTS!!");
 }
 if(t==0)
 {
  outtextxy(330,200,"NEITHER EULER CIRCUIT NOR EULER PATH EXISTS");
 }
 if(t==1)
 {
 euler_path(&adja[0][0],counter,no,k,vertices,gr);
 }

}
getch();
setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;

 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 2);

/*finding whether hamiltonian path exists or not*/
if(gr=='n')
{
 for(i=0;i<=no-1;i++)
 {
  for(j=i+1;j<=no-1;j++)
  {
   if((deg[i]+deg[j])>=no-1)
     continue;
   else
   {

     outtextxy(330,170,"HAMILTONIAN PATH MAY OR MAY NOT EXIST");
	settextstyle(2, HORIZ_DIR, 5);
	outtextxy(330,230,"(Since finding the hamiltonian path is a ");
	outtextxy(330,245,"incomplete problemso it would be appropriate");
	outtextxy(330,260,"to say the above statment.)") ;
       //	 getch();
	// clrscr();
	 goto pos;
   }
  }
 }
 if(i==no)
 {

   outtextxy(330,170,"HAMILTONIAN PATH EXISTS!!!");
  hamilton_path(&adja[0][0],no,vertices);

 }
  /* to check whether hamiltonian circuit exists or not*/
  for(i=0;i<20;i++)
  {
   for(j=0;j<20;j++)
   {
     arr[i][j]=100;
   }
  }
  for(i=0;i<no;i++)
  {
   int k=0;
   for(j=0;j<no;j++)
   {
    if((adja[i][j]!=0)||(i==j))
      continue;
    else
    {
      arr[i][k]=j;
      //printf("%d\t",arr[i][k]);
      k++;
    }
   }
 }
 for(i=0;i<no;i++)
 {
   for(k=0;arr[i][k]!=100;k++)
   {
     if((deg[i]+deg[arr[i][k]])>=no)
       continue;
     else
     {

      outtextxy(330,170,"HAMILTONIAN PATH MAY OR MAY NOT EXIST");
	  settextstyle(2, HORIZ_DIR, 5);
	  outtextxy(330,230,"(Since finding the hamiltonian path is a ");
	  outtextxy(330,245,"incomplete problemso it would be appropriate");
	  outtextxy(330,260,"to say the above statment.)") ;


       goto pos;
     }
   }
 }
 if(i==no)
 {


     outtextxy(330,170,"HAMILTONIAN PATH EXISTS!!!");

 }
   pos:


}

getch();
clrscr();
matching(vertices,no,&adja[0][0]);
getch();
clrscr();
color(vertices,no,&adja[0][0]);
getch();
clrscr();
cover(vertices,no,&adja[0][0]);


getch();
}


void matching(char *vertices, int no,int *x)
{
int i,h=0,j,k,n,v,w=0,arr1[20];
int midx,midy,maxx,maxy,maxcol;
midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 maxx = getmaxx();
 maxy = getmaxy();
 maxcol= getmaxcolor();

for(i=0;i<no;i++)
{
arr1[i]=-1;
}

setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;


settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 4);

outtextxy(330,130,"MATCHING");

settextstyle(2, HORIZ_DIR, 5);
	  outtextxy(330,170,"(It represnt the subset of edges that are ");
	  outtextxy(330,185,"not adjacent to each other");

for(i=0;i<no;i++)
 {
  n=0;
  for(k=0;k<no;k++)
  {
  if(i==arr1[k])
  {
  n=1;
  break;

   }
  }
  if(n==1)
  continue;

  for(j=0;j<no;j++)
  {
   v=0;
  for(k=0;k<no;k++)
  {
  if(j==arr1[k])
  {
  v=1;
  break;
  }
  }
   if(v==1)
   continue;

   if((*(x+i*20+j))==1)
   {

   arr1[w]=i;
   w++;
   arr1[w]=j;
   w++;
   gotoxy(25,15+h);
   printf("%c   -   %c :",vertices[i],vertices[j]);
   h=h+2;
  *(x+i*20+j)= -1;
  *(x+j*20+i)= -1;

   break;
   }
  }

  }
 for(i=0;i<no;i++)
 {
 for(j=0;j<no;j++)
  {
   if((*(x+i*20+j))==-1)
    {
    (*(x+i*20+j))=1;
    (*(x+j*20+i))=1;
   }
   }
   }
}
void color(char *vertices,int no,int *x)
{int a=0,midx,midy,maxx,maxy,maxcol;
int i,s,k,j,t,l=10;
char *paint[20];
char *color[]={"red","green","blue","magenta","pink","cyan","yellow","black","white","orange"};
int total=1;
for(i=0;i<20;i++)
   paint[i]=0;

 paint[0]=color[0];
 for(i=0,s=1;i<no-1;i++)
 {
   for(k=0;k<=i;k++)
   {
    if(*(x+k*20+i+1)==1)
     continue;
    else
     {
     paint[i+1]=paint[k];
     for(t=0;t<=i;)
     {
      if(*(x+(i+1)*20+t)==1)
       {
	l=strcmp(paint[t],paint[i+1]);
	if(l==0)
	{
	paint[i+1]=0;
	break;
	}
	else
	{
	 t++;
	}
       }
      else
      {
       t++;
      }
     }//3rd for loop
     }//else
     if(paint[i+1]!=0)
       break;
   } // 2nd for loop

   if(k==(i+1)&&(paint[i+1]==0))
   {
     paint[i+1]=color[s];
     s++;
   }

   l=10;
 }

midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 maxx = getmaxx();
 maxy = getmaxy();
 maxcol= getmaxcolor();

setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0,maxx, midy/4-5);
 bar(0, 0,midx/4-15, maxy);
 bar(0, 7*midy/4-25,maxx, maxy);
 bar(7*midx/4+15, 0,maxx, maxy);
 setfillstyle(0, maxcol);
 bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;


settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(1, HORIZ_DIR, 4);

outtextxy(325,130,"COLOURING");

settextstyle(2, HORIZ_DIR, 5);

 for(i=0;i<no;i++)
 {
  gotoxy(20,12+a);
  printf("Color of vertex %c is %s",vertices[i],paint[i]);
  a+=1;
 }

 for(i=1;i<no;i++)
 {
  for(j=0;j<=i-1;)
  {
   if(paint[i]==paint[j])
    break;
   else
    j++;
  }
  if(j==i)
   total++;
 }
 gotoxy(31,22);
 printf("GRAPH IS %d- CHROMATIC",total);

}
void intro()
{
 int midx,midy,maxx,maxy,maxcol;
 midx = getmaxx() / 2;
 midy = getmaxy() / 2;
 maxx = getmaxx();
 maxy = getmaxy();
 maxcol= getmaxcolor();
 /* select the fill style */
 setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0, maxx, maxy);
 rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;

 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3); ///6 IS SIZE
 setcolor(4);
 outtextxy(315,125,"WELCOME");
 outtextxy(310,170,"TO");
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
 outtextxy(324,250,"EULER's PATH FINDER");
 getch();//delay(1200);

 clrscr();
 setfillstyle(10, maxcol);
 /* fill the screen with the pattern */
 bar(0, 0, maxx, maxy);
 setcolor(15);
 rectangle(midx/4,midy/4,7*midx/4+10,7*midy/4-30)  ;
 rectangle(midx/4-5,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
 settextjustify(CENTER_TEXT, CENTER_TEXT);
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
 setcolor(4);
 outtextxy(330,200,"INTRODUCTION");
 settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
 outtextxy(325,250,"(If you don't want an introduction press Esc)");
 if((getch())=='z')
  return;
 else
  {
   setfillstyle(10, maxcol);
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(4, HORIZ_DIR, 4);
   setcolor(4);
   outtextxy(315,100,"INTRODUCTION");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(350,160,"LEONARD EULAR was a Swiss mathmatician.");
   outtextxy(330,185,"He is considered to be father of graph theory.");
   outtextxy(330,210,"He solved the very famous Koingsberg bridge ");
   outtextxy(330,235,"problem in 1736 in his very first paper of GT.");

   /* draw ellipse */
   line(240,260,480,260);
   ellipse(300, 300, 0, 360, 40, 15);
   ellipse(430,300,0,360,40,15);
   line(340,300,390,300);
   line(342,302,390,302);
   line(240,340,480,340);
   line(430,285,430,260);
   line(432,285,432,260);
   line(430,315,430,340);
   line(432,315,432,340);
   line(280,260,295,285);
   line(282,260,297,285);
   line(320,260,305,285);
   line(318,260,303,285);
   line(280,340,295,315);
   line(282,340,297,315);
   line(320,340,305,315);
   line(318,340,303,315);
   outtextxy(300,298,"A");
   outtextxy(430,298,"B");
   getch();//delay(2500);

   clrscr();
   setfillstyle(10, maxcol);
   /* fill the screen with the pattern */
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(4, HORIZ_DIR, 4);
   outtextxy(290,95,"WHAT IS EULAR GRAPH??");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(363,145,"In a graph G,if a closed walk contains ") ;
   outtextxy(310,170,"all the edges of the grapg G,the walk is ");
   outtextxy(280,195,"called a EULER LINE or EULER CYCLE.");
   outtextxy(340,225,"A graph G is called as EULER GRAPH if it");
   outtextxy(240,250,"contains a EULER LINE in G.");
   outtextxy(325,290,"An open walk in a graph is called an EULER");
   outtextxy(325,315,"PATH if it contains all the edges of graph G.");
   getch();//delay(2500);

   clrscr();
   setfillstyle(10, maxcol);
   /* fill the screen with the pattern */
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(4, HORIZ_DIR, 4);
   outtextxy(315,100,"SIR WILLIAM HAMILTON");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(370,145,"Sir Rowan Hamilton was a very famous  ");
   outtextxy(332,170,"Irish mathematician. He invented a game ");
   outtextxy(330,195,"consisting of a solid regular dodecahedron ");
   outtextxy(340,220,"in 1857 and the concept is used in solving ");
   outtextxy(317,245,"the famous travelling salesman problem");
   outtextxy(337,270,"where the salesman is to eake a tour of all");
   outtextxy(340,295,"cities going through edges such that no city");
   outtextxy(300,320,"appears more than one in the tour. ");
   getch();//delay(2500);

   clrscr();
   setfillstyle(10, maxcol);
   /* fill the screen with the pattern */
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(4, HORIZ_DIR, 3);
   outtextxy(290,95,"WHAT IS HAMILTONIAN GRAPH?");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(363,145,"In a graph G,a circuit that contains") ;
   outtextxy(310,170,"each vertex of G exactly once except the");
   outtextxy(325,195,"terminal vertices that appear twice is called");
   outtextxy(280,225,"as HAMILTONIAN CIRCUIT");
   outtextxy(320,250,"A graph G is called as HAMILTONIAN GRAPH");
   outtextxy(315,275,"if it contains a HAMILTONIAN CIRCUIT in G.");
   outtextxy(323,300,"If we delete one edge from the hamiltonian");
   outtextxy(327,325,"circuit,we get a path called HAMILTONIAN PATH");
   getch();//delay(2500);

   clrscr();
   setfillstyle(10, maxcol);
   /* fill the screen with the pattern */
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(4, HORIZ_DIR, 4);
   outtextxy(310,95,"LET US TAKE A EXAMPLE...");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(330,140,"Suppose you wish to know presence of EULER");
   outtextxy(330,165,"or HAMILTONIAN path in following set of edges.");
   outtextxy(325,205,"{ a-b, a-c, b-e, b-c, c-e, e-d, c-d }");
   outtextxy(190,250,"Let us consider the ");
   outtextxy(170,275,"edges undirected.");
   outtextxy(175,305,"Then graph is =>");
   line(370,350,450,350);  //  e-d
   line(370,290,450,290); //  b-c
   line(370,350,370,290);  //  b-e
   line(450,350,450,290); //   c-d
   line(370,350,450,290);//e-c
   line(410,250,370,290);  //   a-b
   line(410,250,450,290);  //    a-c
   settextstyle(2, HORIZ_DIR, 7);
   outtextxy(410,240,"a");
   outtextxy(365,350,"e");
   outtextxy(365,290,"b");
   outtextxy(455,290,"c");
   outtextxy(455,350,"d");
   getch();//delay(2500);

   clrscr();
   setfillstyle(10, maxcol);
   /* fill the screen with the pattern */
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(1, HORIZ_DIR, 3);
   outtextxy(310,95,"The graph has both EULER as well");
   outtextxy(310,125," as HAMILTONIAN path");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(310,155,"Let us see for Euler first.... ")  ;
   settextstyle(2, HORIZ_DIR, 7);
   outtextxy(300,205,"a");
   outtextxy(245,350,"e");
   outtextxy(245,260,"b");
   outtextxy(355,260,"c");
   outtextxy(355,350,"d");
   delay(500);
   line(250,260,350,260); //  b-c
   delay(500);
   line(300,210,350,260);  //    a-c
   delay(500);
   line(300,210,250,260);  //   a-b
   delay(500);
   line(250,350,250,260);  //  b-e
   delay(500);
   line(250,350,350,350);  //  e-d
   delay(500);
   line(350,350,350,260); //   c-d
   delay(500);
   line(250,350,350,260);//e-c
   delay(1000);

   clrscr();
   setfillstyle(10, maxcol);
   /* fill the screen with the pattern */
   bar(0, 0,maxx, midy/4-5);
   bar(0, 0,midx/4-15, maxy);
   bar(0, 7*midy/4-25,maxx, maxy);
   bar(7*midx/4+15, 0,maxx, maxy);
   setfillstyle(0, maxcol);
   bar(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   rectangle(midx/4-10,midy/4,7*midx/4+10,7*midy/4-30)  ;
   rectangle(midx/4-15,midy/4-5,7*midx/4+15,7*midy/4-25)  ;
   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(1, HORIZ_DIR, 3);
   outtextxy(310,95,"The graph has both EULER as well");
   outtextxy(310,125," as HAMILTONIAN path");
   settextstyle(1, HORIZ_DIR, 2);
   outtextxy(310,155,"Now for Hamiltonian path.... ")  ;
   settextstyle(2, HORIZ_DIR, 7);
   outtextxy(300,205,"a");
   outtextxy(245,350,"e");
   outtextxy(245,260,"b");
   outtextxy(355,260,"c");
   outtextxy(355,350,"d");
   delay(1000);
   line(300,210,250,260);  //   a-b
   delay(500);
   line(250,350,250,260);  //  b-e
   delay(500);
   line(250,350,350,350);  //  e-d
   delay(500);
   line(350,350,350,260); //   c-d
   delay(500);
  }
}
示例#25
0
main()
{
 int gdriver=DETECT,gmode;
 int i,j,k,l,x,x1,x2,y1,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8;
 initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
  x1=115; y1=150; x2=145; y2=110;
  x3=155; y3=150; x4=185; y4=110;
  x5=195; y5=150; x6=225;  y6=110;
  x7=235; y7=150; x8=265;  y8=110;

  j=1;
  i=1;

  while(!(kbhit()))
 {
 i=0;
 //conveyor belt
 circle(90,200,50);
 circle(300,200,50);
 line(80,150,300,150);
 line(80,250,300,250);
 //bins
  rectangle(x1,y1,x2,y2);
  rectangle(x3,y3,x4,y4);
  rectangle(x5,y5,x6,y6);
  rectangle(x7,y7,x8,y8);

  if(x7>=320){
  i=0;
  if(x8<=560 && y7<=300){

  rectangle(x7+i,y7++,x8+i,y8++);
  i=i+8;
  }}
  if(x5>=320){
  i=0;

  if(x6<=560 && y5<=300){
  rectangle(x5+i,y5++,x6+i,y6++);
  i=i+10;
  }}
  if(x3>=320){
  i=0;

   if(x4<=560 && y3<=300){
  rectangle(x3+i,y3++,x4+i,y4++);
  i=i+10;
  }}
   if(x1>=320){
  i=0;
   if(x2<=560 && y1<=300){
  rectangle(x1+i,y1++,x2+i,y2++);
  i=i+10;
  }}
//basket
 rectangle(350,300,560,250);

 setfillstyle(EMPTY_FILL, getmaxcolor());
 pieslice(90,200,45-x,135-x,50);
 pieslice(90,200,135-x,225-x,50);
 pieslice(90,200,225-x,315-x,50);
 pieslice(90,200,90-x,270-x,50);
 pieslice(90,200,0-x,180-x,50);
 pieslice(300,200,45-x,135-x,50);
 pieslice(300,200,135-x,225-x,50);
 pieslice(300,200,225-x,315-x,50);
 pieslice(300,200,90-x,270-x,50);
 pieslice(300,200,0-x,180-x,50);
 if(x1<=370 || x3<=370 || x5<=370 ||x7<=370){
 x++;
 x1++,x2++;x3++;x4++;x5++;x6++;x7++; x8++; }
 delay(80);
 cleardevice();

 }
 cleardevice();
 getch();
 closegraph();
 return 0;

}
示例#26
0
// this function pushes values in stack
void push() 
{ 
   int a=178 ,  b=425    ; 
   /*---------------------------------------------------------------*/
   //displays the value that is to be pushed in stack 
   moveto(178,447); 
   itoa(arr[count],string,10); 
   outtext(string); 
   /*--------------------------------------------------------------*/
   /*after a delay remove the value , and display the value in box that is to pushed next */ 
   delay(10); 
   bar(170,446,208,455); 
   itoa(arr[count+1],string,10); 
   moveto(178,447); 
   outtext(string); 
   /*--------------------------------------------------------------*/ 
   moveto(a,b); 
   /*this loop displays and moves the value untill top row position is not found */
   while(gety()!=y) 
     { 
      setfillstyle(0, getmaxcolor()); 
      circle(a+6,b+3,12); 
      itoa(arr[count],string,10); 
      outtext(string); 
      delay(10); 
      setfillstyle(0, getmaxcolor()); 
      bar(170 ,gety()-20 ,200 ,gety()+14); 
      moveto(a,b); 
      b--; 
     } 
   setfillstyle(0, getmaxcolor()); 
   circle(a+6,b+3,9); 
   outtext(string); 
   moveto(125,b); 
   /*--------------------------------------------------------------*/
   //This loop displays the animated arrow toward top box os stack
   for(int j   =0 ;j<6 ; j++) 
      { 
    outtext("®"); 
    delay(100); 
    setfillstyle(0, getmaxcolor()); 
    bar(getx()-3 ,gety() ,getx() ,gety()+8); 
    delay(100); 
      } 
   /*--------------------------------------------------------------*/
   delay(100); 
   //Remove last displayed value 
   setfillstyle(0, getmaxcolor()); 
   bar(getx()-48 ,gety() ,getx() ,gety()+8); 
   /*--------------------------------------------------------------*/
   delay(100);
   delay(200); 
   /*while required coloumn of top box is not found , Display and move value to required colimn */
   while(getx()!=x+60) 
     { 
      setfillstyle(0, getmaxcolor()); 
      circle(a+6,b+3,9); 
      itoa(arr[count],string,10); 
      outtext(string); 
      delay(10); 
      setfillstyle(0, getmaxcolor()); 
      bar(getx()-20 ,gety()-10 ,getx()+70 ,gety()+20); 
      moveto(a,b); 
      a--; 
     } 
   /*--------------------------------------------------------------*/
   delay(100); 
   //display the value in required box 
   moveto(60,gety()); 
   outtext(string); 
   count++; 
   // to have cursor position in top box of stack 
   y = y-40; 
} 
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "c:\\TurboC3\\BGI");

   /* read result of initialization */
   errorcode = graphresult();
   /* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }

   setcolor(getmaxcolor());
   xmax = getmaxx();
   ymax = getmaxy();
    int level=0,flag=0,t1=500,t2=300;
   int well[8]={350-85,250,350-85,400,350+85,400,350+85,250};
   while(!kbhit())
   {

     int bucketwater[8]={310,470-level,370,470-level,370,getmaxy(),310,getmaxy()};

   int bucket[10]={310,430,370,430,370,getmaxy(),310,getmaxy(),310,430};
   drawpoly(5,bucket);
    int y=0,x=0,y1=0,y2=0,s=0;
    while(level<50)
   {



   cleardevice();
   circle(500,200,30); //head
   line(500,230,500,400);  //body
   line(500,400,450,450); //left leg
   line(500,400,550,450);  //right leg

  /* int s=0;
   while(s<25)
   {
   line(500,250,450,220+s);
   line(500,250,450,210+s);
   setcolor(BLACK);
    line(500,250,450,220+s);
   line(500,250,450,210+s);
 setcolor(WHITE);
   s=s++;
   } */
   if(flag!=0)
    {
    setfillstyle(1,BLUE);
    fillpoly(4,bucketwater);
    }
   drawpoly(5,bucket);

   if(y2<70)
   {
 ellipse(340,220+y2,0,360,10,5);
   line(340,220,340,225);
   line(330,220+y2,330,245+y2);
   line(350,220+y2,350,245+y2);
   line(330,245+y2,350,245+y2);
   line(358,170,t1-x,t2-y);
    line(500,270,450,240);
   line(500,270,450,230);

   y2++;
  }

  if((y2<90)&&(y2>20))
  y2++;


  // line(350-85,250,350-85,400);   //walls
  // line(350+85,250,350+85,400);    //wall
  // arc(350,235,242,298,185);  //base

  setfillstyle(1,BROWN);
  fillpoly(4,well);
  setfillstyle(1,LIGHTGRAY);
  fillellipse(350,250,85,20); //top
   line(350-85,250,350-85,150);//structure
   line(350+85,250,350+85,150);//to hold
   line(350-85,150,350+85,150);//pulley
   if(x%2==0)
   {
   line(350,165,350,185);
   line(340,175,360,175);
   }
   else
   {
   line(350+5,165+2,350-5,185-2);
   line(350-5,165+2,350+5,185-2);
   }

   line(350,150,350,165);
   circle(350,175,10); //pulley
  if(y>90)
   {
   line(360-2,165+5,400+x,200+y);
  // t1=x;
  // t2=y;
    }
  //  int s=10;
   if((y>=50)&&(y<90))
   {
   ellipse(340,240-y1,0,360,10,5);
   line(340,175,340,240-y1);
   line(330,240-y1,330,265-y1);
   line(350,240-y1,350,265-y1);
   line(330,265-y1,350,265-y1);
    line(360-2,165+5,400+x,200+y);
   if(s<20)
   {
   line(500,270,450,240+s);
   line(500,270,450,230+s);
   s++;
   }
 //  line(450,250,400,220+s);
   //line(450,250,400,210+s);

    t1=400+x;
    t2=200+y;

  // floodfill(335,280,BLUE);
   y1++;
   }

   else if(y>=90)
   {
    int water[8]={330,270-y1,330,470-y1,350,470-y1,350,270-y1};

   {
   line(500,250,350,220);
   line(500,250,350,210);

   }
  ellipse(340,270-y1,0,360,10,10);
   line(340,175,340,270-y1-10);
  // line(330,270-y1,330,295-y1);
  // line(350,270-y1,350,295-y1);
  // line(330,295-y1,350,295-y1);
    setfillstyle(1,BLUE);
    fillpoly(4,water);
   // delay(15);
    fillpoly(4,bucketwater);
    level++;
    if(level%10==0)
    { flag=1;

     break;
    }


   }
   else
   {
   line(340,175,340,250);
   }
   y++;
   x++;
  // s+=3;


   delay(20);


   }
  int overflow[8]={370,430,370,getmaxy(),380,getmaxy(),380,430};
  setfillstyle(1,LIGHTBLUE);
  fillpoly(4,overflow);
   }
   /* clean up */
   getch();
   closegraph();
   return 0;
}
int main(void)
{
    /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   int stangle = 200, endangle =340 ;
   int radius = 50;

   /* initialize graphics and local
   variables */
   initgraph(&gdriver, &gmode, "c:\\TurboC3\\BGI");

   /* read result of initialization */
   errorcode = graphresult();
   /* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();

      exit(1);    /* terminate with an error code */
   }

   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor());
   midx=midx-250;
   int i=0;
   int j,a,b,lt;
   /* draw arc */
   while(i<=200)
   {
   j=0;
   while(j<=50)
   {
   cleardevice();
   arc(midx+i, midy, stangle, endangle, radius);
   line(22+i,255,117+i,255);
   line(0,285,getmaxx(),285);
   circle(40+i,210,10);
   circle(500,40,20);
   line(40+i,220,40+i,255);
   line(40+i,230,50+i,225+j);
   line(40+i,235,49+i,230+j);
   line(65+i,200,20+i,285+j);
   i++;
   j+=3;
   delay(20);
   }
   }
   while(i<=getmaxx())
   {
     j=0;
     while(j<=50)
     {
       cleardevice();
       arc(midx+i, midy, stangle, endangle, radius);
       line(22+i,255,117+i,255);
       line(0,285,getmaxx(),285);
       circle(40+i,210,10);
       setlinestyle(DASHED_LINE,1,1);
       for(int l=0;l<=200;l++)
       {
	a= random(getmaxx());
	b= random(285);
	lt= 15;
       line(a,b,a-lt,b+lt);
       }
       arc(50+i,210,0,180,50);
       setlinestyle(SOLID_LINE,1,1);
       line(40+i,220,40+i,255);
       line(40+i,230,50+i,225+j);
       line(40+i,235,49+i,230+j);
       line(65+i,200,20+i,285+j);
       i++;
       j+=3;
   delay(70);
   }
  }
   /* clean up */
   getch();
   closegraph();
   return 0;
}
示例#29
0
void stack() 
{ 
  cleardevice(); 
  /*-------------------------------------------------------------*/ 
    outtextxy(400,465,"Babar saeed"); 
    outtextxy(500,465,"32"); 
    outtextxy(545,465,"QAU, ISB"); 
  /*-------------------------------------------------------------*/
  //Displays stacks Menu 
  moveto(400,60); 
  outtext("STACK'S OPERATIONS"); 
  moveto(400,80); 
  outtext("PUSH           [p]"); 
  moveto(400,100); 
  outtext("POP            [o]"); 
  moveto(400,120); 
  outtext("EXIT           [x]"); 
  //End of stack Menu
  /*-----------------------------------------------------------------*/
  /*-----------------------------------------------------------------*/
  // displays value of top in start of program 
  moveto(300,425); 
  outtext("Top"); 
  itoa(top,string,10); 
  outtextxy(308,450,string); 
  /*-----------------------------------------------------------------*/
  //Dislplays stack figure 
  setbkcolor(0); 
  setcolor(14); 
  outtextxy(55,26,"STACK"); 
  line(30,40,30,440); 
  int r=40; 
  for(int i = 1 ;i<12 ;i++) 
   { 
     line(30,r,110,r); 
     r+=40; 
   } 
  line(110,40,110,440); 
  r = 55; 
  // This loop Displays stack's boxes Number
  for( i = 10 ;i>=1 ;i--) 
   { 
     moveto(10,r); 
     itoa(i,string,10); 
     outtext(string)  ; 
     r+=40; 
   } 
   //These four statements makes a box 
   line(165,440,210,440); 
   line(165,440,165,460); 
   line(210,440,210,460); 
   line(165,460,210,460); 
   setfillstyle(0, getmaxcolor()); 
   // This do while loop , reads coorect option (push, pop, Exit) 
   // And Makes calls to push, pop functions
   char ch[2]; 
   do 
    { 
     moveto(400,140); 
     outtext("ENTER OPTION   "); 
     ch[0]=getche(); 
     //convert entered option in lower character 
     ch[0] = tolower(ch[0]); 
     if(ch[0]=='p') 
    {  // start of outer if
	// displays p 
       outtext("p"); 
       // make a delay 
       delay(500); 
       // draw a bar to remove p 
       bar(getx()-30,gety(),getx()+2,gety()+20); 
       /*--------------------------------------------------------*/
	   // if size of stack's remaining boxese less than one
	   // than stack is overflow
	   if(size<1) 
        { //start of nested if
		for(int i = 0 ;i<4 ; i++){ 
          moveto(420,170); 
          outtext("Stack Overflow "); 
          delay(1000); 
          setfillstyle(0, getmaxcolor()); 
          bar(420 ,165 ,630 ,180); 
          delay(500);} 
         }//end of nested if
		 /*--------------------------------------------------------*/
		 // if there are stack's boxes remains(if size>1)
		 else 
         { 
          //start of nested else part
		  // decrease stack remaining boxes 
          size--; 
          // increase top position , where last item is Inserted 
          top++; 
          // call to push function 
          push(); 
          // bar removes last displayes value 
          bar(290,440,350,479); 
          // convert integer value to assci value
		  /* becuse outtext/outtextxy function require string as third argument */ 
          itoa(top,string,10); 
          outtextxy(308,447,string); 
          }//End of Nested else Part 
    }//end  of Nested if 
	else if(ch[0]=='o') 
    {  // start of outer if's elseif part
	// Displays o , and remove it after a delay 
       outtext("o"); 
       delay(500); 
       bar(getx()-30,gety(),getx()+10,gety()+20); 
       /*--------------------------------------------------------*/
	   /* if all boxes of stack are empty than display message of overflow */
	   if(size==10) 
         { 
          for(int i = 0 ;i<4 ; i++){ 
          moveto(410,170); 
          outtext("Stack, Underflow "); 
          delay(1000); 
          setfillstyle(0, getmaxcolor()); 
          bar(330 ,165 ,630 ,180);   // (left, top)     ³ upper left corner 
          delay(500);  }                //        (right, bottom) ³ lower right corner*/ 
         } 
       /*--------------------------------------------------------*/
	   /*if there are some boxes of stack filled than call pop function */
	   else 
          { 
          // update top's value 
          top--; 
          pop(); 
          //display value of updated top 
          bar(290,440,350,479); 
          itoa(top,string,10); 
          outtextxy(308,447,string);} 
          } 
         /*------------------------------------------------------*/ 
}while(ch[0]!='x'); 
} 
示例#30
0
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;
   int xs[]={200,100,250,350,300,270};
   int ys[]={400,200,50,170,350,280};
   int n=sizeof(xs)/sizeof(*xs);
   int i=0,j=0;
   float inverse_m[6];
   struct point *points[6];
   struct point *sortedy[6];
   struct point *sortedx[6];
   struct edge *edges[6];
   float p=0;

   for(i=0;i<n;i++)
   {
    points[i]=(struct point *)malloc(sizeof(struct point));
    points[i]->x=xs[i];
    points[i]->y=ys[i];
   }

   initgraph(&gdriver, &gmode, "C:\\Turboc3\\BGI");

   errorcode = graphresult();

   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }

   setcolor(getmaxcolor());

   for(i=0;i<n;i++)
   {
    if(i==(n-1))
    {
     line(xs[i],ys[i],xs[0],ys[0]);
    }
    else
    {
     line(xs[i],ys[i],xs[i+1],ys[i+1]);
    }
   }
   printf("%d\n",n);

   for(i=0;i<n;i++)
   {
    if(i==(n-1))
    {
     inverse_m[i]=(xs[i]-xs[0])/((float)(ys[i]-ys[0]));
    }
    else
    {
     inverse_m[i]=(xs[i]-xs[i+1])/((float)(ys[i]-ys[i+1]));
    }
   }

   for(i=0;i<n;i++)
   {
    printf("%d , %d\n",points[i]->x,points[i]->y);
   }

   for(i=0;i<n;i++)
   {
    edges[i]=(struct edge *)malloc(sizeof(struct edge));
    edges[i]->start=points[i];
    if(i==n-1)
    {
      edges[i]->end=points[0];
    }
    else
    {
     edges[i]->end=points[i+1];
    }
    edges[i]->inv_m=inverse_m[i];

    if((edges[i]->end->x)>(edges[i]->start->x))
    {
     edges[i]->xmin=edges[i]->start->x;
    }
    else
    {
     edges[i]->xmin=edges[i]->end->x;
    }

    if((edges[i]->end->y)>(edges[i]->start->y))
    {
     edges[i]->ymin=edges[i]->start->y;
     edges[i]->xymin=edges[i]->start->x;
    }
    else
    {
     edges[i]->ymin=edges[i]->end->y;
     edges[i]->xymin=edges[i]->end->x;
    }

    edges[i]->status=0;
   }

   for(i=0;i<n;i++)
   {
     struct edge *first=edges[i];
     struct edge *second;
     if(i==n-1)
     {
       second=edges[0];
     }
     else
     {
      second=edges[i+1];
     }

     if(first->start->y>first->end->y && second->end->y<second->start->y)
     {
      struct point *temp=(struct point*)malloc(sizeof(struct point));
      temp->y=second->start->y+1;

      p=getp(first->end->x,first->end->y,first->start->x,first->start->y);

      if(p>0)
      {
       if(first->end->x>first->start->x)
       {
	temp->x=first->end->x-1;
       }
       else
       {
	temp->x=first->end->x+1;
       }
      }
      else
      {
       temp->x=first->end->x;
      }
      first->end=temp;
     }
     else if(first->start->y<first->end->y && second->end->y>second->start->y)
     {
      struct point *temp=(struct point*)malloc(sizeof(struct point));
      temp->y=first->end->y+1;

      p=getp(second->start->x,second->start->y,second->end->x,second->end->y);

      if(p>0)
      {
	if(second->end->x>second->start->x)
	{
	  temp->x=second->start->x+1;
	}
	else
	{
	  temp->x=second->start->x-1;
	}
      }
      else
      {
       temp->x=second->start->x;
      }

      second->start=temp;
     }
   }

   for(i=0;i<n-1;i++)
   {
    for(j=0;j<n-i-1;j++)
    {
     if(edges[j]->ymin>edges[j+1]->ymin)
     {
      struct edge *temp=edges[j];
      edges[j]=edges[j+1];
      edges[j+1]=temp;
     }
     else if(edges[j]->ymin==edges[j+1]->ymin)
     {
       if(edges[j]->xmin>edges[j+1]->xmin)
       {
	 struct edge *temp=edges[j];
	 edges[j]=edges[j+1];
	 edges[j+1]=temp;
       }
     }
    }
   }

   for(i=0;i<n;i++)
   {
    printf("startx=%d  ,  starty=%d  endx=%d  ,  endy=%d  xmin=%d  ,  ymin=%d xymin=%d \n ",edges[i]->start->x,edges[i]->start->y,edges[i]->end->x,edges[i]->end->y,edges[i]->xmin,edges[i]->ymin,edges[i]->xymin);
   }

   getch();
   closegraph();
   return 0;
}