如何使用Visual Studio 2005画一张正规的国旗图片
绘画一张正规标准的国旗图片是学习C程序最基础的一步,也是必不可少的一步,在学习C程序的第一天,学习绘画国旗是十分必要的,接下来,我将展示出它的绘画过程以及成品图。
#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include<math.h>
const double PI = 3.1415927;
void DrawStar(int x, int y, int R, double arcbegin)
{
POINT pt[10];
double r = R*sin(18 * PI / 180) / sin(126 * PI / 180);
double arc = PI / 5.0;
double r1;
for (int i = 0; i < 10; ++i)
{
if (i % 2 == 0)
r1 = R;
else
r1 = 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(900, 600); // 创建绘图窗口
setlinecolor(RGB(255, 0, 0));
setfillcolor(RGB(255, 0, 0));
fillrectangle(0, 0, 900, 600);
DrawStar(150, 150, 90, -PI / 2);
DrawStar(300, 60, 30, -PI - atan(3.0 / 5));
DrawStar(360, 120, 30, -PI - atan(1.0 / 7));
DrawStar(360, 210, 30, -PI + atan(2.0 / 7));
DrawStar(300, 270, 30, -PI + atan(4.0 / 5));
_getch(); // 按任意键继续
closegraph(); // 关闭绘图窗口
}
以上就是我绘制国旗的程序以及成果图。
我爱中国嗷!