一、项目介绍这是一个C语言绘制中国国旗的程序,为祖国母亲庆生!编译环境:visual c++ 6.0第三方库:Easyx2022 注意需要提前安装easyX,如没有基础可以先了解easyX图形编程二、运行截图
【瓜分奖池】C语言画国庆节国旗教程及源码 第5张插图

【瓜分奖池】C语言画国庆节国旗教程及源码 第6张插图

【瓜分奖池】C语言画国庆节国旗教程及源码 第7张插图
三、代码思路1.引入easyx头文件define PI 3.143.角星的外接圆半径和起始角度作为参数void fivePointedStar(int radius, double startAngle){ double delta = 2 PI / 5; // 增量为一个圆的5分之一 POINT points[5]; // 长度为5的POINT数组,用于存储5个点 for (int i = 0; i < 5; i++) { points[i].x = cos(startAngle + i delta 2) radius; // 计算x坐标 points[i].y = sin(startAngle + i delta 2) radius; // 计算y坐标 } solidpolygon(points, 5);}4.主函数int main(void){ int width = 900; int height = width / 3 2; // 高度为宽度的2/3 int grid = width / 3 / 15; // 网格宽度 initgraph(800, 420); // 创建窗体设置背景色 setbkcolor(BLACK); cleardevice();setcolor(YELLOW); // 文本颜色setbkcolor(BLACK); // 文本背景色settextstyle(100,0,"楷体"); // 文本高度和字体outtextxy(600, 10, "喜"); // 文本位置和内容outtextxy(600, 110, "迎"); // 文本位置和内容outtextxy(600, 210, "国"); // 文本位置和内容outtextxy(600, 310, "庆"); // 文本位置和内容outtextxy(700, 10, "举"); // 文本位置和内容outtextxy(700, 110, "国"); // 文本位置和内容outtextxy(700, 210, "欢"); // 文本位置和内容outtextxy(700, 310, "庆"); // 文本位置和内容setcolor(YELLOW);setbkcolor(BLACK);settextstyle(20,0,"楷体");outtextxy(650, 400, "Dotcpp.com");setfillcolor(RED);solidrectangle(10,10,600,400); setaspectratio(1, -1); // 翻转坐标轴,设置填充颜色为黄色 setfillcolor(YELLOW); setpolyfillmode(WINDING); getchar(); closegraph(); return 0;}完成四、完整源码include include // 引用图形库头文件include#define PI 3.14void fivePointedStar(int radius, double startAngle)// 角星的外接圆半径和起始角度作为参数,由调用者决定{ double delta = 2 PI / 5; // 增量为一个圆的5分之一 POINT points[5]; // 长度为5的POINT数组,用于存储5个点 for (int i = 0; i < 5; i++) { points[i].x = cos(startAngle + i delta 2) radius; // 计算x坐标 points[i].y = sin(startAngle + i delta 2) radius; // 计算y坐标 } solidpolygon(points, 5);}int main(void){ int width = 900; int height = width / 3 2; // 高度为宽度的2/3 int grid = width / 3 / 15; // 网格宽度 initgraph(800, 420); // 创建窗体设置背景色 setbkcolor(BLACK); cleardevice();setcolor(YELLOW); // 文本颜色setbkcolor(BLACK); // 文本背景色settextstyle(100,0,"楷体"); // 文本高度和字体outtextxy(600, 10, "喜"); // 文本位置和内容outtextxy(600, 110, "迎"); // 文本位置和内容outtextxy(600, 210, "国"); // 文本位置和内容outtextxy(600, 310, "庆"); // 文本位置和内容outtextxy(700, 10, "举"); // 文本位置和内容outtextxy(700, 110, "国"); // 文本位置和内容outtextxy(700, 210, "欢"); // 文本位置和内容outtextxy(700, 310, "庆"); // 文本位置和内容setcolor(YELLOW);setbkcolor(BLACK);settextstyle(20,0,"楷体");outtextxy(650, 400, "Dotcpp.com"); setfillcolor(RED);solidrectangle(10,10,600,400); setaspectratio(1, -1); // 翻转坐标轴,设置填充颜色为黄色 setfillcolor(YELLOW); setpolyfillmode(WINDING); setorigin(grid 5, grid 5); // 大五角星 fivePointedStar(grid 3, PI / 2); setorigin(grid 10, grid 2); // 小五角星1 double startAngle = atan(3.0 / 5.0) + PI; fivePointedStar(grid, startAngle); setorigin(grid 12, grid 4); // 小五角星2 startAngle = atan(1.0 / 7.0) + PI; fivePointedStar(grid, startAngle); setorigin(grid 12, grid 7); // 小五角星3 startAngle = -atan(2.0 / 7.0) + PI; fivePointedStar(grid, startAngle); setorigin(grid 10, grid * 9); // 小五角星4 startAngle = -atan(4.0 / 5.0) + PI; fivePointedStar(grid, startAngle); getchar(); closegraph(); return 0;}