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



三、代码思路
1.引入easyx头文件
#include <easyx.h>
2.宏定义
#define PI 3.14
3.角星的外接圆半径和起始角度作为参数
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 <stdio.h>
#include <easyx.h>
#include <math.h>
#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include<time.h>
#define PI 3.14
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);
}
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;
}C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程