雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

C語言fillpoly函數(shù)詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊:

C語言中,fillpoly函數(shù)的功能是畫一個多邊形,今天我們就來學習學習。

C語言fillpoly函數(shù):填充一個多邊形

函數(shù)名:fillpoly

功  能:畫并填充一個多邊形

頭文件:#include <graphics.h>

原  型:fillpoly(int numpoints, int far *polypoints);

參數(shù)說明:numpoints 為多邊形的邊數(shù);far *polypoints 為存儲各頂點坐標的數(shù)組,每兩個一組表示一個頂點的 X 和 Y 坐標。

實例代碼:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
 
int main(void)
{
 /* request auto detection */
 int gdriver = DETECT, gmode, errorcode;
 int i, maxx, maxy;
 
 /* our polygon array */
 int poly[8];
 
 /* 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 */
 }
 
 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;
 
 /*
 4th vertex. fillpoly automatically
 closes the polygon.
 */
 poly[6] = maxx / 2;
 poly[7] = maxy / 2;
 
 /* loop through the fill patterns */
 for (i=EMPTY_FILL; i<USER_FILL; i++)
 {
 /* set fill pattern */
 setfillstyle(i, getmaxcolor());
 
 /* draw a filled polygon */
 fillpoly(4, poly);
 
 getch();
 }
 
 /* clean up */
 closegraph();
 return 0;
}

注:fillpoly 函數(shù)是 TC 編譯環(huán)境下的函數(shù),VC 中無法使用。

以上就是關(guān)于fillpoly函數(shù)填充多邊形功能的實現(xiàn)代碼,希望對大家的學習有所幫助。

上一篇:C++實現(xiàn)動態(tài)綁定代碼分享

欄    目:C語言

下一篇:C++實現(xiàn)對輸入數(shù)字組進行排序

本文標題:C語言fillpoly函數(shù)詳解

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/2668.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有