一、程序设计
#include <graphics.h> // 引用图形库头文件
#include <math.h>
#include <conio.h>
const double PI = 3.1415927;
void DrawStar(int x, int y, int R, double arcbegin)
{
POINT pt[10];
double arc = PI / 5.0;
double r = R*sin(18 * PI / 180) / sin(126 * PI / 180);
double r1;for (int i = 0; i < 10; ++i)
{if (i % 2 == 0)r1 = R;elser1 = r;pt[i].y = sin(arcbegin + i*arc)*r1 + y;pt[i].x = cos(arcbegin + i*arc)*r1 + x;
}setfillcolor(RGB(255, 255, 0));
setcolor(RGB(255, 255, 0));
fillpolygon(pt, 10);
}
int main()
{
initgraph(600, 400); // 创建绘图窗口,大小为600*400像素
setfillcolor(RGB(255, 0, 0));
setcolor(RGB(255, 0, 0));
fillrectangle(0, 0, 600,400); // 画矩形,长宽分别为600,400
DrawStar(100, 100, 60, -PI/2);
DrawStar(200, 40, 20, -PI -atan(3.0/5));
DrawStar(240, 80, 20, -PI -atan(1.0 / 7));
DrawStar(240, 140, 20, -PI +atan(2.0/7 ));
DrawStar(200, 180, 20, -PI + atan(4.0 / 5));
}
二、结果展示