五角星

void DrawPentacle(CDC*pDC, FLOAT circleR/*半径*/, FLOAT vectX/*圆点*/, FLOAT vectY)

{

   //偏移主窗口(x,y)距离

   //五角星的各个顶点

   POINT apt[6] = {(LONG)vectX,(LONG)(vectY-circleR),

      (LONG)(vectX-circleR*cos(54.0f*PI/180)),(LONG)(vectY+circleR*sin(54.0f*PI/180)),

      (LONG)(vectX+circleR*cos(18.0f*PI/180)),(LONG)(vectY-circleR*sin(18.0f*PI/180)),

      (LONG)(vectX-circleR*cos(18.0f*PI/180)),(LONG)(vectY-circleR*sin(18.0f*PI/180)),

      (LONG)(vectX+circleR*cos(54.0f*PI/180)),(LONG)(vectY+circleR*sin(54.0f*PI/180)),

      (LONG)vectX, (LONG)(vectY-circleR)};

   HDC hDC = pDC->GetSafeHdc();

   SetPolyFillMode(hDC, WINDING);


   for(int index = 0; index < 6; index++){

      Polygon(hDC, apt,6);

   }

}


六叶图

C语言程序说明:

本实例主要讲解arc(),她的调用格式如下:

void far arc(int x,int y,int stangle,intendangle,int radius)

参数说明:

x,y为所绘制的弧线以(x,y)为圆心。

radius:
所绘制弧线的半径,从stangle开始到endangle结束(用度表示),画一段圆弧线。在TURBO C中规定x轴正向为0度,逆时针方向旋转一周,依次为90度、180度、270度和360度。

另外,本例还讲解了两个三家函数sin()cos()。注意,在语言程序中使用三角函数时,要把度数转化为弧度才能带入公式进行运算,度数与弧度的具体切换示例:25度编程弧度为25*3.14/180

代码如下:

#include<graphics.h>
#include <math.h>
#include <conio.h>

#define PI 3.1415926535

/*
图形驱动函数 */
void initgr(void)
{
   int gd = DETECT, gm = 0;
  registerbgidriver(EGAVGA_driver);
   initgraph(&gd, &gm,"");
}

void main(void)
{
   double a = 0, b;
   int x0 = 340, y0 = 240,radius = 100, i, x, y;
   initgr(); /*
驱动图形模式 */
   setcolor(2); /*
设置前景色为绿色 */
   setlinestyle(0, 0, 0); /*
设置股线的类型与宽度 */
   for(i = 0; i < 6; i++, a+= 60)
   {
       b = a* PI / 180; /*
把度数转化为弧度 */
       x =x0 + radius * cos(b);
       y =y0 + radius * sin(b);

      arc(x, y, 120 - i * 60, 240 - i * 60, radius); /*
绘制弧线 */
   }
   getch(); /*
暂停屏幕查看结果 */
   closegraph(); /*
关闭图形模式 */

}

171302406.jpg