当前位置:首页 » 编程语言 » c语言图形时钟

c语言图形时钟

发布时间: 2022-05-31 02:03:34

1. 图形时钟用c语言怎么编

#include<graphics.h>
#include<conio.h>
#include<math.h>

voidDraw(inthour,intminute,intsecond)
{
doublea_hour,a_min,a_sec;//时、分、秒针的弧度值
intx_hour,y_hour,x_min,y_min,x_sec,y_sec;//时、分、秒针的末端位置
intx_hour1,y_hour1,x_min1,y_min1,x_sec1,y_sec1;
//计算时、分、秒针的弧度值
a_sec=second*2*PI/60;
a_min=minute*2*PI/60;
a_hour=hour*2*PI/12+a_min/12;;

//计算时、分、秒针的首末端位置
x_sec=320+(int)(120*sin(a_sec));
y_sec=240-(int)(120*cos(a_sec));
x_min=320+(int)(100*sin(a_min));
y_min=240-(int)(100*cos(a_min));
x_hour=320+(int)(70*sin(a_hour));
y_hour=240-(int)(70*cos(a_hour));
x_sec1=320-(int)(15*sin(a_sec));
y_sec1=240+(int)(15*cos(a_sec));
x_min1=320-(int)(10*sin(a_min));
y_min1=240+(int)(10*cos(a_min));
x_hour1=320-(int)(5*sin(a_hour));
y_hour1=240+(int)(5*cos(a_hour));//画时针
setlinestyle(PS_SOLID,NULL,7);
setcolor(WHITE);
line(x_hour1,y_hour1,x_hour,y_hour);

//画分针
setlinestyle(PS_SOLID,NULL,4);
setcolor(LIGHTGRAY);
line(x_min1,y_min1,x_min,y_min);

//画秒针
setlinestyle(PS_SOLID,NULL,2);
setcolor(RED);
line(x_sec1,y_sec1,x_sec,y_sec);
}

voidmain()
{
initgraph(640,480);//初始化640x480的绘图窗口

//绘制一个简单的表盘
circle(320,240,2);
circle(320,240,60);
circle(320,240,160);
outtextxy(296,330,"竹斌");
intx,y;
for(inti=0;i<12;i++)
{
x=320+(int)(140*sin(30*i*2*PI/360));
y=240-(int)(140*cos(30*i*2*PI/360));
switch(i)
{
case0:outtextxy(x-5,y-5,"12");break;
case1:outtextxy(x-5,y-5,"1");break;
case2:outtextxy(x-5,y-5,"2");break;
case3:outtextxy(x-5,y-5,"3");break;
case4:outtextxy(x-5,y-5,"4");break;
case5:outtextxy(x-5,y-5,"5");break;
case6:outtextxy(x-5,y-5,"6");break;
case7:outtextxy(x-5,y-5,"7");break;
case8:outtextxy(x-5,y-5,"8");break;
case9:outtextxy(x-5,y-5,"9");break;
case10:outtextxy(x-5,y-5,"10");break;
case11:outtextxy(x-5,y-5,"11");break;
}
}

//设置XOR绘图模式
setwritemode(R2_XORPEN);//设置XOR绘图模式


//画刻度
inta,b,a1,b1,n=0;
for(n=0;n<60;n++)
{
a=320+(int)(160*sin(n*2*PI/60));
b=240-(int)(160*cos(n*2*PI/60));
a1=320+(int)(150*sin(n*2*PI/60));
b1=240-(int)(150*cos(n*2*PI/60));
if(n%5==0)
setlinestyle(PS_SOLID,NULL,5);
else
setlinestyle(PS_SOLID,NULL,1);
line(a1,b1,a,b);
}


//绘制表针
SYSTEMTIMEti;//定义变量保存当前时间
while(!kbhit())//按任意键退出钟表程序
{
GetLocalTime(&ti);//获取当前时间
Draw(ti.wHour,ti.wMinute,ti.wSecond);//画表针
Sleep(1000);//延时1秒
Draw(ti.wHour,ti.wMinute,ti.wSecond);//擦表针(擦表针和画表针的过程是一样的)
}

closegraph();//关闭绘图窗口
}

2. C语言编辑一个程序。要求在屏幕上显示一个图形时钟(用程序绘制一个与时钟样式相似即可)用的什么函数

用 MFC 吧 下面是C语言里的函数 时间函数 #include #include void main () { time_t rawtime; struct tm * timeinfo; char timE [80]; time ( &rawtime ); timeinfo = localtime ( &rawtime ); strftime ( timE,80,"Data:\n%Y-%m-%d \nTime:\n%I...

3. C语言程序设计:图形时钟

/* Note:Your choice is C IDE */
#include "stdio.h"
#include "graphics.h"
#include "math.h"
#include "time.h"
#include "dos.h"
#include "stdlib.h"
#include "conio.h"
#define R 200
#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(void);
void draw_bp(void);
void close(void);
void draw_kt(void);
int main(void)
{
int x,y,hc=0;
int bx,by,ax,ay;
int h,m,s;
struct time t[1];
init();
draw_bp();
draw_kt();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
setcolor(7);
d(150,h,30);
setcolor(14);
d(170,h,6);
setcolor(4);
d(190,s,6);
while(!kbhit())
{
while(t[0].ti_sec==s)
gettime(t);
sound(400);
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
setfillstyle(SOLID_FILL,13);
floodfill(1,380,14);
setcolor(4);
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();
}
setcolor(hc++);
if(hc==12) hc=0;
ellipse(300,300,160,340,23,23);
ellipse(220,170,0,360,23,65);
ellipse(380,170,0,360,23,65);
ellipse(300,180,0,180,23,23);
ellipse(380,180,0,180,23,23);
arc(150,80,20,250,59);
}
close();
return 0;
}
void init(void)
{
int driver,mode;
driver=DETECT;
initgraph(&driver,&mode,"c:\\tc");
cleardevice();
}
void draw_bp(void)
{
int x=300,y=240,i,n,l,ax,ay,bx,by;
for(n=0;n<27;n++)
printf("\n");
for(n=0;n<29;n++)
printf(" ");
setbkcolor(0);
setcolor(14);
circle(x,y,R);
setcolor(12);
circle(x,y,190);
setfillstyle(SOLID_FILL,14);
floodfill(x,y,12);
setfillstyle(SOLID_FILL,13);
floodfill(1,1,14);
setcolor(2);
circle(x,y,2);
circle(x,y,5);
for(i=0;i<60;i++)
{
if(i%5==0)
l=15;
else
l=5;
ax=200*cos(i*6*PI/180)+300;
ay=200*sin(i*6*PI/180)+240;
bx=(200-l)*cos(i*6*PI/180)+300;
by=(200-l)*sin(i*6*PI/180)+240;
line(ax,ay,bx,by);
}
settextstyle(3,0,5);
outtextxy(260,380,"MADEIN CHINA");
}

void draw_kt(void)
{
int x=300,y=240;
ellipse(x-80,y-70,0,360,23,65);
ellipse(x+80,y-70,0,360,23,65);
ellipse(x-80,y-60,0,180,23,23);
setfillstyle(SOLID_FILL,0);
floodfill(x-80,y-60,2);
ellipse(x+80,y-60,0,180,23,23);
setfillstyle(SOLID_FILL,0);
floodfill(x+80,y-70,2);
setcolor(5);
circle(150,80,60);
setfillstyle(SOLID_FILL,14);
floodfill(150,80,5);
circle(450,80,60);
setfillstyle(SOLID_FILL,14);
floodfill(450,80,5);
setcolor(14);
arc(150,80,0,360,60);
arc(450,80,0,360,60);
setcolor(0);
ellipse(x,y+60,160,340,23,23);
circle(x+120,y+10,23);
setfillstyle(SOLID_FILL,12);
floodfill(x+120,y+10,0);
setcolor(14);
circle(x+120,y+10,23);
setcolor(0);
circle(x-120,y+10,23);
setfillstyle(SOLID_FILL,12);
floodfill(x-120,y+10,0);
setcolor(14);
circle(x-120,y+10,23);
ellipse(x,y+60,0,180,23,23);
}
void close(void)
{
getch();
closegraph();
}

4. C语言编图形时钟

给你2个选吧,都是原创:
第1个:
#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*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s;
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
setcolor(7);
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit())
{while(t[0].ti_sec==s)
gettime(t);
sound(400);
delay(70);
sound(200);
delay(30);
nosound();
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();
}
}
getch();
closegraph();
}

第2个:
#include<graphics.h>
#include<math.h>
#include<dos.h>

#define PI 3.1415926
#define x0 320 /*定义钟表中心坐标*/
#define y0 240

void DrawClock(int x,int y,int color) /*画表盘*/
{ int r=150; /*表盘的半径*/
float th;
setcolor(color);
circle(x,y,r);
circle(x,y,2);
}

void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}

void main()
{int gdriver=DETECT,gmode;
struct time curtime;
float th_hour,th_min,th_sec;
initgraph(&gdriver,&gmode,"");

setbkcolor(0);

while(! kbhit())
{
DrawClock(x0,y0,14);
gettime(&curtime); /*得到当前系统时间*/

gotoxy(35,20); /*定位输出位置*/
if((float)curtime.ti_hour<=12) /*午前的处理*/
{printf("AM ");
if((float)curtime.ti_hour<10) printf("0"); /*十点之前在小时数前加零*/
printf("%.0f:",(float)curtime.ti_hour);
}
else /*午后的处理*/
{printf("PM ");
if((float)curtime.ti_hour-12<10) printf("0");
printf("%.0f:",(float)curtime.ti_hour-12);
}

if((float)curtime.ti_min<10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec<10) printf("0");
printf("%.0f",(float)curtime.ti_sec);

/*以下三行计算表针转动角度,以竖直向上为起点,顺时针为正*/

th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour,70,2); /*画时针*/
DrawHand(x0,y0,th_min,110,3); /*分针*/
DrawHand(x0,y0,th_sec,140,12); /*秒针*/

sleep(1); /*延时一秒后刷新*/
cleardevice();
}

closegraph();
}

5. C语言时钟设计

#include<graphics.h> /* 引入graphic.h */ #include<math.h> /* 引入math.h */ #include<dos.h> /* 引入dos.h */ #define pi 3.1415926 /*定义pi=3.14159*/ #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*cos(i*6*pi/180)+300; y1=200*sin(i*6*pi/180)+240; x2=(200-l)*cos(i*6*pi/180)+300; y2=(200-l)*sin(i*6*pi/180)+240; line(x1,y1,x2,y2); } } main() { int x,y; int gd=VGA,gm=2; unsigned char h,m,s; /*定义*/ struct time t[1]; initgraph(&gd,&gm,"d:\\tc"); init(); setwritemode(1); gettime(t); h=t[0].ti_hour; m=t[0].ti_min; s=t[0].ti_sec; /*定义时分秒*/ setcolor(7); /*设置颜色*/ d(150,h,30); setcolor(14); d(170,m,6); setcolor(4); d(190,s,6); while(!kbhit()) /*获取键盘相应*/ {while(t[0].ti_sec==s) gettime(t); /*C语言中得到时间的函数*/ sound(400); /*计算时间……*/ delay(70); sound(200); delay(30); nosound(); 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(); } } getch(); /*设置空格后退出*/ closegraph(); }

6. 怎么使用C语言制作一个时钟

这个也是我在别的地方找到的
很好的
#include "stdio.h"
#include "graphics.h"
#include "math.h"
#include "time.h"
#include "dos.h"
#define r 200
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300; /*遇到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; /*遇到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) /*宏定义不是说明或语句,在行末不必加分号,如加上分号则连分号也一起置换*/
/*
那么就是当执行d(200,12,6)时 相当于写了3句话
首先X(a,b,c) 也就是X(200,12,6) 这时计算x=200*cos(12*6*pi/180-pi/2)+300
也就是计算出了 以半径为200,度数为12 步长为6 (实际上就是72度 但是这里又减去了pi/2 也就是72-45=27度)
的那点的横坐标 也就是x的数值
然后执行Y(a,b,c)也就是Y(200,12,6)这时计算y=200*sin(12*6*pi/180-pi/2)+240
也就是计算出了 以半径为200,度数为12 步长为6 (实际上就是72度 但是这里又减去了pi/2 也就是72-45=27度)
的那点的纵坐标 也就是y的数值
最后是 line(300,240,x,y) 也就是 画线 这样指针就出来了
那么这里第一个参数是设置半径长度 第二个参数是设置度数 第三个参数是设置步长(度数)
*/
main()
{
int x=300,y=240,bx,by,bx1,by1,bx2,by2,bx3,by3,jd,i,j,k,h1,m1,hc=0,l,ax,ay,n,p=0;
char b[]={'I',' ',' ',' ',' ','L','o','v','e',' ',' ',' ',' ','Y','o','u'};
int driver=VGA,mode=VGAHI; /*定义图形驱动器*/
int h,m,s; /*定义时针hour 分针minute 秒针second*/
struct time t[1]; /*定义一个结构体名为time的数组,只有一个成员t[0]*/
initgraph(&driver,&mode,""); /*设置图形驱动器*/
setbkcolor(0); /*设置背景色为黑色*/
for(n=0;n<=27;n++)

printf("\n");
for(n=0;n<=29;n++)
printf(" ");
setcolor(14); /*设置前景色为黄色*/
circle(x,y,r); /*以300,240,半径为200画大圆*/
setcolor(12); /*设置前景色为洋红色*/
circle(x,y,190); /* 内部小圆*/
/*设置填充样式及颜色*/
setfillstyle(SOLID_FILL,14); /*实心填充*/
floodfill(x,y,12); /* 填充表盘 填充色为洋红(12) */
setfillstyle(SOLID_FILL,13); /*实心填充*/
floodfill(1,1,14);
setcolor(2); /*设置为绿色*/
/*画表心*/
circle(x,y,2); /*表心小圆*/
circle(x,y,5); /*表心大圆*/
/*眼睛*/
ellipse(x-80,y-70,0,360,23,65); /*左 外面的椭圆*/
ellipse(x+80,y-70,0,360,23,65); /*右 外面的椭圆*/
ellipse(x-80,y-60,0,180,23,23); /*左 里面的椭圆*/
setfillstyle(SOLID_FILL,0); /*实型填充 填充颜色为黑色*/
floodfill(x-80,y-60,2); /*填充颜色 绿色*/
ellipse(x+80,y-60,0,180,23,23); /*右 里面的椭圆*/
setfillstyle(SOLID_FILL,0); /*实型填充 填充颜色为黑色*/
floodfill(x+80,y-70,2); /*填充颜色 绿色*/
/* outtextxy(225,380,"EmBEdDed 06241 ShiwU");
outtextxy(245,400,"MaDE In HuaXiA"); */

/*六个胡子*/
setcolor(5); /* 粉红色 */
line(x-120,y+70,x-250,y+90);
line(x-120,y+90,x-250,y+110);
line(x-120,y+110,x-250,y+130);
line(x+120,y+70,x+250,y+90);
line(x+120,y+90,x+250,y+110);
line(x+120,y+110,x+250,y+130);
/*画耳朵*/
arc(150,80,0,360,60); /*画圆弧(此处完全可以用圆来代替)*/
setfillstyle(SOLID_FILL,14); /*填充色黄色*/
floodfill(150,80,5);
arc(450,80,0,360,60);
setfillstyle(SOLID_FILL,14);
floodfill(450,80,5);
setcolor(14); /*擦除内部圆弧痕迹*/
arc(150,80,0,360,60);
arc(450,80,0,360,60);
/*画嘴*/
setcolor(0);
ellipse(x,y+60,160,340,23,23); /*用圆弧画嘴*/
/*画侧脸*/
circle(x+120,y+10,23); /*前景色为0 侧面的圆圈*/
setfillstyle( SOLID_FILL,12); /*实型填充 颜色为12 淡洋红*/
floodfill(x+120,y+10,0); /*以侧面的圆心为中心 边缘颜色为0 白色 进行对封闭图形的填充*/
setcolor(14); /*设置前景色为黄色 清除内部圆弧痕迹*/
circle(x+120,y+10,23); /*重新画小圈*/
setcolor(0); /*前景色为0 侧面的圆圈*/
circle(x-120,y+10,23); /*以下同上*/
setfillstyle( SOLID_FILL,12);
floodfill(x-120,y+10,0);
setcolor(14);
circle(x-120,y+10,23);

ellipse(x,y+60,0,180,23,23);
for(i=0;i<60;i++)
{if(i%5==0) l=15;
else l=5;
ax=200*cos(i*6*pi/180)+300;
ay=200*sin(i*6*pi/180)+240;
bx=(200-l)*cos(i*6*pi/180)+300;
by=(200-l)*sin(i*6*pi/180)+240;
line(ax,ay,bx,by);

}
setwritemode(1); /*这句无敌了*/

gettime(t); /*得到系统时间给数组t实际上就是给了t[0]*/
h=t[0].ti_hour; /*时针数值给h*/
m=t[0].ti_min; /*分针数值给m*/
s=t[0].ti_sec;
/*秒针数值给s*/
setcolor(7); /*设置前景色为7 淡灰色*/
/*第一个参数是设置半径长度 第二个参数是设置起始度数 第三个参数是设置步长(度数)*/
d(150,h,30); /*以半径为150,h为起始度数,步长为30度,时针总共一圈才走12下*/
setcolor(14); /*设置分针颜色 1 蓝色*/
d(170,m,6); /*以半径170,m为起始度数,步长为6度,分针一圈走60下*/
setcolor(4); /*设置秒针颜色 4 红色*/
d(190,s,6); /*以半径190,s为起始度数,步长为6度,秒针一圈走60下*/
while(!kbhit()) /*当不敲击键盘时候一直循环*/
{

while(t[0].ti_sec==s) /*判断当前系统时间是否与刚才得到的秒时间相等,一定相等,没有刷新系统时间*/
gettime(t);
setcolor(4);
d(190,s,6); /*所以重新刷新系统时间*/
s=t[0].ti_sec;
setfillstyle(SOLID_FILL,13); /*实心填充*/
floodfill(1,380,14);
if(p<=15)
{ setbkcolor(hc); printf("%c",b[p]); }
else
setbkcolor(0);
p++;
setcolor(4); /*设置秒针颜色为2 绿色*/
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);
}
setcolor(hc++);
if(hc==12)
hc=0;
ellipse(300,300,160,340,23,23);

/*眼睛*/
ellipse(220,170,0,360,23,65);
ellipse(380,170,0,360,23,65);
ellipse(220,180,0,180,23,23);
ellipse(380,180,0,180,23,23);

arc(150,80,20,250,59);
arc(450,80,-70,165,59);

}

getch();
}

7. c语言 时钟模拟

#include<math.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#define PI 3.141592653589793
int h,m,s,i,l,mon,y,d;
struct time t;
struct date data;
draw()
{
gettime(&t); //取得时间信息到t
s=t.ti_sec; //秒
h=t.ti_hour; //时
m=t.ti_min; //分
getdate(&data); //取得日期信息到data
y=data.da_year; //年
mon=data.da_mon; //月
d=data.da_day; //日

//画出钟的外圆(即是轮廓)
setcolor(11);
circle(300,200,152);
setcolor(3);
circle(300,200,157);

//画出60个分钟刻度
for(i=0;i<60;i+=1)
{
if(i%5==0) l=140;
else l=145;
line(300+150*sin(i*PI/30),200-150*cos(i*PI/30),
300+l*sin(i*PI/30),200-l*cos(i*PI/30));
}

//画秒针
setcolor(19);
line(300,200,300+140*sin(s*PI/30),200-140*cos(s*PI/30));
//画分针
setcolor(3);
line(300,200,300+110*sin(m*PI/30),200-110*cos(m*PI/30));
//画时针
setcolor(11);
line(300,200,300+90*sin(((float)h+(float)m/60)*PI/6),200-90*cos(((float)h+(float)m/60)*PI/6));

//标注钟盘上的"3"、"6"、"9"、"12"
settextstyle(3,0,2);
outtextxy(430,190,"3");
outtextxy(295,320,"6");
outtextxy(160,190,"9");
outtextxy(293,60,"12");
}
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,""); //初始化屏幕模式
setbkcolor(8);
while(!kbhit()) //若有键盘输入则跳出(结束程序)
{
draw(); //绘制钟
settextstyle(3,0,5);
setcolor(9);
outtextxy(60,170,"my clock");
gotoxy(35,17);
//打印出数字形式的时间(hh:mm:ss)
if(h<10) printf("0");printf("%d:",h);
if(m<10) printf("0");printf("%d:",m);
if(s<10) printf("0");printf("%d",s);
gotoxy(33,18);
printf("%d:",y);
//打印出日期(mm:dd)
if(mon<10) printf("0");printf("%d:",mon);
if(d<10) printf("0");printf("%d",d);
sound(200); //让喇叭以200HZ叫一声
delay(70); //延时0.07秒,即是声音延续0.07秒
nosound(); //停止声音
sleep(1); //停止一秒
cleardevice(); //清屏
}
}

8. 如何用C语言在图形界面里画时钟时针

这是我用C语言写的

需要采用EasyX图形库,绘制方法很简单,只需要根据时间,算出指针的偏转角度,然后从中心点向外画长度不等的线即可

9. C语言 用Devc++做一个图形时钟,要能在devc上运行的,简简单单的就行,谢谢。

#include<iostream>
#include<windows.h>
using namespace std;
class Clock{
public:
Clock(short h=0,short m=0,short s=0):h(h),m(m),s(s){
}
void displayTime();
private:
short h;
short m;
short s;
};void Clock::displayTime(){
while(true){
cout<<h<<':'<<m<<':'<<s<<" ";
Sleep(1000);//一秒更新一次
cout<<'\r';
if(!(s=++s%60))
if(!(m=++m%60))
h=++h%24;
}
} int main()
{
Clock A(12,20,30);//初始时间
A.displayTime();//更新函数
return 0;
}
/*
12:20:3

10. C语言 用Devc++编一个图形时钟,要求能在devc++上运行的,简简单单的就可以了。

//图形库是EGE,下载后配置一下
#include<iostream>
#include"graphics.h"
#include<math.h>
#include<time.h>
#include<windows.h>

#definex0210.0
#definey0210.0
#definer200.0

POINTpt[60],pt_s[60],pt_m[60],pt_h[60],pt1[60];

usingnamespacestd;
intmain()
{
initgraph(420,420);
setfillcolor(0xffccff);
setcolor(0xffccff);

fillellipse(x0,y0,10,10);
ints=45,m,h,n=0;
while(n<60)
{
pt_s[s].x=x0+(int)((r-20)*cos((n-90)*3.1415926/30.0));
pt_s[s].y=y0+(int)((r-20)*sin((n-90)*3.1415926/30.0));

pt_m[s].x=x0+(int)((r-50)*cos((n-90)*3.1415926/30.0));
pt_m[s].y=y0+(int)((r-50)*sin((n-90)*3.1415926/30.0));

pt_h[s].x=x0+(int)((r-80)*cos((n-90)*3.1415926/30.0));
pt_h[s].y=y0+(int)((r-80)*sin((n-90)*3.1415926/30.0));

pt[s].x=x0+(int)(r*cos((n-90)*3.1415926/30.0));
pt[s].y=y0+(int)(r*sin((n-90)*3.1415926/30.0));

fillellipse(pt[s].x,pt[s].y,2,2);
n++;
s++;
if(s>=60)
{
s=0;
}
}
for(inti=0;i<12;i++)
{
fillellipse(pt[i*5].x,pt[i*5].y,5,5);
}
intxs,ys,xm=-1,ym=-1,xh=-1,yh=-1;
while(1)
{
intn,m;
SYSTEMTIMEst={0};
GetLocalTime(&st);
setcolor(0xffccff);
line(x0,y0,pt_s[st.wSecond].x,pt_s[st.wSecond].y);
xs=pt_s[st.wSecond].x;
ys=pt_s[st.wSecond].y;
if(pt_m[st.wMinute].x!=xm&&pt_m[st.wMinute].y!=ym)
{
setcolor(0);
line(x0,y0,xm,ym);
xm=pt_m[st.wMinute].x;
ym=pt_m[st.wMinute].y;
setcolor(0xffccff);
}
line(x0,y0,pt_m[st.wMinute].x,pt_m[st.wMinute].y);
if(st.wHour>12)
{
n=st.wHour-12;
}
else
{
n=st.wHour;
}
m=(n*60+st.wMinute)/12;
line(x0,y0,pt_h[m].x,pt_h[m].y);
Sleep(1000);
setcolor(0x0);
line(x0,y0,xs,ys);
fillellipse(x0,y0,10,10);
}
closegraph();
return0;
}

热点内容
免费ftp服务软件 发布:2025-02-11 15:58:06 浏览:865
大樱桃建园为什么要配置授粉树 发布:2025-02-11 15:58:00 浏览:628
五菱宏光s顶配有哪些配置 发布:2025-02-11 15:50:57 浏览:286
华为8加128配置有哪些 发布:2025-02-11 15:48:20 浏览:579
压缩机三转子 发布:2025-02-11 15:45:54 浏览:827
linux操作系统shell 发布:2025-02-11 15:45:53 浏览:338
安卓模拟器如何选择安装 发布:2025-02-11 15:34:26 浏览:176
安卓手机和华为哪个好用 发布:2025-02-11 15:32:11 浏览:555
大众车载dv设置密码多少 发布:2025-02-11 15:26:06 浏览:413
sqlserver连接超时 发布:2025-02-11 15:24:25 浏览:741