# \"stdlib.h\"
# \"conio.h\"
# \"stdio.h\"
# \"graphics.h\"
# \"math.h\"
# \"dos.h\"
# BB 3.14159/180 void InitGra(void);
void SysTime( x, y, r);
Clock( x, y, r);
void ClockPict( x, y, r);
(void)
{
x, y, r; /* 定义表盘中心及半径 */
x = 310;
y = 240;
r = 42;
InitGra;
SysTime(x, y, r);
closegraph;
(0);
}
void InitGra(void)
{
GraphDrive = DETECT, GraphMode;
registerbgidriver(EGAVGA_driver);
initgraph(&GraphDrive, &GraphMode, \"\");
}
void SysTime( x, y, r) /* 表盘中心坐标, 半径 */
{
ClockPict(x, y, r);
while ((Clock(x, y, r) != 1) && (! kbhit)); /* 钟表运行直到按键为止 */
}
Clock( x, y, r) /* 表盘中心, 表盘半径 */
{
float hr, mt, sd, dh, dm, ds, ds0;
i, Fst = 1;
union REGS in, out;
color(0); fillstyle(1, 0);
pieslice(x, y, 0, 360, r-11);
in.h.ah = 0x2c;
86(0x21, &in, &out);
hr = out.h.ch; /* 时 */
mt = out.h.cl; /* 分 */
sd = out.h.dh; /* 秒 */
(hr > 12) hr = hr-12;
hr = hr+mt/60;
dh = 270+30*hr; (dh > 360) dh = dh-360; dh = dh*BB;
dm = 270+6*mt; (dm > 360) dm = dm-360; dm = dm*BB;
ds = 270+6*sd; (ds > 360) ds = ds-360; ds = ds*BB;
color(15); linestyle(0, 0, 3);
line(x, y, x+(r-20)*cos(dh), y+(r-20)*sin(dh)); /* 画时针 */
linestyle(0,0,1);
line(x, y, x+(r-15)*cos(dm), y+(r-15)*sin(dm)); /* 画分针 */
writemode(XOR_PUT);
for (i = 0; i < 300; i)
{
in.h.ah = 0x2c; /* 循环内执行秒针走动 */
86(0x21, &in, &out);
sd = out.h.dh;
ds = 270+6*sd;
(ds > 360) ds = ds-360;
ds = ds*BB;
(Fst) ds0 = ds;
linestyle(0, 0, 1); color(12);
(!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;
(kbhit) (1); /* 如果有按键, 返回 */
delay(100);
}
}
void ClockPict( x, y, r) /* 画表盘 */
{
float af;
i, Dlt;
writemode(COPY_PUT); linestyle(0,0,1);
color(0); fillstyle(1,0);
pieslice(x, y, 0, 360, r+2);
color(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);
linestyle(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;
(i0 || i90 || i180 || i270) Dlt = 8; /* 3,6,9,12点刻度稍长*/
Dlt = 5;
line(x+(r-Dlt)*cos(af), y+(r-Dlt)*sin(af), x+r*cos(af), y+r*sin(af));
}
}
最新评论