头文件显示图形。h包含 drawpoly() 用于绘制多边形的函数,如三角形、矩形、五边形、六边形等。
null
语法:
void drawpoly( 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 :Input : arr[] = {120, 250, 400, 250, 400, 350, 450, 200, 120, 250}; Output :
![]()
说明: drawpoly()的声明包含两个参数。数字表示(n+1)点的数量,其中n是多边形中的顶点数。第二个参数,即多点指向(n*2)个整数序列。每对整数给出多边形上一点的x和y坐标。我们指定(n+1)个点,因为第一个点的坐标应该等于(n+1)th才能绘制完整的图形。
例1: 使用drawpoly绘制三角形。 int arr[]={320、150、400、250、250、350、320、150};
大堆 啊 包含三角形的坐标,即(320150)、(400250)和(250350)。请注意,阵列中的最后一个点(320150)与第一个点相同。
下面是drawpoly()函数的实现。
// C Implementation for drawpoly() #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, "" ); // drawpoly function drawpoly(4, arr); getch(); // closegraph function closes the // graphics mode and deallocates // all memory allocated by // graphics system . closegraph(); return 0; } |
输出:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END