标题:有关时钟的程序
只看楼主
maqingqin
Rank: 1
等 级:新手上路
帖 子:23
专家分:4
注 册:2010-2-1
结帖率:0
 问题点数:0 回复次数:3 
有关时钟的程序
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#define PI 3.1415926
#include <math.h>
#include <dos.h>
#include <stdlib.h>
#define GETX(a,l) l*sin(PI-a*PI/30)+320 /*取得以320,240为圆心,l为半径,a*PI/30为偏移角度(以y正轴为准)的圆上的x坐标*/
#define GETY(a,l) l*cos(PI-a*PI/30)+240 /*取得以320,240为圆心,l为半径,a*PI/30为偏移角度(以y正轴为准)的圆上的y坐标*/




void xianshi(int x,int y,int number,int w)
{ switch(number)
    {case 0:{line(x,y,x+w,y); /*1*/
            line(x,y,x,y+w); /*2*/
            line(x,y+w,x,y+2*w); /*3*/
            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/
            /*line(x,y+w,x+w,y+w);7*/ }

            break;

    case 1:{line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/}
            break;
    case 2:{line(x,y,x+w,y); /*1*/
            line(x,y+w,x,y+2*w); /*3*/
            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+w,x+w,y); /*6*/
            line(x,y+w,x+w,y+w);/*7*/
            }

            break;

    case 3:{line(x,y,x+w,y); /*1*/

            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/
            line(x,y+w,x+w,y+w); /*7*/}

            break;

    case 4:{
            line(x,y,x,y+w); /*2*/

            line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/
            line(x,y+w,x+w,y+w); /*7*/}

            break;

    case 5:{line(x,y,x+w,y); /*1*/
            line(x,y,x,y+w); /*2*/

            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+2*w,x+w,y+w); /*5*/

            line(x,y+w,x+w,y+w); /*7*/}

            break;

    case 6:{line(x,y,x+w,y); /*1*/
            line(x,y,x,y+w); /*2*/
            line(x,y+w,x,y+2*w); /*3*/
            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+2*w,x+w,y+w); /*5*/

            line(x,y+w,x+w,y+w); /*7*/}

            break;

    case 7:{line(x,y,x+w,y); /*1*/


            line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/
            }

            break;

    case 8:{line(x,y,x+w,y); /*1*/
            line(x,y,x,y+w); /*2*/
            line(x,y+w,x,y+2*w); /*3*/
            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/
            line(x,y+w,x+w,y+w); /*7*/}

            break;

    case 9:{line(x,y,x+w,y); /*1*/
            line(x,y,x,y+w); /*2*/
            line(x,y+2*w,x+w,y+2*w); /*4*/
            line(x+w,y+2*w,x+w,y+w); /*5*/
            line(x+w,y+w,x+w,y); /*6*/
            line(x,y+w,x+w,y+w); /*7*/}

            break;
      }
}



/*图形初始化函数定义*/
void Init()
{int gdriver, gmode;
 /*registerbgidriver(EGAVGA_driver);*/
gdriver=DETECT;
initgraph(&gdriver, &gmode, "c:\\tc");
}

main()
{ float jiao;
 int i=0,r;
 int h,m,s;

 struct time t;
 Init();
     rectangle(15,15,120,45);
    /*circle(320,240,2);*/
    setcolor(4);
     for(jiao=PI,i=0;i<60;i++,jiao-=PI/30)
     {if(i%5==0)
        r=7;
      else
        r=2;

         {setfillstyle(1,random(15));
          circle(200*sin(jiao)+320,200*cos(jiao)+240,r);
          floodfill(200*sin(jiao)+320,200*cos(jiao)+240,4);}/*画周边的60个圆(12个半径为7的大圆,48个半径为2的小圆)*/
      }


               {gettime(&t);
                h=t.ti_hour;
                m=t.ti_min;
                s=t.ti_sec;}
             setcolor(4);
            settextstyle(0,0,1);
            outtextxy(490,410,"myname:maqingqin");
             setcolor(3);
            outtextxy(500,430,"QICQ:812154952");

     do{

            {setcolor(4);
             setlinestyle(0,0,3);
             settextstyle(0,0,2);
             outtextxy(308,60,"12");}


             if(h<10)
               {xianshi(20,20,0,10);
                xianshi(35,20,h,10);}

             else
                {xianshi(20,20,h/10,10);
                 xianshi(35,20,h%10,10);}

               {line(50,24,50,27);
                line(50,34,50,37);}



               if(m>=0&&m<12)


                         {setcolor(4);
                          setlinestyle(0,0,3);
                          line(320,240,GETX(h*5,100),GETY(h*5,100));}


                else  if(m>=12&&m<24)


                          {setcolor(4);
                           setlinestyle(0,0,3);
                           line(320,240,GETX((h*5+1),100),GETY((h*5+1),100));}


                       else if(m>=24&&m<36)


                               {setcolor(4);
                                setlinestyle(0,0,3);
                                line(320,240,GETX((h*5+2),100),GETY((h*5+2),100)); }



                             else if(m>=36&&m<48)


                                      {setcolor(4);
                                       setlinestyle(0,0,3);
                                       line(320,240,GETX((h*5+3),100),GETY((h*5+3),100));}

                                   else

                                        {setcolor(4);
                                         setlinestyle(0,0,3);
                                         line(320,240,GETX((h*5+4),100),GETY((h*5+4),100));}
                                         /*画时钟的位置*/





             setcolor(5);
             outtextxy(315,410,"6");

             if(m<10)
               {xianshi(55,20,0,10);
                xianshi(70,20,m,10);}
             else
                {xianshi(55,20,m/10,10);
                 xianshi(70,20,m%10,10);}

                {line(85,24,85,27);
                 line(85,34,85,37);}


             setlinestyle(0,0,3);
             line(320,240,GETX(m,150),GETY(m,150));/*画时钟的分针*/


             setcolor(3);
             outtextxy(140,235,"9");
             outtextxy(490,235,"3");

             if(s<10)
               {xianshi(90,20,0,10);
                xianshi(105,20,s,10);}
             else
                {xianshi(90,20,s/10,10);
                 xianshi(105,20,s%10,10);}


             setlinestyle(0,0,1);
             line(320,240,GETX(s,192),GETY(s,192)); /*画时钟的秒针*/


             gettime(&t);

             switch(t.ti_min)
             { case 0: if(t.ti_sec==0)
                       {setcolor(0);
                       setlinestyle(0,0,3);
                       line(320,240,GETX((h*5-1),100),GETY((h*5-1),100));}

                  break;
                case 12: if(t.ti_sec==0)
                        {setcolor(0);
                         setlinestyle(0,0,3);
                          line(320,240,GETX((h*5),100),GETY((h*5),100));}

                   break;
                 case 24:{setcolor(0);
                         setlinestyle(0,0,3);
                          line(320,240,GETX((h*5+1),100),GETY((h*5+1),100));}

                    break;

                 case 36:if(t.ti_sec==0)
                         {setcolor(0);
                         setlinestyle(0,0,3);
                          line(320,240,GETX((h*5+2),100),GETY((h*5+2),100));}

                    break;
                 case 48:if(t.ti_sec==0)
                         {setcolor(0);
                         setlinestyle(0,0,3);
                          line(320,240,GETX((h*5+3),100),GETY((h*5+3),100));}

                    break;

                  default:break;
                }


           if(t.ti_hour!=h)
           {setcolor(0);
            setlinestyle(0,0,3);

            if(h<10)
               {xianshi(20,20,0,10);
                xianshi(35,20,h,10);}
             else
                {xianshi(20,20,h/10,10);
                 xianshi(35,20,h%10,10);}



            h=t.ti_hour;}

            if(t.ti_min!=m)
            {setcolor(0);
             setlinestyle(0,0,3);


             if(m<10)
               {  if(t.ti_min/10!=m/10)
                    xianshi(55,20,0,10);
                 xianshi(70,20,m,10);}
             else
                {if(t.ti_min/10!=m/10)
                    xianshi(55,20,m/10,10);
                 xianshi(70,20,m%10,10);}

             line(320,240,GETX(m,150),GETY(m,150));


             m=t.ti_min;}

            if(t.ti_sec!=s)
            { setcolor(0);
             setlinestyle(0,0,3);
            if(s<10)
               { if(t.ti_sec/10!=s/10)
                    xianshi(90,20,0,10);
                 xianshi(105,20,s,10);}
             else
                { if(t.ti_sec/10!=s/10)
                     xianshi(90,20,s/10,10);
                  xianshi(105,20,s%10,10);}

              /*sound(500);
              delay(500);
              nosound();*/
             setlinestyle(0,0,1);
             line(320,240,GETX(s,192),GETY(s,192));

             s=t.ti_sec;}

        }while(!kbhit());/*当有按键被按下就退出*/
 
   closegraph();

  }
搜索更多相关主题的帖子: 时钟 
2010-02-05 11:00
纯洁
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-7-21
得分:0 
收下了,楼主辛苦了
2010-07-21 01:32
maqingqin
Rank: 1
等 级:新手上路
帖 子:23
专家分:4
注 册:2010-2-1
得分:0 
给你们看看效果
MYSHIZ~1.rar (32.72 KB)
2010-08-17 11:00
快乐小混
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-10-24
得分:0 
#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;
 initgraph(&gd,&gm,"d:\\tc"); /*初始化图形系统*/
init();
setwritemode(1);
 gettime(&t); /*读取系统时间*/
 h=t.ti_hour;
 m=t.ti_min;
 s=t.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.ti_sec==s)
 gettime(&t);
 sound(400);
delay(70);
 sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t.ti_sec;
 d(190,s,6);
if (t.ti_min!=m)
 {
setcolor(14);
d(170,m,6);
m=t.ti_min;
 d(170,m,6);
}
if (t.ti_hour!=h)
 { setcolor(7);
d(150,h,30);
h=t.ti_hour;
 d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch();
closegraph(); /*关闭图形系统*/
}
2012-06-03 10:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-297290-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.393884 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved