用C++制作钟表的源程序代码

时间:2022-07-14 08:19:13 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。


#include "timer.h"

void draw();

int second,minute,hour; struct tm *temp; time_t t;

char time_buff[10]; void main() {

initgraph(WIDTH,HEIGHT); while (1) {

time(&t);

temp = localtime(&t); second = temp->tm_sec; minute = temp->tm_min; hour = temp->tm_hour; draw();

Sleep(1000); cleardevice(); }

getch();

closegraph(); }

void draw() {

char *p[]={"12","1","2","3","4","5","6","7","8","9","10","11"}; setbkcolor(LIGHTBLUE);

setlinestyle(PS_SOLID,NULL,3);

setfillstyle(RGB(249,157,247)); fillellipse(RX,RY,R+40,R+40); setcolor(DARKGRAY);

setfillstyle(RGB(133,122,125)); fillellipse(RX,RY,R,R); setcolor(BLUE); line(RX,RY,

sin(second *PI/30)*R*0.7+RX, -cos(second *PI/30)*R*0.7+RY);








for (int i = 0; i < 60; i++ ) {

int x = sin(i*PI/30) * R ; int y =-cos(i*PI/30) * R ; if (i % 5 != 0) {

setcolor(LIGHTRED);

line(x* 0.9 +RX,y*0.9+RY,x +RX,y+RY); } else {

setcolor(LIGHTGRAY);

line(x* 0.85 +RX,y*0.85+RY,x +RX,y+RY); outtextxy(x* 0.8 +RX-8,y*0.8+RY-8,p[i/5]); } }

setcolor(BLUE); line(RX,RY,

sin(minute *PI/30)*R*0.6+RX, -cos(minute *PI/30)*R*0.6+RY); setcolor(BLUE); line(RX,RY,

sin(hour*PI/6)*R*0.4+RX, -cos(hour *PI/6)*R*0.4+RY);

sprintf(time_buff,"%2d:%02d:%02d",hour,minute,second);

outtextxy(370,370,time_buff);

outtextxy(350,350,"MADE IN CHINA"); }






本文来源:https://www.wddqw.com/doc/099fbc76a417866fb84a8eb3.html