#include<graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
void main()
{
int driver,mode;
static int polypoints1[18]={100,100,110,120,100,130,120,125,140,140,130,120,
140,110,120,115,100,100};
static int polypoints2[18]={180,100,210,120,200,130,220,125,240,140,230,120,
240,110,220,115,220,110};
driver=DETECT;
mode=0;
initgraph(&driver,&mode,"");
setfillcolor(RED);
setcolor(YELLOW);
drawpoly(9,polypoints1);
drawpoly(9,polypoints2);
getch();
//restorecrtmode();
}
功能: 函数drawpoly() 用当前绘图色、线型及线宽,画一个给定若干点所定义的多边形。
用法: 此函数调用方式为void drawpoly(int pnumber,int *points);
说明: 参数pnumber为多边形的顶点数;参数points指向整型数组,该数组中是多边形所有顶点(x,y)坐标值,即一系列整数对,x坐标值在前。显然整型数组的维数至少为顶点数的2倍,在定义了多边形所有顶点的数组polypoints时,顶点数目可通过计算sizeof(polypoints)除以2倍的sizeof(int)得到,这里除以2倍的原因是每个顶点有两个整数坐标值。另外有一点要注意,画一个n个顶点的闭合图形,顶点数必须等于n+1,并且最后一点(第n+1)点坐标必须等于第一点的坐标。
drawpoly()函数对应的头文件为grpahics.h