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

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

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

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