这是最近老师留的作业,反正闲来无事,多花了点时间自己用easy_x的绘图函数写出的,代码如下。(=_=!其实图像的话我直接可以用图片来着)。(o(TヘTo)以后一定要三思而后行啊)
这是运行效果
#undef UNICODE
#include
#include
#include
#define PI 3.14159
void showsun()
{
int i,d,r,l;
int px,py;
int x,y;
int xp,yp,xpe,ype;
r = 30;
d = 20;
l = 20;
px = (r+d+l+20)*2;
py = (r+d+l+20)*2;
x = px/2;
y = py/2;
setcolor(RED);
setfillcolor(RED);
fillcircle(x,y,r);
xp = x;
xpe = x;
yp = y - d;
ype = y - d - l;
for(i = 0;i<12;i++)
{
xp = x + int(cos(PI*2*i/12)*(r+d*1.0));
yp = y + int(sin(PI*2*i/12)*(r+d*1.0));
xpe = x + int(cos(PI*2*i/12)*(r+d*1.0+l));
ype = y + int(sin(PI*2*i/12)*(r+d*1.0+l));
setlinestyle(PS_SOLID,5);
setcolor(RED);
line(xp,yp,xpe,ype);
}
}
void showmoon( )
{
int x,y;
int r,R;
int rx,ry;
int rs;
int px,py;
int sl,st,sr,sb;
int slx,sly,srx,sry,stx,sty,sbx,sby;
r = 50;
R = 50;
rs = r/3;
x = 90;
y = 90;
rx = x+20;
ry = y;
sl = x+r;
st = y - r/3;
sr = sl + 2*r/3;
sb = y + r/3;
slx = sl;
sly = st;
srx = sr;
sry = sb;
stx = sr;
sty = st;
sbx = sl;
sby = sb;
setcolor(YELLOW);
setfillcolor(YELLOW);
fillcircle(x,y,r);
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(rx,ry,R);
setcolor(YELLOW);
setfillcolor(YELLOW);
setcolor(YELLOW);
setfillcolor(YELLOW);
fillrectangle(sl,st,sr,sb);
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(slx,sly,rs);
fillcircle(srx,sry,rs);
fillcircle(stx,sty,rs);
fillcircle(sbx,sby,rs);
}
void cleardaynight(int px,int py)
{
setcolor(BLACK);
setfillcolor(BLACK);
fillrectangle(0,0,px,py);
}
void showpm()
{
settextcolor(WHITE);
int x,y;
x = 50;
y = 190;
outtextxy(x,y,"PM");
}
void showam()
{
settextcolor(WHITE);
int x,y;
x = 50;
y = 190;
outtextxy(x,y,"AM");
}
void showmotto()
{
setcolor(GREEN);
int x,y;
x = 700/2-65;
y = 480/2+130;
outtextxy(x,y,"GOOD GOOD STUDY");
x = x +24;
y = y+20;
outtextxy(x,y,"DAY DAY UP");
}
void clearampm()
{
setcolor(BLACK);
setfillcolor(BLACK);
int l,r,t,b;
l = 50;
r = 90;
t = 190;
b = 240;
bar(l,t,r,b);
}
int main()
{
int W = 700,H = 480;
int x,y;
int clearx,cleary;
int i;
int xc,yc;
int hx,hy,hl,mx,my,ml,sx,sy,sl;
double ha,ma,sa;
initgraph(W,H);
SYSTEMTIME ti;
x = W/2;
y = H/2;
sl = 95;
ml = 80;
hl = 70;
clearx = 180;
cleary = 180;
showmotto();
setlinestyle(PS_SOLID,1);
setcolor(GREEN);
circle(x,y,115);
showmoon();
setcolor(WHITE);
setfillcolor(WHITE);
for(i = 0;i<60;i++)
{
xc = x + int(105*sin(PI*2*i/60));
yc = y + int(105*cos(PI*2*i/60));
if(i%15 == 0)
bar(xc-3,yc-3,xc+3,yc+3);
else if(i%5 ==0)
circle(xc,yc,2);
else
putpixel(xc,yc,WHITE);
}
BeginBatchDraw();
while(1)
{
setlinestyle(PS_SOLID,1);
setcolor(GREEN);
circle(x,y,45);
GetLocalTime(&ti);
ha = ti.wHour*2*PI/12 + ti.wMinute*2*PI/720;
ma = ti.wMinute*2*PI/60 + ti.wSecond*2*PI/3600;
sa = ti.wSecond*2*PI/60;
if(ti.wHour>=6&&ti.wHour<=21)//可以设置日月的显示
{
cleardaynight(clearx,cleary);
showsun();
}
else
{
cleardaynight(clearx,cleary);
showmoon();
}
if(ti.wHour>=0&&ti.wHour<=12)//设置显示上午下午
{
clearampm();
showam();
}
else
{
clearampm();
showpm();
}
hx = x + int (hl*sin(ha));
hy = y - int (hl*cos(ha));
mx = x + int (ml*sin(ma));
my = y - int (ml*cos(ma));
sx = x + int (sl*sin(sa));
sy = y - int (sl*cos(sa));
setlinestyle(PS_SOLID,6);
setcolor(GREEN);
line(x,y,hx,hy);
setlinestyle(PS_SOLID,4);
setcolor(YELLOW);
line(x,y,mx,my);
setlinestyle(PS_SOLID,2);
setcolor(RED);
line(x,y,sx,sy);
FlushBatchDraw();
Sleep(100);
setcolor(BLACK);
setlinestyle(PS_SOLID,6);
line(x,y,hx,hy);
setlinestyle(PS_SOLID,4);
line(x,y,mx,my);
setlinestyle(PS_SOLID,2);
line(x,y,sx,sy);
}
getch();
closegraph();
return 0;
}