graphicsh 功能.docx

上传人:b****4 文档编号:11579095 上传时间:2023-03-19 格式:DOCX 页数:16 大小:21.02KB
下载 相关 举报
graphicsh 功能.docx_第1页
第1页 / 共16页
graphicsh 功能.docx_第2页
第2页 / 共16页
graphicsh 功能.docx_第3页
第3页 / 共16页
graphicsh 功能.docx_第4页
第4页 / 共16页
graphicsh 功能.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

graphicsh 功能.docx

《graphicsh 功能.docx》由会员分享,可在线阅读,更多相关《graphicsh 功能.docx(16页珍藏版)》请在冰豆网上搜索。

graphicsh 功能.docx

graphicsh功能

graphics.h功能

@函数名称:

    getarccoords

函数原型:

    voidfargetarccoords(structarccoordstypefar*coords)

函数功能:

    得到最后一次画圆弧的坐标

函数返回:

参数说明:

    coords-使用函数arc()画圆弧的坐标,该结构如下:

          structarccoordstype{

            intm,n;  /*圆心坐标*/

            intxstart,ysrart,xend,yend;/*圆弧起点终点坐标*/

          };

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  structarccoordstypearcinfo;

  intmidx,midy;

  intstangle=45,endangle=270;

  charsstr[80],estr[80];

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("

ressanykeytohalt:

");

      getch();

      exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

  arc(midx,midy,stangle,endangle,100);

  getarccoords(&arcinfo);

  sprintf(sstr,"*-(%d,%d)",arcinfo.xstart,arcinfo.ystart);

  sprintf(estr,"*-(%d,%d)",arcinfo.xend,arcinfo.yend);

  outtextxy(arcinfo.xstart,arcinfo.ystart,sstr);

  outtextxy(arcinfo.xend,arcinfo.yend,estr);

  getch();

  closegraph();

  return0;

}

@函数名称:

    arc

函数原型:

    voidfararc(intx,inty,intstart,intend,intradius)

函数功能:

    画一圆弧线

函数返回:

参数说明:

    x,y-圆心,radius-半径,start,end-弧线的起始和中止角度

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy;

  intstangle=45,endangle=135;

  intradius=100;

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("

ressanykeytohalt:

");

      getch();

      exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

  arc(midx,midy,stangle,endangle,radius);

  getch();

  closegraph();

  return0;

}

@函数名称:

    circle

函数原型:

    voidfarcircle(intx,inty,intradius)

函数功能:

    画圆

函数返回:

参数说明:

    x,y-圆心坐标,radius-半径

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy;

  intradius=100;

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("

ressanykeytohalt:

");

      getch();

      exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

  circle(midx,midy,radius);

  getch();

  closegraph();

  return0;

}

@函数名称:

    pieslice

函数原型:

    voidfarpieslice(intx,inty,intstart,intend,intradius)

函数功能:

    画扇形

函数返回:

参数说明:

    x,y-扇形所在园的圆心坐标,start,end-扇形的开始和结束角度,radius-园的半径

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy;

  intstangle=45,endangle=135,radius=100;

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("Pressanykeytohalt:

");

      getch();

      exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setfillstyle(EMPTY_FILL,getmaxcolor());

  pieslice(midx,midy,stangle,endangle,radius);

  getch();

  closegraph();

  return0;

}

@函数名称:

    getaspectratio,setaspectratio

函数原型:

    voidfargetaspectratio(intfar*xasp,intfar*yasp)

函数功能:

    得到图形显示的比例因子

函数返回:

参数说明:

    xasp-x方向比例因子,yasp-y方向比例因子

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  intxasp,yasp,midx,midy;

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("Pressanykeytohalt:

");

  getch();

  exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

  getaspectratio(&xasp,&yasp);

  circle(midx,midy,100);

  getch();

  cleardevice();

  setaspectratio(xasp/2,yasp);

  circle(midx,midy,100);

  getch();

  cleardevice();

  setaspectratio(xasp,yasp/2);

  circle(midx,midy,100);

  getch();

  closegraph();

  return0;

}

@函数名称:

  sector

函数原型:

    voidfarsector(intx,inty,intstart,intend,intxrad,intyrad)

函数功能:

    画扇形,并填充以预定填充图案和颜色

函数返回:

参数说明:

    x,y-圆心坐标,start,end-圆弧起点和终点角度,单位度,xrad,yrad-椭圆x,y方向的半径

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain(void)

{

  /*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy,i;

  intstangle=45,endangle=135;

  intxrad=100,yrad=50;

  /*initializegraphicsandlocalvariables*/

  initgraph(&gdriver,&gmode,"");

  /*readresultofinitialization*/

  errorcode=graphresult();

  if(errorcode!

=grOk)  /*anerroroccurred*/

  {

    printf("Graphicserror:

%s\n",grapherrormsg(errorcode));

    printf("Pressanykeytohalt:

");

    getch();

    exit

(1);/*terminatewithanerrorcode*/

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  /*loopthroughthefillpatterns*/

  for(i=EMPTY_FILL;i<USER_FILL;i++)

  {

    /*setthefillstyle*/

    setfillstyle(i,getmaxcolor());

    /*drawthesectorslice*/

    sector(midx,midy,stangle,endangle,xrad,yrad);

    getch();

  }

  /*cleanup*/

  closegraph();

  return0;

}

@函数名称:

    ellipse

函数原型:

    voidfarellipse(intx,inty,intstart,intend,intxradius,intyradius)

函数功能:

    画椭圆弧

函数返回:

参数说明:

    x,y-圆心坐标,start,end-圆弧起点和终点角度,单位为度,xradius,yradius-椭圆x,y方向的半径

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy;

  intstangle=0,endangle=360;

  intxradius=100,yradius=50;

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("Pressanykeytohalt:

");

      getch();

      exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  setcolor(getmaxcolor());

  ellipse(midx,midy,stangle,endangle,xradius,yradius);

  getch();

  closegraph();

  return0;

}

@函数名称:

    fillellipse

函数原型:

    voidfarfillellipse(intx,inty,intxradius,intyradius)

函数功能:

    画椭圆并用当前的填充色和填充图案填充

函数返回:

参数说明:

    x,y-圆心坐标,xradius,yradius-椭圆x,y方向的半径

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy,i;

  intxradius=100,yradius=50;

  initgraph(&gdriver,&gmode,"");

  errorcode=graphresult();

  if(errorcode!

=grOk){

    printf("Graphicserror:

%s\n",grapherrormsg(errorcode));

    printf("Pressanykeytohalt:

");

    getch();

    exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  /*loopthroughthefillpatterns*/

  for(i=EMPTY_FILL;i<USER_FILL;i++){

    /*setfillpattern*/

    setfillstyle(i,getmaxcolor());

    fillellipse(midx,midy,xradius,yradius);

    getch();

  }

  closegraph();

  return0;

}

@函数名称:

    getfillsettings

函数原型:

    voidfargetfillsettings(structfillsettingstypefar*info)

函数功能:

    得到当前填充模式和颜色编号

函数返回:

参数说明:

    info-当前填充模式和颜色编号,该结构定义如下:

      structfillsettingstype{

        intpatterns;

        intcolor;

      }

      其中patterns定义如下:

      EMPTY_FILL    0背景色填充    SOLID_FILL    1实填充

      LINE_FILL    2---线填充    LTSLASH_FILL  3斜线填充

      SLASH_FILL    4粗斜线填充    BKSLASH_FILL  5反粗斜线填充

      LTBKSLASH_FILL6反斜线填充    HATCH_FILL    7网格填充

      XHATCH_FILL  8斜网格填充    INTERLEAVE_FILL9间隔点线填充

      WIDE_DOT_FILL  10稀疏点填充  CLOSE_DOT_FILL  11密集点填充

      USER_FILL    12用户自定义填充

所属文件:

    <graphics.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

char*fname[]={"EMPTY_FILL","SOLID_FILL","LINE_FILL","LTSLASH_FILL","SLASH_FILL",

  "BKSLASH_FILL","LTBKSLASH_FILL","HATCH_FILL","XHATCH_FILL","INTERLEAVE_FILL",

  "WIDE_DOT_FILL","CLOSE_DOT_FILL","USER_FILL"};

intmain()

{

  intgdriver=DETECT,gmode,errorcode;

  structfillsettingstypefillinfo;

  intmidx,midy;

  charpatstr[40],colstr[40];

  initgraph(&gdriver,&gmode,);

  errorcode=graphresult();

  if(errorcode!

=grOk)

  {

      printf("Graphicserror:

%s",grapherrormsg(errorcode));

      printf("Pressanykeytohalt:

");

      getch();

      exit

(1);

  }

  midx=getmaxx()/2;

  midy=getmaxy()/2;

  getfillsettings(&fillinfo);

  sprintf(patstr,"%sisthefillstyle.",fname[fillinfo.pattern]);

  sprintf(colstr,"%disthefillcolor.",fillinfo.color);

  settextjustify(CENTER_TEXT,CENTER_TEXT);

  outtextxy(midx,midy,patstr);

  outtextxy(midx,midy+2*textheight("W"),colstr);

  getch();

  closegraph();

  return0;

}

@函数名称:

    getfillpattern,setfillpattern

函数原型:

    voidfargetfillpattern(charfar*pattern)

          voidfarsetfillpattern(char

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1