當前位置:首頁 » 編程軟體 » 時鍾代碼編程

時鍾代碼編程

發布時間: 2022-05-27 08:08:53

A. c++時鍾程序代碼

//win32
控制台應用程序的......
#include
<windows.h>
#include
<iostream>
int
main()
{
systemtime
time;//時間結構體
while(true)
{
getsystemtime(&time);//獲取當前系統時間
system("cls");//清屏
std::cout<<time.wyear<<"年"<<time.wmonth<<"月"<<time.wday<<"日
"<<time.whour<<":"<<time.wminute<<":"<<time.wsecond;//顯示
sleep(1000);//暫停一秒
}
return
0;
}

B. vb時鍾代碼編寫

DimPAsSingle,SJ,SHIAsInteger,FENAsInteger,MIAOAsInteger

PrivateSubForm_Load()

Timer1.Interval=1000

Timer1.Enabled=True

P=3.1415926

EndSub

PrivateSubTimer1_Timer()

SJ=Time

SHI=DatePart("H",SJ)

FEN=DatePart("N",SJ)

MIAO=DatePart("S",SJ)

IfSHI>=12Then

SHI=SHI-12

EndIf

Label5.Caption=FormatDateTime(SJ,3)

Line2.X2=2760+1500*Sin(P*(SHI*30+FEN/2)/180)

Line2.Y2=2760-1500*Cos(P*(SHI*30+FEN/2)/180)

Line5.X2=2760+1920*Sin(P*(FEN*6+MIAO/10)/180)

Line5.Y2=2760-1920*Cos(P*(FEN*6+MIAO/10)/180)

Line1.X2=2760+2400*Sin(P*MIAO*6/180)

Line1.Y2=2760-2400*Cos(P*MIAO*6/180)

EndSub

C. 用c語言 編寫 一個時鍾程序

/*全屏幕模擬時鍾的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;
#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(0);
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())
/*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();
/*關閉圖形系統*/
}

D. C語言 時鍾 編程 源代碼 越繁復越好

幫你找了一個!希望對你有幫助……(個人覺得在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',' ',' ',' ',' ','T','e','l','l',' ',' ',' ',' ','Y','o','u'};
int driver=VGA,mode=VGAHI; /*定義圖形驅動器*/
int h,m,s; /*定義時針hour 分針minute 秒針second*/
struct time t[1]; /*定義一個結構體名為time的數組,只有一個成員t[0]*/
registerbgidriver(EGAVGA_driver);
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;<br> else l=5;<br> ax=200*cos(i*6*pi/180)+300;<br> ay=200*sin(i*6*pi/180)+240;<br> bx=(200-l)*cos(i*6*pi/180)+300;<br> by=(200-l)*sin(i*6*pi/180)+240;<br> line(ax,ay,bx,by);</p><p> }
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();
getch();
}

E. c程序時鍾代碼誰有

#include <reg52.h>
#define uint unsigned int
sbit P3_0=P3^0;
sbit K1=P3^2;
sbit K2=P3^3;
sbit K3=P3^4;
sbit K4=P3^5;
uint count,min,hour,i,j=0;
uint code tab1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint code tab2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uint code tab3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0x00,0xff,0x00,0xff,
0xfe,0xfb,0xef,0xbf,0xfd,0xf7,0xdf,0x7f,0x7e,0x3c,0x18,0x00,0x81,
0xc3,0xe7,0xff,0xe7,0xdb,0xbd,0x7e,0xff,0x7e,0xbd,0xdb,0xe7,0xff,
0x00,0xff,0x00,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,
0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x00,0xff,0x00,0xff,0xfe,0xfc,
0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,
0xff,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,0x00,0xff,0x00,0xff};

void adjust(void)
{
if(!K3) //分調整
{
for(i=0;i<20000;i++);min++;
if(min==60)min=0;
}
if(!K4) //時調整
{
for(i=0;i<20000;i++);hour++;
if(hour==24)hour=0;
}
}

void display(void)
{
P0=tab1[min%10];P2=0xf7;for(i=0;i<5;i++);P2=0xff;//分個位顯示
P0=tab1[min/10];P2=0xfb;for(i=0;i<5;i++);P2=0xff;//分十位顯示
P0=tab2[hour%10];P2=0xfd;for(i=0;i<5;i++);P2=0xff;//時個位顯示
P0=tab1[hour/10];P2=0xfe;for(i=0;i<5;i++);P2=0xff;//時十位顯示
}

void ring(void)
{
if(hour/10==0&&(hour%10>=8&&hour%10<=9))P3_0=0;//早上7:00到晚上7:00自動整點報時,其中13、14點不報時
if(hour/10==1&&(hour%10>=0&&hour%10<=2))P3_0=0;
if(hour/10==1&&(hour%10>=5&&hour%10<=9))P3_0=0;
}

void update(void)
{
if(count==1200)
{
count=0;min++;
if(min==60)
{
min=0;hour++;
if(hour==24)hour=0;
ring();
}
}
}

void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
EA=1;
ET0=1;
while(1)
{
if(count==120)P3_0=1;//報時六秒後自動關閉蜂鳴器
adjust();
display();
}
}

void timer0_rupt(void) interrupt 1 // 定時器0中斷
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count%10==0)
{
P1=tab3[j];
j++;
if(j>99)j=0;
}
update();
}

F. 時鍾程序(C語言)怎麼寫

具體代碼如下:
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926

//屏幕中心的坐標(640X480模式下)
#define mid_x 320
#define mid_y 240

int main()
{ int graphdriver=DETECT,graphmode;
int end_x,end_y;
struct time curtime;
float th_hour,th_min,th_sec;

initgraph(&graphdriver,&graphmode,"C:\\TC2"); //初始化VGA屏幕模式
setbkcolor(BLACK); //使用黑色的背景色
while(!kbhit(0)) //若有鍵盤輸入,則跳出,即是結束程序
{ setcolor(GREEN); //把畫筆設為綠色
circle(mid_x,mid_y,180); //鍾的外圓
circle(mid_x,mid_y,150); //鍾的內圓
circle(mid_x,mid_y,1); //畫出鍾的圓心
gettime(&curtime); //取得系統當前時間
th_sec=(float)curtime.ti_sec*0.1047197551; //把秒針的角度化為弧度,為以後繪制時方便,下同
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0; //分針的弧度
th_hour=(float)curtime.ti_hour*0.5235987755+th_min/12.0; //時度的弧度,注意整時是12等分的,所時乘的是3.14/180*5
//計算出時針的尾的坐標(時針長70)
end_x=mid_x+70*sin(th_hour);
end_y=mid_y-70*cos(th_hour);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //用紅色線畫出時針
//計算出分針坐標(分針長110)
end_x=mid_x+110*sin(th_min);
end_y=mid_y-110*cos(th_min);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //用紅色畫出分針
end_x=mid_x+140*sin(th_sec);
end_y=mid_y-140*cos(th_sec);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //同上,畫出秒針,長為140
//畫出鍾盤上的刻度,刻度長20
line(140,240,160,240); //9點對應的大刻度
line(320,60,320,80); //12點對應的大刻度
line(500,240,480,240); //3點的刻度
line(320,420,320,400); //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點
sleep(BLUE); //這里應該是打錯,停止一秒,應為sleep(1000)
cleardevice(); //清除屏幕上的顯示
}
closegraph(); //關閉VGA屏幕,即返迴文本方式
return 0;
}

G. 用c++編寫一個時鍾的代碼

http://scmbl.anyp.cn/050808213853041.aspx
這里是148款精美時鍾代碼

http://www.9941.cn/moban/zhong/1.htm
flash時鍾,時鍾,qq空間時鍾代碼,透明flash時鍾

以下是flash時鍾代碼:(博客flash時鍾庫)
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="300" height="200">
<param name="movie" value="flash時鍾地址">
<param name="quality" value="high">
<embed src="d" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
</object>
說明:(手動插入必看)
1、width=300,height=300為flash文件的寬度和高度,你可以自定修改
2、flash時鍾地址,是flash文件地址,復制以下任一地址都行,如:/free/UploadFiles_2504/clock/clock1.swf
flash時鍾下載, 下載方法:(請用「右鍵-目標另存為」方式下載,或是使用下載工具)
下面為您提供一些時鍾地址,效果見FLASH欄目里的「時鍾樣式」專輯,也可以直接點擊下面的網址查看效果。您可以對照選擇您喜歡的樣式。
時鍾1:/free/UploadFiles_2504/clock/clock1.swf
時鍾2:/free/UploadFiles_2504/clock/clock2.swf
時鍾3:/free/UploadFiles_2504/clock/clock3.swf
時鍾4:/free/UploadFiles_2504/clock/clock4.swf
時鍾5:/free/UploadFiles_2504/clock/clock5.swf
時鍾6:/free/UploadFiles_2504/clock/clock6.swf
時鍾7:/free/UploadFiles_2504/clock/clock7.swf
時鍾8:/free/UploadFiles_2504/clock/clock8.swf
時鍾9:/free/UploadFiles_2504/clock/clock9.swf
時鍾10:/free/UploadFiles_2504/clock/clock10.swf
時鍾11:/free/UploadFiles_2504/clock/clock11.swf
時鍾12:/free/UploadFiles_2504/clock/clock12.swf
時鍾13:/free/UploadFiles_2504/clock/clock13.swf
時鍾14:/free/UploadFiles_2504/clock/clock14.swf
時鍾15:/free/UploadFiles_2504/clock/clock15.swf
時鍾16:/free/UploadFiles_2504/clock/clock16.swf
時鍾17:/free/UploadFiles_2504/clock/clock17.swf
時鍾18:/free/UploadFiles_2504/clock/clock18.swf
時鍾19:/free/UploadFiles_2504/clock/clock19.swf
時鍾20:/free/UploadFiles_2504/clock/clock20.swf
時鍾21:/free/UploadFiles_2504/clock/clock21.swf
時鍾22:/free/UploadFiles_2504/clock/clock22.swf
時鍾23:/free/UploadFiles_2504/clock/clock23.swf
時鍾24:/free/UploadFiles_2504/clock/clock24.swf
時鍾25:/free/UploadFiles_2504/clock/clock25.swf
時鍾26:/free/UploadFiles_2504/clock/clock26.swf
時鍾27:/free/UploadFiles_2504/clock/clock27.swf
時鍾28:/free/UploadFiles_2504/clock/clock28.swf
時鍾29:/free/UploadFiles_2504/clock/clock29.swf
時鍾30:/free/UploadFiles_2504/clock/clock30.swf
時鍾31:/free/UploadFiles_2504/clock/clock31.swf
時鍾32:/free/UploadFiles_2504/clock/clock32.swf
時鍾33:/free/UploadFiles_2504/clock/clock33.swf
時鍾34:/free/UploadFiles_2504/clock/clock34.swf
時鍾35:/free/UploadFiles_2504/clock/clock35.swf
時鍾36:/free/UploadFiles_2504/clock/clock36.swf
時鍾37:/free/UploadFiles_2504/clock/clock37.swf
時鍾38:/free/UploadFiles_2504/clock/clock38.swf
時鍾39:/free/UploadFiles_2504/clock/clock39.swf
時鍾40:/free/UploadFiles_2504/clock/clock40.swf

H. 時鍾的C語言程序代碼,要沒錯誤,能運行的。最好重要的語句後面要有注釋,急求~~高手求解~~~

給你一個指示吧 1.繪圖函數 2.時間從主板上面取 程序如下(運行環境是在TC下面的)/***********簡單的時鍾程序,界面不是很美觀,您可以根據自己的愛好加以修改,如給表盤加上刻度,將指針改為其它外形等*/

#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;<br> struct time curtime;<br> float th_hour,th_min,th_sec;<br> initgraph(&gdriver,&gmode,"");<br><br> setbkcolor(0);<br><br> while(! kbhit())<br> {<br> DrawClock(x0,y0,14);<br> gettime(&curtime); /*得到當前系統時間*/<br><br> gotoxy(35,20); /*定位輸出位置*/<br> if((float)curtime.ti_hour<=12) /*午前的處理*/<br> {printf("AM ");<br> if((float)curtime.ti_hour<10) printf("0"); /*十點之前在小時數前加零*/<br> printf("%.0f:",(float)curtime.ti_hour);<br> }
else /*午後的處理*/
{printf("PM ");<br> if((float)curtime.ti_hour-12<10) printf("0");<br> printf("%.0f:",(float)curtime.ti_hour-12);<br> }

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();
}

I. c語言怎麼樣編寫一個時鍾程序

c語言時鍾程序代碼如下:

#include<windows.h>

#include<math.h>

#define ID_TIMER 1//計時器ID

#define TWOPI (2*3.14159)

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)

{

static TCHAR szAppName[]=TEXT("Clock");

HWND hwnd;

MSG msg;

WNDCLASS wndclass;

wndclass.cbClsExtra=0;

wndclass.cbWndExtra=0;

wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);

wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);

wndclass.hInstance=hInstance;

wndclass.lpfnWndProc=WndProc;

wndclass.lpszClassName=szAppName;

wndclass.lpszMenuName=NULL;

wndclass.style=CS_HREDRAW|CS_VREDRAW;

if(!RegisterClass(&wndclass))

{

MessageBox(NULL,TEXT("This program requires Windows

T"),szAppName,MB_ICONERROR);

return 0;

}

hwnd=CreateWindow(szAppName,TEXT("Analog Clock"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,iCmdShow);

UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

void Setsotropic(HDC hdc,int cxClient,int cyClient)

{

SetMapMode(hdc,MM_ISOTROPIC);

SetWindowExtEx(hdc,1000,1000,NULL);

SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL);

SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);

}

void RotatePoint(POINT pt[],int iNum,int iAngle)

{

int i;

POINT ptTemp;

for(i=0;i<iNum;i++)

{

ptTemp.x=(int)(pt[i].x*cos(TWOPI*iAngle/360)+pt[i].y*sin(TWOPI*iAngle/360));

ptTemp.y=(int)(pt[i].y*cos(TWOPI*iAngle/360)+pt[i].x*sin(TWOPI*iAngle/360));

pt[i]=ptTemp;

}

}

void DrawClock(HDC hdc)

{

int iAngle;

POINT pt[3];

for(iAngle=0;iAngle<360;iAngle+=6)

{

pt[0].x=0;

pt[0].y=900;

RotatePoint(pt,1,iAngle);

pt[2].x=pt[2].y=iAngle%5?33:100;

pt[0].x-=pt[2].x/2;

pt[0].y-=pt[2].y/2;

pt[1].x=pt[0].x+pt[2].x;

pt[1].y=pt[0].y+pt[2].y;

SelectObject(hdc,GetStockObject(BLACK_BRUSH));

Ellipse(hdc,pt[0].x,pt[0].y,pt[1].x,pt[1].y );

}

}

void DrawHands(HDC hdc,SYSTEMTIME *pst,BOOL fChange)

{

static POINT pt[3][5]={0,-150,100,0,0,600,-100,0,0,-150, 0,-200,50,0,0,800,-50,0,0,-200, 0,0,0,0,0,0,0,0,0,800 };

int i,iAngle[3];

POINT ptTemp[3][5];

iAngle[0]=(pst->wHour*30)%360+pst->wMinute/2;

iAngle[1]=pst->wMinute*6;

iAngle[2]=pst->wSecond*6;

memcpy(ptTemp,pt,sizeof(pt));

for(i=fChange?0:2;i<3;i++)

{

RotatePoint(ptTemp[i],5,iAngle[i]);

Polyline(hdc,ptTemp[i],5);

}

}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)

{

static int cxClient,cyClient;

static SYSTEMTIME stPrevious;

BOOL fChange;

HDC hdc;

PAINTSTRUCT ps;

SYSTEMTIME st;

switch(message)

{

case WM_CREATE:

SetTimer(hwnd,ID_TIMER,1000,NULL);

GetLocalTime(&st);

stPrevious=st;

return 0;

case WM_SIZE:

cxClient=LOWORD(lParam);

cyClient=HIWORD(lParam);

return 0;

case WM_TIMER:

GetLocalTime(&st);

fChange=st.wHour!=stPrevious.wHour||st.wMinute!=stPrevious.wMinute;

hdc=GetDC(hwnd);

Setsotropic(hdc,cxClient,cyClient);

SelectObject(hdc,GetStockObject(WHITE_PEN));

DrawHands(hdc,&stPrevious,fChange);

SelectObject(hdc,GetStockObject(BLACK_PEN));

DrawHands(hdc,&st,TRUE);

stPrevious=st;

return 0;

case WM_PAINT:

hdc=BeginPaint(hwnd,&ps);

Setsotropic(hdc,cxClient,cyClient);

DrawClock(hdc);

DrawHands(hdc,&stPrevious,TRUE);

EndPaint(hwnd,&ps);

return 0;

case WM_DESTROY:

KillTimer(hwnd,ID_TIMER);

PostQuitMessage(0);

return 0;

}

return DefWindowProc(hwnd,message,wParam,lParam);

}

J. 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();
}

具體的。。就是套用用幾個函數算時間。。
不要對這種很長的東西害怕,其實大部分都是在畫這個鍾~
加油哦~

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:647
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:939
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:634
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:823
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:734
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1069
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:302
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:163
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:855
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:765