1. 初始化图形系统 
函数名: initgraph
  : 初始化图形系统
  : void far initgraph(int far *graphdriver, int far *graphmode,
    char far *pathtodriver);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
  /* request auto detection */
  int gdriver = DETECT, gmode, errorcode;
  /* initialize graphics mode */
  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);            /* return with error code */
  }
  /* draw a line */
  line(0, 0, getmaxx(), getmaxy());
  /* clean up */
  getch();
  closegraph();
  return 0;
}
 
 
2.  
函数名: drawpoly
  : 画多边形
  : void far drawpoly(int numpoints, int far *polypoints);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
  /* request auto detection */
  int gdriver = DETECT, gmode, errorcode;
  int maxx, maxy;
  /* our polygon array */
  int poly[10];
  /* initialize graphics and 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();
  /* terminate with an error code */
      exit(1);
  }
  maxx = getmaxx();
  maxy = getmaxy();
  poly[0] = 20;        /* 1st vertext */
  poly[1] = maxy / 2;
  poly[2] = maxx - 20; /* 2nd */
  poly[3] = 20;
  poly[4] = maxx - 50; /* 3rd */
  poly[5] = maxy - 20;
  poly[6] = maxx / 2;  /* 4th */
  poly[7] = maxy / 2;
/*
  drawpoly doesn't automatically close
  the polygon, so we close it.
*/
  poly[8] = poly[0];
  poly[9] = poly[1];
  /* draw the polygon */
  drawpoly(5, poly);
  /* clean up */
  getch();
  closegraph();
  return 0;
}
 
 
_
 
函数名: ellipse
  : 画一椭圆
  : void far ellipse(int x, int y, int stangle, int endangle,
    int xradius, int yradius);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
  /* request auto detection */
  int gdriver = DETECT, gmode, errorcode;
  int midx, midy;
  int stangle = 0, endangle = 360;
  int xradius = 100, yradius = 50;
  /* 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 an error code */
  }
  midx = getmaxx() / 2;
  midy = getmaxy() / 2;
  setcolor(getmaxcolor());
  /* draw ellipse */
  ellipse(midx, midy, stangle, endangle,
    xradius, yradius);
  /* clean up */ c语言库函数
  getch();
  closegraph();
  return 0;
}
 
 
_
 
函数名: fillellipse
  : 画出并填充一椭圆
  : void far fillellipse(int x, int y, int xradius, int yradius);
程序例:
#include <graphics.h>
#include <conio.h>
int main(void)
{
  int gdriver = DETECT, gmode;
  int xcenter, ycenter, i;
  initgraph(&gdriver,&gmode,"");
  xcenter = getmaxx() / 2;
  ycenter = getmaxy() / 2;
  for (i=0; i<13; i++)
  {
      setfillstyle(i,WHITE);
      fillellipse(xcenter,ycenter,100,50);
      getch();
  }
  closegraph();
  return 0;
}
 
 
 
_
 
函数名: getbkcolor
  : 返回当前背景颜
  : int far getbkcolor(void);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
  /* request auto detection */
  int gdriver = DETECT, gmode, errorcode;
  int bkcolor, midx, midy;
  char bkname[35];
/* 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();
/* terminate with an error code */
      exit(1);
  }

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。