C语言中的fillpoly()函数

头文件显示图形。h包含 fillpoly() 函数,用于绘制和填充多边形,即三角形、矩形、五边形、六边形等。它需要与drawpoly()相同的参数。

null

语法:

void fillpoly( int number, int *polypoints );

where,
number indicates (n + 1) number of points 
where, n is the number of vertices in a 
polygon. polypoints points to a sequence
of (n*2) integers.

例如:

Input : arr[] = {320, 150, 400, 250,
                 250, 350, 320, 150};
Output : 图片[1]-C语言中的fillpoly()函数-yiteyi-C++库

Input : arr[] = {120, 250, 400, 250, 400,
                350, 450, 200, 120, 250};
Output : 图片[2]-C语言中的fillpoly()函数-yiteyi-C++库

说明: fillpoly()的声明包含两个参数:number表示(n+1)点的数量,其中n是多边形中顶点的数量。第二个参数,即多点指向(n*2)个整数序列。每对整数给出多边形上一点的x和y坐标。我们指定(n+1)个点,因为第一个点的坐标应该等于(n+1)th才能绘制完整的图形。

例1: 使用fillpoly绘制三角形。 int arr[]={320、150、400、250、250、350、320、150};

大堆 包含三角形的坐标,即(320150)、(400250)和(250350)。请注意,阵列中的最后一个点(320150)与第一个点相同。

下面是fillpoly()函数的实现。

// C Implementation for fillpoly()
#include <graphics.h>
// driver code
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
// coordinates for polygon
int arr[] = {320, 150, 400, 250,
250, 350, 320, 150};
// initgraph initializes the
// graphics system by loading a
// graphics driver from disk
initgraph(&gd, &gm, "" );
// fillpoly function
fillpoly(4, arr);
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system .
closegraph();
return 0;
}


输出:

图片[3]-C语言中的fillpoly()函数-yiteyi-C++库

注: fillpoly()使用当前填充图案和颜色进行填充,可以使用setfillstyle进行更改。

下面是使用setfillstyle()填充多边形的程序。

// C Implementation for fillpoly()
// using setfillstyle()
#include <graphics.h>
// driver code
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
// coordinates of polygon
int arr[] = {320, 150, 400, 250,
250, 350, 320, 150};
// initgraph initializes the
// graphics system by loading a
// graphics driver from disk
initgraph(&gd, &gm, "" );
// setfillstyle function sets the
// current fill pattern and fill color.
setfillstyle(XHATCH_FILL, RED);
// fillpoly function
fillpoly(4, arr);
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system .
closegraph();
return 0;
}


输出:

图片[4]-C语言中的fillpoly()函数-yiteyi-C++库
© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享