第七组 图形时钟 源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第七组图形时钟
源代码
#include <graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<time.h>
#define pi 3.1415926
#define midx 320
#define midy 240
#define CLICK 100
#define CLICKDELAY 30
void main()
{
//函数声明
void draw(int hour,int min,int sec);
void Click();
void Highclick();
void Naoling();
int gdriver, gmode,h,m;
start:gdriver=DETECT;
gmode=0;
initgraph(&gdriver, &gmode, ""); //初始化图形模式setbkcolor(WHITE); //设置背景颜色cleardevice();
while(!kbhit())
{
setfillcolor(LIGHTGRAY); //给表盘添颜色
setcolor(BLACK);
fillcircle(320,240,215); //画实心圆盘
fillcircle(320,240,170);
setfillcolor(YELLOW);
fillcircle(320,240,4);
setcolor(YELLOW); //给刻度添颜色line(120,240,150,240); //9
line(320,40,320,70); //12
line(520,240,490,240); //3
line(320,440,320,410); //6
line(410,395.7,400,378.4); //5
line(475.7,330,458.4,320); //4
line(475.7,150,458.4,160); //2
line(410,84.3,400,101.6); //1
line(230,84.3,240,101.6); //11
line(164.3,150,181.6,160); //10 line(164.3,330,181.6,320); //8 line(230,395.7,240,378.4); //7 setcolor(RED);
//给表盘添数字
outtextxy(319.9,36,"12"); outtextxy(118,238,"9"); outtextxy(519,238,"3"); outtextxy(320,435,"6"); outtextxy(418,411,"5"); outtextxy(490,337,"4"); outtextxy(493.2,139.9,"2"); outtextxy(419.9,66.8,"1"); outtextxy(215,63,"11"); outtextxy(143,136,"10"); outtextxy(146.8,340,"8"); outtextxy(220,413.2,"7");
//获取系统时间
time_t temp;
struct tm *p;
time(&temp);
p=localtime(&temp);
draw( p->tm_hour,p->tm_min,p->tm_sec); //调用画指针函数
if(p->tm_min==0&&p->tm_sec==0) //整点报时
Highclick();
else
Click();
if(p->tm_hour==h&&p->tm_min==m) //闹钟
Naoling();
Sleep(830);
if(p->tm_hour==h&&p->tm_min==m)
Naoling();
cleardevice(); //清屏
}
closegraph(); //关闭模拟时钟界面,进入设定闹钟功能选择界面
char p;
start1:system("cls");
printf("是否设定闹钟:(y/n/s)?");
p=getch(); //获得指令
if(p=='y') //执行指令
{
system("cls"); //清屏
printf("请输入闹铃时间\n");
printf("小时:");
scanf("%d",&h);
system("cls");
printf("%02d:",h);
printf("\n分钟:");
scanf("%d",&m);
system("cls");
printf("闹铃时间:\n");
printf("%02d:%02d\n",h,m);
getch();
goto start; //返回模拟时钟界面}
else if(p=='n')
goto start;
else if(p=='s') //闹钟的延时
{
m=m+5; //延时五分钟
goto start;
}
else
{
system("cls");
goto start1;
}
}
void draw(int hour,int min,int sec)//定义画指针函数
{
float endx,endy;
float a_sec,a_min,a_hour;
//根据获取时间计算对应指针角度
a_sec=(sec)*2*pi/60;
a_min=(min)*2*pi/60+a_sec/60;
a_hour=(hour)*2*pi/12+a_min/12;
//计算末端坐标
endx=midx+100*sin(a_hour);
endy=midy-100*cos(a_hour);
setcolor(BLUE); //给时针添颜色
line(midx,midy,endx,endy);//利用line()函数画指针endx=midx+170*sin(a_min);
endy=midy-170*cos(a_min);
setcolor(RED);
line(midx,midy,endx,endy);
endx=midx+180*sin(a_sec);
endy=midy-180*cos(a_sec);
setcolor(WHITE);
line(midx,midy,endx,endy);
}
void Click() //定义控制指针转动的滴答声函数{
Beep (700,100);
Sleep(CLICKDELAY);
}
void Highclick() //定义整点报时的声音控制函数{
Beep(1000,200);
Sleep(CLICKDELAY);
}
void Naoling() //定义闹钟的声音控制函数{
Beep(2000,200);
}。

相关文档
最新文档