题目是要求用纯C程编一个于电脑时间同步走的,显示3根走动的针,外面要有一个表盘的钟。(最好下面还带数字显示几点的)。还要求每走一格秒针表盘不会闪烁。这种题比较麻烦,还请各位高手帮帮忙,做一个看看。谢谢了先!
void InitGra(void); void SysTime(int x, int y, int r); int Clock(int x, int y, int r); void ClockPict(int x, int y, int r);
int main(void) { int x, y, r; /* 定义表盘的中心及半径 */ x = 310; y = 240; r = 42; InitGra(); SysTime(x, y, r); closegraph(); return(0); }
void InitGra(void) { int GraphDrive = DETECT, GraphMode; registerbgidriver(EGAVGA_driver); initgraph(&GraphDrive, &GraphMode, ""); }
void SysTime(int x, int y, int r) /* 表盘中心坐标, 半径 */ { ClockPict(x, y, r); while ((Clock(x, y, r) != 1) && (! kbhit())); /* 钟表运行直到按键为止 */ }
int Clock(int x, int y, int r) /* 表盘中心, 表盘半径 */ { float hr, mt, sd, dh, dm, ds, ds0; int i, Fst = 1; union REGS in, out; setcolor(0); setfillstyle(1, 0); pieslice(x, y, 0, 360, r-11); in.h.ah = 0x2c; int86(0x21, &in, &out); hr = out.h.ch; /* 时 */ mt = out.h.cl; /* 分 */ sd = out.h.dh; /* 秒 */ if (hr > 12) hr = hr-12; hr = hr+mt/60; dh = 270+30*hr;if (dh > 360) dh = dh-360; dh = dh*BB; dm = 270+6*mt; if (dm > 360) dm = dm-360; dm = dm*BB; ds = 270+6*sd; if (ds > 360) ds = ds-360; ds = ds*BB; setcolor(15); setlinestyle(0, 0, 3); line(x, y, x+(r-20)*cos(dh), y+(r-20)*sin(dh)); /* 画时针 */ setlinestyle(0,0,1); line(x, y, x+(r-15)*cos(dm), y+(r-15)*sin(dm)); /* 画分针 */ setwritemode(XOR_PUT); for (i = 0; i < 300; i++) { in.h.ah = 0x2c; /* 循环内执行秒针的走动 */ int86(0x21, &in, &out); sd = out.h.dh; ds = 270+6*sd; if (ds > 360) ds = ds-360; ds = ds*BB; if (Fst) ds0 = ds; setlinestyle(0, 0, 1); setcolor(12); if (!Fst) line(x,y,x+(r-12)*cos(ds0),y+(r-12)*sin(ds0)); /* 擦去原秒针*/ line(x, y, x+(r-12)*cos(ds), y+(r-12)*sin(ds)); /* 重画秒针 */ ds0 = ds; Fst = 0; if (kbhit()) return (1); /* 如果有按键, 返回 */ else delay(100); } }
void ClockPict(int x, int y, int r) /* 画表盘 */ { float af; int i, Dlt; setwritemode(COPY_PUT); setlinestyle(0,0,1); setcolor(0); setfillstyle(1,0); pieslice(x, y, 0, 360, r+2); setcolor(14); circle(x, y, r); line(x+r+5, y-2, x+r+10, y-2); line(x+r+5, y+2, x+r+10, y+2); setlinestyle(0,0,3); rectangle(x+r+5, y-6, x+r+10, y+6); circle(x, y, r+5); for (i = 0; i < 360; i += 30) /* 画表的时刻刻度 */ { af = i*BB; if (i==0 || i==90 || i==180 || i==270) Dlt = 8; /* 3,6,9,12点刻度稍长*/ else Dlt = 5; line(x+(r-Dlt)*cos(af), y+(r-Dlt)*sin(af), x+r*cos(af), y+r*sin(af)); } }
getch();
[此贴子已经被作者于2004-11-09 22:27:12编辑过]