本文目录一览:
C语言 用Devc++编一个图形时钟,要求能在devc++上运行的,简简单单的就可以了。
//图形库是EGE,下载后配置一下
#include iostream
#include "graphics.h"
#include math.h
#include time.h
#include windows.h
#define x0 210.0
#define y0 210.0
#define r 200.0
POINT pt[60],pt_s[60],pt_m[60],pt_h[60],pt1[60];
using namespace std;
int main()
{
initgraph(420,420);
setfillcolor(0xffccff);
setcolor(0xffccff);
fillellipse(x0,y0,10,10);
int s=45,m,h,n=0;
while(n60)
{
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(int i=0;i12;i++)
{
fillellipse(pt[i*5].x,pt[i*5].y,5,5);
}
int xs,ys,xm=-1,ym=-1,xh=-1,yh=-1;
while(1)
{
int n,m;
SYSTEMTIME st={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.wHour12)
{
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();
return 0;
}
用"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());
}
linux下怎样用c语言编写一个时钟
我希望你只是需要如何知道时间,而不是写你一个时钟程序,那个太复杂了,如果只是想如何知道时间-
#include stdio.h
#include time.h
int main(void)
{
struct tm *tm_ptr;
time_t the_time;
(void)time(the_time);
tm_ptr=localtime(the_time);
printf("Date: %04d/%02d/%02d\n",
1900+tm_ptr-tm_year,tm_ptr-tm_mon+1,tm_ptr-tm_mday);
printf("Time: %02d:%02d:%02d\n",
tm_ptr-tm_hour,tm_ptr-tm_min,tm_ptr-tm_sec);
return(0);
}