arash مدير بخش سي
Joined: 27 Nov 2004 Posts: 1232 Location: www.parsx.com
|
Posted: Mon Oct 30, 2006 8:50 pm Post subject: |
|
|
|
//Programmed By : Himanshu Mishra
//Email ID : himanshu_mishra007@yahoo.co.in
/*Other Programmes: 1) SNAKEG
2) PIANO
*/
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
const float PI=3.141;
class needle
{
int size,color,x,y,end_x,end_y;
double theta;
public:
void draw(float,float);
void init(int a,int b,int c,int d)
{x=a;y=b;size=c;color=d;}
};
void needle::draw(float a,float b)
{
theta=(a*b-90)*(PI/180);
setcolor(0);
line(x,y,end_x,end_y);
setcolor(color);
end_x=x+cos(theta)*size;
end_y=y+sin(theta)*size;
line(x,y,end_x,end_y);
}
void main()
{
int d=DETECT,m;
initgraph(&d,&m,"c:\\tc\\bgi");
// setbkcolor(0);
int size=90,a;
float theta;
char tim[12][3]={"3","4","5","6","7","8","9","10","11","12","1","2"};
for(int i=0,j=0;i<360;i+=6)
{
theta=PI/180*i;
a=3;
if(i%5==0)
{
a=12;
outtextxy(320+cos(theta)*(size-a)-textwidth(tim[j])/2,240+sin(theta)*(size-a)-textheight(tim[j])/2,tim[j]);
j++;
a=8;
}
line(320+cos(theta)*(size-a),240+sin(theta)*(size-a),320+cos(theta)*size,240+sin(theta)*size);
}
circle(320,240,size+2);
circle(320,240,size+8);
setfillstyle(1,LIGHTBLUE);
floodfill(320,240+size+3,getcolor());
// setfillstyle(1,6);
// floodfill(0,0,getcolor());
outtext("Press any key to exit......");
needle second,minute,hour,milli;
second.init(320,240,60,BLUE);
minute.init(320,240,70,RED);
hour.init(320,240,40,LIGHTGRAY);
milli.init(320,240,65,6);
int sec,min,hr,hun,last_hun;
static char d_hr[3],d_min[3],d_sec[3],d_hun[3],time[20];
int d_x=275,d_y=120;
struct time t;
while(!kbhit())
{
gettime(&t);
hun=t.ti_hund;
sec=t.ti_sec;
min=t.ti_min;
hr=t.ti_hour;
if(hun!=last_hun)
{
//STARTING ANALOG CLOCK
setcolor(getbkcolor());
outtextxy(d_x,d_y,time);
setlinestyle(0,0,1);
milli.draw(hun,360/100);
second.draw(sec*100+hun,0.06);
setlinestyle(0,0,3);
minute.draw(min*60+sec,0.1);
hour.draw(hr*60+min,0.5);
//ENDING ANALOG CLOCK
//STARTING DIGITAL WATCH
itoa(hr,d_hr,10);
itoa(min,d_min,10);
itoa(sec,d_sec,10);
itoa(hun,d_hun,10);
time[0]=d_hr[0];
time[1]=d_hr[1];
time[2]=':';
time[3]=d_min[0];
time[4]=d_min[1];
time[5]=':';
time[6]=d_sec[0];
time[7]=d_sec[1];
time[8]='.';
time[9]=d_hun[0];
time[10]=d_hun[1];
for(int i=0;i<11;i++)
if(time[i]=='\0'){time[i]=time[i-1];time[i-1]='0';}
time[11]='\0';
setcolor(random(15));
outtextxy(d_x,d_y,time);
//ENDING DIGITAL WATCH
}
last_hun=hun;
}
closegraph();
}
|
|
|