目标:绘制一面国旗
程序设计
#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include <math.h>
const double PI = 3.1415927; //常量
通过(x,y)坐标确定五角星的角的位置。
void DrawStar(int x, int y, int R,double arcbegin) /*调用主函数中DrawStar
{
double r1;
POINT pt[10];
double r = R*sin(18 * PI / 180) / sin(126 * PI / 180);
double arc = PI / 5.0;
for(int i = 0; i<10; ++i)
{
if
(i % 2 == 0)
r1 = R;
else
r1 = r;
pt[i].y = r1*sin(arcbegin + i*arc) + y; // 将五角星的角的坐标存放在pt[]中。
pt[i].x = r1*cos(arcbegin + i*arc) + x;
}
setfillcolor(RGB(255, 255, 0)); //填充五角星的颜色为黄色
setcolor(RGB(255, 255, 0));// 填充五角星边的颜色为黄色
fillpolygon(pt, 10); / /fillpolygon函数 画填充的多边形
}
int main()
{
initgrap