收藏 分享(赏)

C语言实现动态星空.doc

上传人:精品资料 文档编号:10286853 上传时间:2019-10-28 格式:DOC 页数:2 大小:14.45KB
下载 相关 举报
C语言实现动态星空.doc_第1页
第1页 / 共2页
C语言实现动态星空.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、/ 编译环境:Visual C+ 6.0, EasyX 2014 冬至版/ e a s y x . c n/#include #include #include #define MAXSTAR 200 / 星星总数struct STARdouble x;int y;double step;int color;STAR starMAXSTAR;/ 初始化星星void InitStar(int i)stari.x = 0;stari.y = rand() % 480;stari.step = (rand() % 5000) / 1000.0 + 1;stari.color = (int)(star

2、i.step * 255 / 6.0 + 0.5); / 速度越快,颜色越亮stari.color = RGB(stari.color, stari.color, stari.color);/ 移动星星void MoveStar(int i)/ 擦掉原来的星星putpixel(int)stari.x, stari.y, 0);/ 计算新位置stari.x += stari.step;if (stari.x 640) InitStar(i);/ 画新星星putpixel(int)stari.x, stari.y, stari.color);/ 主函数void main()srand(unsigned)time(NULL); / 随机种子initgraph(640, 480); / 创建绘图窗口/ 初始化所有星星for(int i = 0; i MAXSTAR; i+)InitStar(i);stari.x = rand() % 640;/ 绘制星空,按任意键退出while(!kbhit()for(int i = 0; i MAXSTAR; i+)MoveStar(i);Sleep(20);closegraph(); / 关闭绘图窗口

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报