c语言怎么编程个表,关于一个钟表编程,求助!

#include "stdlib.h"

#include "conio.h"

#include "stdio.h"

#include "graphics.h"

#include "math.h"

#include "dos.h"

#define BB 3.14159/180

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();

57bde7fa0788dd1c6176fc9de185299c.gif

[此贴子已经被作者于2004-11-09 22:27:12编辑过]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值