当前位置: 首页 > news >正文

网站建设 公司 天津学校网站建设运行简介

网站建设 公司 天津,学校网站建设运行简介,做店铺装修的公司网站,大连网络开发公司大家好#xff0c;这是我学完C后#xff0c;完整的编写的一个程序之一#xff0c;有兴趣的可尝试编写#xff0c;画面#xff08;动态的#xff09;还可以。 本程序总结有两个版本#xff0c;分别是对C中的继承、多态等一些方面的练习。 编写用的是VS2019#xff0c;e…大家好这是我学完C后完整的编写的一个程序之一有兴趣的可尝试编写画面动态的还可以。 本程序总结有两个版本分别是对C中的继承、多态等一些方面的练习。 编写用的是VS2019easyx。 首先来写第一个版本也是最基础的版本后续的都是在这个上进行一些细节的优化。有更好想法的小伙伴欢迎来一起讨论。 #includeiostream #includegraphics.h #includetime.h #includecoino.h #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 840 using namespace std; //创建一个星星类管理数据 class star {public:star(){}void Init();void move();~star(){} private:double m_x0;int m_y;int m_color;double m_step; }; void star::Init() //对星星的初始化 {if (m_x 0){m_x rand() % SCREEN_WIDTH;}else{m_x 0;}m_y rand() % SCREEN_HEIGHT;m_step (rand() % 5000) / 1000.0 1;m_color (int)(m_step * 255 / 6.0 0.5);m_color RGB(m_color, m_color, m_color);} void star::move() //星星的移动 {putpixel((int)m_x, m_y, 0);m_x m_step;if (m_x SCREEN_WIDTH){this-Init(); \}putpixel((int)m_x, m_y, m_color); }int main() {srand((unsigned)time(NULL));initgraph(SCREEN_WIDTH, SCREEN_HEIGHT);star star[MAXSTAR];for (int i 0; i MAXSTAR; i){star[i].Init();}while (!_kbhit()){for (int i 0; i MAXSTAR; i){star[i].move();}Sleep(30);}closegraph();return 0;} 有编译环境的可以上机跑一下代码不是很难。 接下来这个版本是升级版对一些代码进行了优化从上述代码中不难看出对星星的“画”、“檫”、“新的位置”这三个用得较多不如将这三个单独用个函数写出后面直接调用即可。 代码优化如下 #includeiostream #includegraphics.h #includewindows.h #includetime.h #includeconio.h #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 840 #define MAXSTAR 400 using namespace std; class Star { public:Star() {}~Star() {}void Init();void Move();public:void Draw();void NewPos();void Remove();double m_x 0;int m_y;double m_step;int m_color;}; class RectStar : public Star { public:RectStar() {}~RectStar() {}void Move(){Remove();NewPos();Draw();}protected:void Draw();void Remove(); }; void Star::Init() {if (m_x 0){m_x rand() % SCREEN_WIDTH;}else{m_x 0;}m_y rand() % SCREEN_HEIGHT;m_step (rand() % 5000) / 1000.0 1;m_color (int)(m_step * 255 / 6.0 0.5); // 速度越快颜色越亮m_color RGB(m_color, m_color, m_color);}void Star::Move() {Remove();NewPos();Draw();}/*void Star::Draw() {putpixel((int)m_x, m_y, m_color); }*/void Star::NewPos() {m_x m_step;if (m_x SCREEN_WIDTH)this-Init(); } void Star::Draw() {putpixel((int)m_x, m_y, m_color);setcolor(m_color);circle(m_x, m_y, 1); }void Star::Remove() {putpixel((int)m_x, m_y, 0);setcolor(0);circle(m_x, m_y, 1); } /*void Star::Remove() {putpixel((int)m_x, m_y, 0); }*/ int main() {srand((unsigned)time(NULL));initgraph(SCREEN_WIDTH, SCREEN_HEIGHT);Star star[MAXSTAR];RectStar rstar[MAXSTAR];for (int i 0; i MAXSTAR; i){star[i].Init();rstar[i].Init();}while (!_kbhit()){for (int i 0; i MAXSTAR; i){star[i].Move();rstar[i].Move();}Sleep(50);}closegraph();return 0;} 是不是在运行后觉得一两种星的形状太枯燥了接下来简单的用多态来实现不同的星星的形状 代码如下 #includeiostream #includegraphics.h #includetime.h #includeconio.h #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 840 #define MAXSTAR 400 using namespace std; class StarType { public:virtual void Draw(int x, int y, int color) 0;virtual void Remove(int x, int y) 0; }; class PointStar:public StarType {void Draw(int x, int y, int color){putpixel((int)x, y, color);setcolor(color);circle(x, y, 1);}void Remove(int x, int y){putpixel((int)x, y,0);setcolor(0);circle(x, y, 1);}}; class RecStar :public StarType {void Draw(int x, int y, int color){putpixel(x, y, color);setcolor(color);rectangle(x - 1,y - 1, x 1, y 1);}void Remove(int x, int y){putpixel(x, y, 0);setcolor(0);rectangle(x - 1, y - 1, x 1, y 1);} }; class XStar :public StarType {void Draw(int x, int y, int color){setcolor(color);outtextxy(x, y, _T(x));}void Remove(int x, int y){settextcolor(0);outtextxy(x, y, _T(x));} };class Star { public:Star(){}~Star() {}void Init();void Move();void Init(StarType* pStarType); public:void NewPos();double m_x;double m_y;int m_color;double m_step;StarType* m_pStarType; }; void Star::Init() {if (m_x 0){m_x rand() % SCREEN_WIDTH;}else{m_x 0;}m_y rand() % SCREEN_HEIGHT;m_step (rand() % 5000) / 1000.0 1;m_color (int)(m_step* 255 / 6.0 1);m_color RGB(m_color, m_color, m_color);} void Star::Init(StarType* pStarType) {this-Init();m_pStarType pStarType; } void Star::Move() {m_pStarType-Remove(m_x,m_y);NewPos();m_pStarType-Draw(m_x, m_y, m_color);} void Star::NewPos() {m_x m_step;if (m_x SCREEN_WIDTH){this-Init();}} void main() {srand((unsigned)time(NULL));initgraph(SCREEN_WIDTH, SCREEN_WIDTH);Star star[MAXSTAR];PointStar pointstar;XStar xstar;RecStar restar;for (int i 0; i MAXSTAR; i){switch (i % 3){case 0:star[i].Init(pointstar);break;case 1:star[i].Init(pointstar);break;case 2:star[i].Init(pointstar);break;default:break;}}while (!kbhit){for (int i 0; i MAXSTAR; i){star[i].Move();}Sleep(50);}closegraph();} 以上就是本次本人对对绘制星图的就简单理解。欢迎有志于学好C的伙伴来分享C学习心得和友好地评论。如是有问题看到了有时间的话会及时回复。感谢各位的观看。
http://wiki.neutronadmin.com/news/419342/

相关文章:

  • 唐山建设网站公司wordpress添加端口访问不了
  • 国外网站建设公司婚介做网站的好处
  • 新开传奇网站刚开wordpress 开发版 视频
  • 建网站的尺寸手机版app制作软件
  • 免费可商用网站社交网站建设网站
  • 专门做酒的网站有哪些网站文章更新怎么做
  • 网站制作多少页网站备案需先做网站吗
  • 鹰潭网站建设建站推广文案
  • 做网站怎么选空间工业和信息化部产业发展促进中心
  • 深圳市专业做网站北京建网站价格
  • 国外公司网站模板flashfxp 网站
  • 杭州网站建设兼职网站开发哪个公司好
  • 宁波市有哪些网站建设公司社交网站建设技术
  • 建筑效果图网站推荐给一个网站
  • 移动 网站模板深圳建站公司专业公司
  • 青岛响应式网站设计简洁网站模板素材
  • 漳浦县建设局网站window2008r2网站建设
  • 用python写一个简单的网站电商思维做招聘网站
  • 丽水网站制作公司wordpress 开发视频
  • 网站建设 面试问题上海网站快速排名
  • 广州制作网站哪家专业网站 测速度
  • 建网站的公司公司外贸拓客软件有用吗
  • 前台网站系统源码有什么网站做头像
  • 浙江省国有建设用地使用权建议网站php的网站数据库如何上传
  • 网站免费云主机杭州室内设计设计公司前十排名
  • 模板网站与定制开发网站的区别推广网站
  • 无锡建网站电话wordpress建站wifi
  • 手机建站图片建设网站如入什么费
  • 广西住房城乡和建设厅网站首页后端低代码平台
  • 网站充值怎么做的7x7x7x7x8黄全场免费