首页 > 编程 > C++ > 正文

C语言fillpoly函数详解

2020-05-23 14:13:51
字体:大 中 小
来源:转载
供稿:网友

在C语言中,fillpoly函数的功能是画一个多边形,并且把多边形填充。填充边框所定义的多边形的内部。fillpoly 函数的用法:void far fillpoly(int numpoints, int far *polypoints);。

C语言中,fillpoly函数的功能是画一个多边形,今天我们就来学习学习。

C语言fillpoly函数:

填充一个多边形

函数名:

fillpoly

功 能:

画并填充一个多边形

头文件:#

include

原 型:

fillpoly(int numpoints, int far *polypoints);

参数说明:

numpoints 为多边形的边数;far *polypoints 为存储各顶点坐标的数组,每两个一组表示一个顶点的 X 和 Y 坐标。

实例代码:

 

 
  1. #include <graphics.h> 
  2. #include <stdlib.h> 
  3. #include <stdio.h> 
  4. #include <conio.h> 
  5.  
  6. int main(void) 
  7. { 
  8. /* request auto detection */ 
  9. int gdriver = DETECT, gmode, errorcode; 
  10. int i, maxx, maxy; 
  11.  
  12. /* our polygon array */ 
  13. int poly[8]; 
  14.  
  15. /* initialize graphics, local variables */ 
  16. initgraph(&gdriver, &gmode, ""); 
  17.  
  18. /* read result of initialization */ 
  19. errorcode = graphresult(); 
  20. if (errorcode != grOk) 
  21. /* an error occurred */ 
  22. { 
  23. printf("Graphics error: %s/n", grapherrormsg(errorcode)); 
  24. printf("Press any key to halt:"); 
  25. getch(); 
  26. exit(1); 
  27. /* terminate with an error code */ 
  28. } 
  29.  
  30. maxx = getmaxx(); 
  31. maxy = getmaxy(); 
  32.  
  33. poly[0] = 20; /* 1st vertext */ 
  34. poly[1] = maxy / 2; 
  35.  
  36. poly[2] = maxx - 20; /* 2nd */ 
  37. poly[3] = 20; 
  38.  
  39. poly[4] = maxx - 50; /* 3rd */ 
  40. poly[5] = maxy - 20; 
  41.  
  42. /* 
  43. 4th vertex. fillpoly automatically 
  44. closes the polygon. 
  45. */ 
  46. poly[6] = maxx / 2; 
  47. poly[7] = maxy / 2; 
  48.  
  49. /* loop through the fill patterns */ 
  50. for (i=EMPTY_FILL; i<USER_FILL; i++) 
  51. { 
  52. /* set fill pattern */ 
  53. setfillstyle(i, getmaxcolor()); 
  54.  
  55. /* draw a filled polygon */ 
  56. fillpoly(4, poly); 
  57.  
  58. getch(); 
  59. } 
  60.  
  61. /* clean up */ 
  62. closegraph(); 
  63. return 0; 
  64. } 

注:fillpoly 函数是 TC 编译环境下的函数,VC 中无法使用。

以上就是关于fillpoly函数填充多边形功能的实现代码,希望对大家的学习有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表