📄 11.c
字号:
#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 /*difine定义符号常量*/
#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)
#define xx(a,b,c) x=a*cos(b*c*pi/180-pi/2)+100 /**/
#define yy(a,b,c) y=a*sin(b*c*pi/180-pi/2)+70 /**/
#define dd(a,b,c) xx(a,b,c);yy(a,b,c);line(100,70,x,y) /**/
#define xxx(a,b,c) x=a*cos(b*c*pi/180-pi/2)+500 /**/
#define yyy(a,b,c) y=a*sin(b*c*pi/180-pi/2)+70 /**/
#define ddd(a,b,c) xxx(a,b,c);yyy(a,b,c);line(500,70,x,y) /**/
void init() /*划时钟边框函数*/
{
int i,l,x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
setbkcolor(16); /*背景颜色黑色*/
circle(300,240,185);
setcolor(12); /*左右圆圈颜色青色*/
circle(300,240,190);
circle(300,240,5);
setcolor(10);
circle(100,70,70);
circle(100,70,0.5);
circle(500,70,70);
circle(500,70,0.5);
ellipse(208,440,0,360,23,40); /*左 外面的椭圆*/
ellipse(390,440,0,360,23,40); /*右 外面的椭圆*/
setcolor(15);
line(215,410,200,450);
line(380,410,400,450); /*时钟的脚*/
ellipse(215,165,0,360,23,50); /*左 外面的椭圆*/
ellipse(385,165,0,360,23,50); /*右 外面的椭圆*/
ellipse(215,165,0,180,23,23); /*左 里面的椭圆*/
ellipse(385,165,0,180,23,23); /*右 里面的椭圆*/
for(i=0;i<60;i++) /*划钟点上的短线*/
{
if(i%5==0)
l=15;
else
l=5;
x1=185*sin(i*6*pi/180)+300;
y1=185*cos(i*6*pi/180)+240;
x2=(185-l)*sin(i*6*pi/180)+300;
y2=(185-l)*cos(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
for(i=0;i<60;i++) /*划左钟点上的短线*/
{
if(i%5==0)
l=10;
else
l=5; /*左表盘上短线长度*/
x3=70*sin(i*6*pi/180)+100;
y3=70*cos(i*6*pi/180)+70;
x4=(70-l)*sin(i*6*pi/180)+100;
y4=(70-l)*cos(i*6*pi/180)+70;
line(x3,y3,x4,y4);
}
for(i=0;i<60;i++) /*划右钟点上的短线*/
{
if(i%5==0)
l=10;
else
l=5; /*右表盘上短线长度*/
x5=70*sin(i*6*pi/180)+500;
y5=70*cos(i*6*pi/180)+70;
x6=(70-l)*sin(i*6*pi/180)+500;
y6=(70-l)*cos(i*6*pi/180)+70;
line(x5,y5,x6,y6);
}
}
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,120,"wang wei") ;
outtextxy(300,80,"12");
outtextxy(300,400,"6");
outtextxy(140,240,"9");
outtextxy(460,240,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(440,320,"4");
outtextxy(380,380,"5");
outtextxy(220,380,"7");
outtextxy(160,160,"10");
outtextxy(160,320,"8");
outtextxy(100,70,"miao biao");
outtextxy(505,70,"fen zhong");
getch();
}
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(140,n,30); /*画出时针*/
setcolor(14); /*设置分针颜色*/
d(155,m,6); /*画出分针*/
ddd(50,m,6); /**/
setcolor(4); /*设置秒针颜色*/
d(160,s,6); /*画出秒针*/
dd(50,s,6); /**/
while(!kbhit()) /*控制程序按下任意键退出*/
{
while(t[0].ti_sec==s)
gettime(t);
gotoxy(44,21); /*使光标移动到指定坐标*/
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(160,s,6);
dd(50,s,6); /**/
setcolor(16); /* 左 外面的椭圆的颜色*/
ellipse(215,165,0,360,23,50); /*左 外面的椭圆*/
ellipse(385,165,0,360,23,50); /*右 外面的椭圆*/
setcolor(4); /**/
s=t[0].ti_sec;
d(160,s,6);
dd(50,s,6); /**/
if(s%2==0){
setcolor(15); /*左 外面的椭圆的颜色*/
ellipse(215,165,0,360,23,50); /*左 外面的椭圆*/
ellipse(385,165,0,360,23,50);} /*右 外面的椭圆*/
/**/
if(t[0].ti_min!=m)
if(t[0].ti_min!=m)
{
setcolor(14);
d(155,m,6);
ddd(50,m,6); /**/
m=t[0].ti_min;
d(155,m,6);
ddd(50,m,6); /**/
}
if(t[0].ti_hour!=h)
{
setcolor(7);
d(140,h,30);
h=t[0].ti_hour;
d(140,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,22); /*在指定坐标上输出日期*/
printf(" %d-%d-%d",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph(); /*关闭图形模式*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -