概述
//需要安装easyX
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <time.h>
#define MAXSTAR 30
#define WINDOW_LEFT 200
#define WINDOW_TOP 100
#define WINDOW_RIGHT 500
#define WINDOW_BUTTON 300
typedef struct
{
double x,y;
double step;
int color;
}STAR;
void Init()
{
srand(time(0));
initgraph(1000,500);
}
void SetStar(STAR &star)
{
star.x=rand()%(WINDOW_RIGHT - WINDOW_LEFT) + WINDOW_LEFT + 10;
star.y=rand()%(WINDOW_BUTTON - WINDOW_TOP) + WINDOW_TOP + 10;
if(star.x >= WINDOW_RIGHT-10) star.x=WINDOW_LEFT + 10;
if(star.y >= WINDOW_BUTTON-10) star.y=WINDOW_TOP + 10;
star.step=(rand()%3000)/1000+1;
star.color=(int)(star.step*255/5.0 + 0.5);
star.color=RGB(star.color,star.color,star.color);
}
void MoveStar(STAR &star)
{
putpixel((int)star.x,(int)star.y,0);
star.x=star.x + star.step;
star.y=star.y + star.step;
if(star.x>=WINDOW_RIGHT-10 || star.y>=WINDOW_BUTTON-10) SetStar(star);
putpixel((int)star.x,(int)star.y,star.color);
}
void Window()
{
setlinecolor(RGB(103,60,20)); //设置线条颜色为棕色
setlinestyle(PS_SOLID | PS_JOIN_MITER,10); //设置线条属性:实线,连接处为斜面,线的宽度为10
rectangle(WINDOW_LEFT,WINDOW_TOP,WINDOW_RIGHT,WINDOW_BUTTON); //设置窗户大小
// 200 100 500 300
}
void Meter(STAR star[]) //流星雨
{
for(int j=0;j<MAXSTAR;j++)
MoveStar(star[j]);
Sleep(8);
}
void ComputerandTable()
{
setlinecolor(RGB(131,131,131));
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE , 5);
line(700,200,850,200); //电脑上屏幕
line(700,300,850,300); //电脑下屏幕
line(700,200,700,300); //电脑左屏幕
line(850,200,850,300); //电脑右屏幕
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE , 20);
line(777,310,777,315); //电脑支架
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE , 5);
line(695,323,855,323); //电脑键盘
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE , 4);
line(875,195,875,324); //电脑主机左线条
line(875,195,940,195); //电脑主机上线条
line(940,195,940,324); //电脑主机右线条
line(875,324,940,324); //电脑主机下线条
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE , 8);
line(885,220,930,220); //磁盘插口
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE , 3);
line(890,250,925,250);
setlinecolor(RGB(103,60,20)); //设置线条颜色为棕色
setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE,12);
line(650,332,980,332); //桌板
line(660,332,660,420); //左桌脚
line(970,332,970,420); //右桌脚
}
void Home()
{
//画房子
setlinestyle(PS_SOLID,1);
line(150,0,0,100);
line(150,0,150,400);
line(0,500,150,400);
line(150,400,1000,400);
//画门
line(10,350,80,304);
line(10,350,10,492);
line(80,304,80,446);
circle(70,400,2); //把手
circle(750,70,40); //时钟
circle(750,70,1); //中心
line(750,70,780,70);
line(750,70,750,32);
}
void ShowChars()
{
int x,y;
char c;
settextstyle(3,3,_T("Courier"));
setlinecolor(BLACK);
settextcolor(GREEN);
/*for(int i=709;i<=842;i++)*/
for(int i=209;i<=292;i++)
{
x=(rand()%137) + 700 + 3;
y=(rand()%82) + 200 + 3;
c=(rand()%2)+'0';
outtextxy(x,y,c);
//line(i,209,i,292);
line(709,i,842,i);
Sleep(0);
}
}
int main()
{
Init();
Home();
Window();
ComputerandTable();
STAR star[MAXSTAR];
for(int i=0;i<MAXSTAR;i++)
SetStar(star[i]);
while(!kbhit())
{
Meter(star);
ShowChars();
}
getch();
closegraph();
return 0;
}
最后
以上就是忧心云朵为你收集整理的C++ easyX画室内图的全部内容,希望文章能够帮你解决C++ easyX画室内图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复