/*开发环境:turbo c 2.0模拟时钟转动程序代码*/
#include"graphics.h"
#include"math.h"
#include"dos.h"
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void init() /*划时钟边框函数*/
{
int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*划钟点上的短线*/
{
if(i%5==0)
l=15;
else
l=5;
x1=200*sin(i*6*pi/180)+300;
y1=200*cos(i*6*pi/180)+240;
x2=(200-l)*sin(i*6*pi/180)+300;
y2=(200-l)*cos(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y,i,k=1;
int gdriver=9,gmode=2;
unsigned char h,m,s;
int o,p,q;
float n;
struct time t[1];
struct date d[1];
initgraph(&gdriver,&gmode,"c:\\tc");
initgraph(&gdriver,&gmode,"c:\\tc");
for(i=0;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i); /*控制输出字符的字体,方向,大小*/
cleardevice();
settextjustify(1,1); /*在指定坐标上输出字符串*/
outtextxy(300,80,"12") ;
outtextxy(300,390,"6");
outtextxy(140,230,"9");
outtextxy(460,230,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(220,370,"7");
outtextxy(160,160,"10");
outtextxy(160,310,"8");
}
init();
setwritemode(1); /*设置画线的输出模式*/
if(k!=0)
{
getdate(d); /*获得系统日期函数*/
o=d[0].da_year;
p=d[0].da_mon;
q=d[0].da_day;
gettime(t); /*获得系统时间函数*/
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
}
setcolor(7); /*设置时针颜色*/
n=(float)h+(float)m/60;
d(150,n,30); /*画出时针*/
setcolor(14); /*设置分针颜色*/
d(170,m,6); /*画出分针*/
setcolor(4); /*设置秒针颜色*/
d(190,s,6); /*画出秒针*/
while(!kbhit()) /*控制程序按下任意键退出*/
{
while(t[0].ti_sec==s)
gettime(t);
gotoxy(44,18); /*使光标移动到指定坐标*/
printf("\b\b\b\b\b\b\b\b\b"); /*退格,使表示时间的字符串不断变化*/
sound(400); /*按给定的频率打开PC扬声器*/
delay(70); /*中断程序的执行,时间为70毫秒*/
sound(200);
delay(30);
nosound(); /*按给定的频率关闭PC扬声器*/
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if(t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if(t[0].ti_hour!=h)
{
setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
if(s<10) /*用字符的形式输出时间*/
{ if(m<10)
printf("%u:0%u:0%u",h,m,s);
else
printf("%u:%u:0%u",h,m,s);
}
else
{ if(m<10)
printf("%u:0%u:%u",h,m,s);
else
printf("%u:%u:%u",h,m,s);
}
gotoxy(34,19); /*在指定坐标上输出日期*/
printf("%d年%d月%d日",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph();
}
/// 两个代码 请用TC编译
#include"graphics.h"
#include"math.h"
#include"dos.h"
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void init() /*划时钟边框函数*/
{
int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*划钟点上的短线*/
{
if(i%5==0)
l=15;
else
l=5;
x1=200*sin(i*6*pi/180)+300;
y1=200*cos(i*6*pi/180)+240;
x2=(200-l)*sin(i*6*pi/180)+300;
y2=(200-l)*cos(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y,i,k=1;
int gdriver=9,gmode=2;
unsigned char h,m,s;
int o,p,q;
float n;
struct time t[1];
struct date d[1];
initgraph(&gdriver,&gmode,"c:\\tc");
initgraph(&gdriver,&gmode,"c:\\tc");
for(i=0;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i); /*控制输出字符的字体,方向,大小*/
cleardevice();
settextjustify(1,1); /*在指定坐标上输出字符串*/
outtextxy(300,80,"12") ;
outtextxy(300,390,"6");
outtextxy(140,230,"9");
outtextxy(460,230,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(220,370,"7");
outtextxy(160,160,"10");
outtextxy(160,310,"8");
}
init();
setwritemode(1); /*设置画线的输出模式*/
if(k!=0)
{
getdate(d); /*获得系统日期函数*/
o=d[0].da_year;
p=d[0].da_mon;
q=d[0].da_day;
gettime(t); /*获得系统时间函数*/
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
}
setcolor(7); /*设置时针颜色*/
n=(float)h+(float)m/60;
d(150,n,30); /*画出时针*/
setcolor(14); /*设置分针颜色*/
d(170,m,6); /*画出分针*/
setcolor(4); /*设置秒针颜色*/
d(190,s,6); /*画出秒针*/
while(!kbhit()) /*控制程序按下任意键退出*/
{
while(t[0].ti_sec==s)
gettime(t);
gotoxy(44,18); /*使光标移动到指定坐标*/
printf("\b\b\b\b\b\b\b\b\b"); /*退格,使表示时间的字符串不断变化*/
sound(400); /*按给定的频率打开PC扬声器*/
delay(70); /*中断程序的执行,时间为70毫秒*/
sound(200);
delay(30);
nosound(); /*按给定的频率关闭PC扬声器*/
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if(t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if(t[0].ti_hour!=h)
{
setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
if(s<10) /*用字符的形式输出时间*/
{ if(m<10)
printf("%u:0%u:0%u",h,m,s);
else
printf("%u:%u:0%u",h,m,s);
}
else
{ if(m<10)
printf("%u:0%u:%u",h,m,s);
else
printf("%u:%u:%u",h,m,s);
}
gotoxy(34,19); /*在指定坐标上输出日期*/
printf("%d年%d月%d日",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph();
}
/////另一个
#include
#include
#include
#define CENTERX 320
#define CENTERY 175
#define CLICK 100
#define CLICKDELAY 30
#define HEBEEP 10000
#define LOWBEEP 500
#define BEEPDELAY 200
int Mrk_1[8]={-5,-160,5,-160,5,-130,-5,-130, };
int Mrk_2[8]={-5,-160,5,-160,2,-130,-2-130, };
int HourHand[8]={-3,-100,3,-120,4, 10,-4,10};
int MiHand[8]={-3,-120,3,-120,4, 10,-4,10};
int SecHand[8]={-2,-150,2,-150,3, 10,-3,10};
void Click()
{
sound(CLICK);
delay(CLICKDELAY);
nosound();
}
void HighBeep()
{
sound(HEBEEP);
delay(BEEPDELAY);
nosound;
}
void LowBeep()
{
sound(LOWBEEP);
}
void DrawPoly(int *data,int angle,int color)
{
int usedata[8];
float sinang,cosang;
int i;
sinang=sin((float)angle/180*3.14);
cosang=cos((float)angle/180*3.14);
for(i=0;i<8;i+=2)
{
usedata[i] =CENTERX+ cosang*data[i]-sinang*data[i+1]+.5;
usedata[i+1]=CENTERY+sinang*data[i]+cosang*data[i+1]+.5;
}
setfillstyle(SOLID_FILL,color);
fillpoly(4,usedata);
}
void DrawClock(struct time *cutime)
{
int ang;
float hourrate,minrate,secrate;
setbkcolor(BLUE);
cleardevice();
setcolor(WHITE);
for(ang=0;ang<360;ang+=90)
{
DrawPoly(Mrk_1,ang,WHITE);
DrawPoly(Mrk_2,ang+30,WHITE);
DrawPoly(Mrk_2,ang+60,WHITE);
}
secrate=(float)cutime->ti_sec/60;
minrate=((float)cutime->ti_min+secrate)/60;
hourrate=(((float)cutime->ti_hour/12)+minrate)/12;
ang=hourrate*360;
DrawPoly(HourHand,ang,YELLOW);/*画时针*/
ang=minrate*360;
DrawPoly(MiHand,ang, GREEN);/*画分针*/
ang=secrate*360;
DrawPoly(SecHand,ang, RED);/*画秒针*/
}
main()
{
int gdriver=EGA,
gmode=EGAHI;
int curpage;
struct time curtime ,newtime ;
initgraph(&gdriver,&gmode,"c:\\tc");
setbkcolor(BLUE);
cleardevice();
gettime(&curtime);
curpage=0;
DrawClock(&curtime);
while(1)
{
if(kbhit())
break;
gettime(&newtime);
if(newtime.ti_sec!=curtime.ti_sec)
{
if(curpage==0)
curpage=1;
else
curpage=0;
curtime=newtime;
setactivepage(curpage);
DrawClock(&curtime);
setvisualpage(curpage);
if(newtime.ti_min==0&&newtime.ti_sec==0)
HighBeep();
else if(newtime.ti_min==59&&
newtime.ti_sec<=59)
LowBeep();
else
Click();
}
}
closegraph();
}
/*开发环境:turbo
c
2.0模拟时钟转动程序代码*/
#include"graphics.h"
#include"math.h"
#include"dos.h"
#define
pi
3.1415926
#define
X(a,b,c)
x=a*cos(b*c*pi/180-pi/2)+300
#define
Y(a,b,c)
y=a*sin(b*c*pi/180-pi/2)+240
#define
d(a,b,c)
X(a,b,c);Y(a,b,c);line(300,240,x,y)
void
init()
/*划时钟边框函数*/
{
int
i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++)
/*划钟点上的短线*/
{
if(i%5==0)
l=15;
else
l=5;
x1=200*sin(i*6*pi/180)+300;
y1=200*cos(i*6*pi/180)+240;
x2=(200-l)*sin(i*6*pi/180)+300;
y2=(200-l)*cos(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int
x,y,i,k=1;
int
gdriver=9,gmode=2;
unsigned
char
h,m,s;
int
o,p,q;
float
n;
struct
time
t[1];
struct
date
d[1];
initgraph(&gdriver,&gmode,"c:\\tc");
initgraph(&gdriver,&gmode,"c:\\tc");
for(i=0;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i);
/*控制输出字符的字体,方向,大小*/
cleardevice();
settextjustify(1,1);
/*在指定坐标上输出字符串*/
outtextxy(300,80,"12")
;
outtextxy(300,390,"6");
outtextxy(140,230,"9");
outtextxy(460,230,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(220,370,"7");
outtextxy(160,160,"10");
outtextxy(160,310,"8");
}
init();
setwritemode(1);
/*设置画线的输出模式*/
if(k!=0)
{
getdate(d);
/*获得系统日期函数*/
o=d[0].da_year;
p=d[0].da_mon;
q=d[0].da_day;
gettime(t);
/*获得系统时间函数*/
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
}
setcolor(7);
/*设置时针颜色*/
n=(float)h+(float)m/60;
d(150,n,30);
/*画出时针*/
setcolor(14);
/*设置分针颜色*/
d(170,m,6);
/*画出分针*/
setcolor(4);
/*设置秒针颜色*/
d(190,s,6);
/*画出秒针*/
while(!kbhit())
/*控制程序按下任意键退出*/
{
while(t[0].ti_sec==s)
gettime(t);
gotoxy(44,18);
/*使光标移动到指定坐标*/
printf("\b\b\b\b\b\b\b\b\b");
/*退格,使表示时间的字符串不断变化*/
sound(400);
/*按给定的频率打开PC扬声器*/
delay(70);
/*中断程序的执行,时间为70毫秒*/
sound(200);
delay(30);
nosound();
/*按给定的频率关闭PC扬声器*/
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if(t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if(t[0].ti_hour!=h)
{
setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
if(s<10)
/*用字符的形式输出时间*/
{
if(m<10)
printf("%u:0%u:0%u",h,m,s);
else
printf("%u:%u:0%u",h,m,s);
}
else
{
if(m<10)
printf("%u:0%u:%u",h,m,s);
else
printf("%u:%u:%u",h,m,s);
}
gotoxy(34,19);
/*在指定坐标上输出日期*/
printf("%d年%d月%d日",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph();
}