1、/ 编译环境:Visual C+ 6.0,EasyX 2014冬至版/ e a s y x . c n/#include #include #include #define MAXSTAR 200/ 星星总数struct STARdoublex;inty;doublestep;intcolor;STAR starMAXSTAR;/ 初始化星星void InitStar(int i)stari.x = 0;stari.y = rand() % 480;stari.step = (rand() % 5000) / 1000.0 + 1;stari.color = (int)(stari.step 。
2、* 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();/ 关闭绘图窗口。
《C语言实现动态星空》由会员简****9分享,可在线阅读,更多相关《C语言实现动态星空》请在金锄头文库上搜索。