當前位置:首頁 » 編程語言 » 表盤用c語言編寫控制項
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

表盤用c語言編寫控制項

發布時間: 2022-12-14 11:44:22

① 求用c語言怎麼實現表盤的指針轉動 因為我在液晶屏上用函數畫了三根針,怎麼讓他們轉起來啊

算sin和cos的值就行了。用極坐標

② C語言編寫機械鍾表盤的指針

可以利用數學上的圓心角!把時間化成圓周度數,在利用圓的極坐標公式 就可以了!

③ 誰能幫我用c語言編寫桌面鍾表啊!

#include<math.h>
#include<dos.h>
#include<graphics.h>
#define CENTERX 320 /*表盤中心位置*/
#define CENTERY 175
#define CLICK 100 /*喀嗒聲頻率*/
#define CLICKDELAY 30 /*喀嗒聲延時*/
#define HEBEEP 10000 /*高聲頻率*/
#define LOWBEEP 500 /*低聲頻率*/
#define BEEPDELAY 200 /*報時聲延時*/

/*表盤刻度形狀*/
int Mrk_1[8]={-5,-160,5,-160,5,-130,-5,-130, };
int Mrk_2[8]={-5,-160,5,-160,2,-130,-2-130, };

/*時針形狀*/
int HourHand[8]={-3,-100,3,-120,4, 10,-4,10};

/*分針形狀*/
int MiHand[8]={-3,-120,3,-120,4, 10,-4,10};

/*秒針形狀*/
int SecHand[8]={-2,-150,2,-150,3, 10,-3,10};

/*發出喀嗒聲*/
void Click()
{
sound(CLICK);
delay(CLICKDELAY);
nosound();
}

/*高聲報時*/
void HighBeep()
{
sound(HEBEEP);
delay(BEEPDELAY);
nosound;
}

/*低聲報時*/
void LowBeep()
{
sound(LOWBEEP);
}

/*按任意角度畫多邊形*/
void DrawPoly(int *data,int angle,int color)
{
int usedata[8];
float sinang,cosang;
int i;
sinang=sin((float)angle/180*3.14);
cosang=cos((float)angle/180*3.14);
for(i=0;i<8;i+=2)
{
usedata[i] =CENTERX+ cosang*data[i]-sinang*data[i+1]+.5;
usedata[i+1]=CENTERY+sinang*data[i]+cosang*data[i+1]+.5;
}
setfillstyle(SOLID_FILL,color);
fillpoly(4,usedata);
}

/*畫表盤*/
void DrawClock(struct time *cutime)
{
int ang;
float hourrate,minrate,secrate;

setbkcolor(BLUE);
cleardevice();
setcolor(WHITE);

/* 畫刻度*/
for(ang=0;ang<360;ang+=90)
{
DrawPoly(Mrk_1,ang,WHITE);
DrawPoly(Mrk_2,ang+30,WHITE);
DrawPoly(Mrk_2,ang+60,WHITE);
}
secrate=(float)cutime->ti_sec/60;
minrate=((float)cutime->ti_min+secrate)/60;
hourrate=(((float)cutime->ti_hour/12)+minrate)/12;
ang=hourrate*360;
DrawPoly(HourHand,ang,YELLOW);/*畫時針*/
ang=minrate*360;
DrawPoly(MiHand,ang, GREEN);/*畫分針*/
ang=secrate*360;
DrawPoly(SecHand,ang, RED);/*畫秒針*/
}
main()
{
int gdriver=EGA,
gmode=EGAHI;
int curpage;
struct time curtime ,newtime ;
initgraph(&gdriver,&gmode,"c:\\tc");
setbkcolor(BLUE);
cleardevice();
gettime(&curtime);
curpage=0;
DrawClock(&curtime);
while(1)
{
if(kbhit())
break; /*按任意鍵退出*/
gettime(&newtime); /*檢測系統時間*/
if(newtime.ti_sec!=curtime.ti_sec)/*每1秒更新一次時間*/
{
if(curpage==0)
curpage=1;
else
curpage=0;
curtime=newtime;
/*設置繪圖頁*/
setactivepage(curpage);
/*在圖頁上畫表盤*/
DrawClock(&curtime);
/*設置繪圖頁為當前可見頁*/
setvisualpage(curpage);
/*0分0秒高聲報時*/
if(newtime.ti_min==0&&newtime.ti_sec==0)
HighBeep();
/* 59分55至秒時低聲報時*/
else if(newtime.ti_min==59&&
newtime.ti_sec<=59)
LowBeep();/*其他時間只發出喀嗒聲*/
else
Click();
}
}
closegraph();
}

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

⑤ 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(); //清屏
}
}

⑥ 想用C語言編寫一個有可視化的界面,有按鈕,有輸入框的程序

可以用MFC做界面,在Visual C++新建》項目》MFC AppWizard(exe)》dialog based》下面都默認,就能建立一個MFC工程。可以添加控制項,控制項響應的原理與VB中的類似,建議你找本MFC的教材仔細了解其原理

⑦ 如何用C語言編寫GUI的軟體

1.可以用
winc
,就是直接在windows下編程。這個比較麻煩,因為所有的東西都必須自己寫(如創建窗口,初始化等一些基本的)以前老師上課的時候講過,理解了之後,感覺其實很簡單,而且都是一個套路,看個例子就能明白的
2.可以用mfc創建界面,裡面要具體實現的東西,直接用c語言寫就可以了,很方便,其實mfc就是對winc的一種封裝,就是第一點說的你要寫的那些基本的東西(創建窗口,初始化之類的),他都給你弄好了,不用自己寫,直接創建一個工程就ok了
3.可以創建c#工程,用c#創建界面(直接拖控制項就行,像vb那樣),然後,你要實現的東西用c語言寫。或者,你先將要實現的東西,用c語言寫好,編譯成動態鏈接庫dll,然後在c#工程中調用該dll。c#工程實際上就起到一個界面封裝的目的,也比較方便

⑧ 用"C語言"編寫一個指針型時鍾模擬的程序

#include"graphics.h"
#define PI 3.1416
#include"math.h"
#include"dos.h"
main()
{
int x0=320,y0=240,r0=150;
void init_sceen();
void sec();
init_sceen(x0,y0,r0);
sec();
closegraph();
}
void init_sceen(int x0,int y0,int r0)/********************************************/
{
int i,x,y,graphdriver,graphmode;
char s[10];
float alpha,a0=90;

graphdriver=DETECT;
initgraph(&graphdriver,&graphmode,"");
setbkcolor(3);
setcolor(2);
circle(x0,y0,r0);
circle(x0,y0,r0+30);
setfillstyle(SOLID_FILL,10);
floodfill(x0-r0-10,y0,2);
/*please input the time*/
for(i=12;i>=1;i--)
{
alpha=(a0+30*(11-i)*PI/180);
x=x0+cos(alpha)*r0-16;
y=y0-sin(alpha)*r0;
sprintf(s,"%2d",i);
setcolor(4);
settextstyle(0,0,2);
outtextxy(x,y,s);
}
/*input second*/
for(i=60;i>=1;i--)
{
alpha=(a0+6*(60-i)*PI/180);
x=x0+cos(alpha)*(r0-20);
y=y0-sin(alpha)*(r0-20);
setcolor(14);
if(i%5==0)
circle(x,y,5);
else circle(x,y,2);
floodfill(x,y,14);
}
setlinestyle(0,0,3);
}
void sec(void) /******************************************************************/
{
int x,y,i,j,k,xj,yj,xk,yk,xi,yi,x0=320,y0=240,r0=150;
union REGS r;

unsigned char *shijie="";
unsigned char *daa="";
struct time tim;
struct date dat;
float alphai,alphak,alphaj,a0=90;
xi=x0;yi=y0;xj=x0;yj=y0;xk=x0;yk=y0;
do
{
/*intput the time*/
x=38;y=12;
gettime(&tim);
sprintf(shijie,"%02d:%02d:%02d",tim.ti_hour,tim.ti_min,tim.ti_sec);
setfillstyle(SOLID_FILL,0);
bar(245,190,375,210);
setcolor(15);
outtextxy(245,190,shijie);
/*input the date*/ /*****************************************************/
getdate(&dat);
sprintf(daa,"%02d--%02d--%02d",dat.da_year,dat.da_mon,dat.da_day);
/*setfillstyle(SOLID_FILL,3);*/
bar(225,290,395,310);
setcolor(RED);
outtextxy(225,290,daa);
x=190;y=430;
setcolor(RED);
outtextxy(x-26,y,"Designed by GuoLiuTa0");
setcolor(LIGHTRED);
outtextxy(x+76,y0+20,"NBA GAME");
setlinestyle(0,0,3);
k=tim.ti_hour;
j=tim.ti_min;
i=tim.ti_sec;
alphak=(a0+30*(12-k)-j*5/60.*6)*PI/180;
alphaj=(a0-6*j)*PI/180;
/*write second hand*/
alphai=(a0+6*(60-i))*PI/180;
x=x0+cos(alphai)*(r0-32);
y=y0-sin(alphai)*(r0-32);
setcolor(BLACK);
line(x0,y0,xi,yi);
setcolor(YELLOW);
line(x0,y0,x,y);
xi=x;
yi=y;
/*write minute hand*/
x=x0+cos(alphaj)*(r0-60);
y=y0-sin(alphaj)*(r0-60);
setcolor(BLACK);
line(x0,y0,xj,yj);
setcolor(BLUE);
line(x0,y0,x,y);
xj=x;
yj=y;
/*write hour hand*/
x=x0+cos(alphak)*(r0-99);
y=y0-sin(alphak)*(r0-99);
setcolor(BLACK);
line(x0,y0,xk,yk);
setcolor(RED);
line(x0,y0,x,y);
xk=x;
yk=y;
delay(10000);
}
while(!kbhit());
}

⑨ 怎麼用C語言編程數字時鍾

1、以下常式實現時鍾的實時顯示基本要求: 1) 自行設計界面,模擬表盤式時鍾。要求界面美觀,清晰。2)數字同步顯示時間信息。


2、常式:

#include<graphics.h>
#include<math.h>
#include<dos.h>
#definePI3.1415926
//屏幕中心的坐標(640X480模式下)
#definemid_x320
#definemid_y240
intmain()
{intgraphdriver=DETECT,graphmode;
intend_x,end_y;
structtimecurtime;
floatth_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屏幕,即返迴文本方式
return0;
}