这是我编的时钟程序,为什么指针有时会闪烁,我知道应该用双缓冲,但要怎么写啊,请各位大神说一下。。。
#include<stdio.h>#include"graphics.h"
#include<time.h>
#include<conio.h>
#include"math.h"
#include"dos.h"
#define pi 3.1415926
void set1()//画外围圈
{
setcolor(YELLOW);
setlinestyle(0,0,3);
circle(300,240,200);
setcolor(WHITE);
circle(300,240,220);
setfillstyle(1,3);
pieslice(300,30,0,360,10);
setfillstyle(1,2);
pieslice(300,450,0,360,10);
}
void set2()//画刻盘
{
int i,l,x1,x2,y1,y2;
for(i=0;i<60;i++)
{
if(i%5==0)
l=15;
else
l=5;
x1=200*sin(i*6*pi/180)+300;
y1=200*cos(i*6*pi/180)+240;
x2=(200-l)*sin(i*6*pi/180)+300;
y2=(200-l)*cos(i*6*pi/180)+240;
setcolor(YELLOW);
line(x1,y1,x2,y2);
}
}
void set3()//填数字
{
setcolor(GREEN);
settextstyle(0,0,2);
outtextxy(290,80,"12");
outtextxy(375,100,"1");
outtextxy(430,160,"2");
outtextxy(460,230,"3");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(295,390,"6");
outtextxy(220,370,"7");
outtextxy(160,310,"8");
outtextxy(140,230,"9");
outtextxy(157,155,"10");
outtextxy(215,95,"11");
}
int main()
{
int drive,mode;
int n1,n2,n3,h1,m1,s1,h2,m2,s2;
struct time *p;
drive=DETECT;
initgraph(&drive,&mode,"");
cleardevice();
set1();
set2();
set3();
while(!kbhit())
{
time_t t;
t=time(NULL);
p=localtime(&t);
n1=p->tm_sec;
n2=p->tm_min;
n3=p->tm_hour;
sound(1000);
delay(1000);
sound(1000);
nosound();
setfillstyle(1,0);
bar(200,150,290,200);
gotoxy(27,11);
printf("%d-%d-%d",1900+p->tm_year,1+p->tm_mon,p->tm_mday);
gotoxy(27,12);
printf("%d:%d:%d",p->tm_hour,p->tm_min,p->tm_sec);
h1=300+100*sin((n3+n2/60.0)*2*pi/12);
m1=300+150*sin(n2*2*pi/60);
s1=300+180*sin(n1*2*pi/60);
h2=240-100*cos((n3+n2/60.0)*2*pi/12);
m2=240-150*cos(n2*2*pi/60);
s2=240-180*cos(n1*2*pi/60);
setcolor(YELLOW);
line(300,240,h1,h2);
setcolor(RED);
line(300,240,m1,m2);
setcolor(BLUE);
line(300,240,s1,s2);
sleep(1);
setcolor(BLACK);
line(300,240,h1,h2);
line(300,240,m1,m2);
line(300,240,s1,s2);
}
getch();
closegraph();
return 0;
}
[ 本帖最后由 浪漫横行 于 2013-12-8 23:38 编辑 ]