Simple Analogue Clock with C\C++ : The following , is a simple analogue clock , created , using the BGI graphics library of Turbo C/C++ 3.0 :
While running this program , make sure using correct path for the BGI graphics driver .For example : if Turbo C/C++ is installed in the following location "C:\TC" , then the BGI graphics path should be "C:\\TC\\BGI" :
Screenshot :
C++ Code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
#include<math.h>
#define cx 320
#define cy 140
#define r 66
#define r1 48
#define r2 37
void second(int x,int y,int x1,int y1,int color);
void minute(int x,int y,int x1,int y1,int color);
void hour(int x,int y,int x1,int y1,int color);
void address(void);
int d(void);
char ch_t[40];
char ch_d[40];
char myear[5];
char mmonth[5];
char mday[5];
void initialize()
{
int gd=DETECT,gm=0;
initgraph(&gd,&gm,"F:\\TC\\BGI");
}
void main()
{
initialize();
int i=320;
cleardevice();
setbkcolor(0);
setcolor(8);
settextstyle(0,0,2);
outtextxy(126,400,"CREATED BY:");
setcolor(9);
settextstyle(0,0,3);
outtextxy(150,440,"MD. MOHIUDDIN AHMED");
setcolor(3);
rectangle(190,30,460,250);
rectangle(195,35,455,245);
rectangle(192,32,458,248);
setcolor(8);
ellipse(i,140,0,360,110,81);
ellipse(i,140,0,360,104,81);
ellipse(i,140,0,360,102,81);
ellipse(i,140,0,360,114,81);
ellipse(i,140,0,360,100,81);
ellipse(i,140,0,360,112,81);
ellipse(i,140,0,360,116,81);
ellipse(i,140,0,360,106,81);
ellipse(i,140,0,360,108,81);
setcolor(6);
settextstyle(0,0,1);
outtextxy(314,64,"12");
outtextxy(273,77,"11");
outtextxy(243,101,"10");
outtextxy(230,137,"9");
outtextxy(250,172,"8");
outtextxy(280,199,"7");
outtextxy(316,210,"6");
outtextxy(355,199,"5");
outtextxy(385,172,"4");
outtextxy(400,137,"3");
outtextxy(383,101,"2");
outtextxy(359,76,"1");
address();
d();
getch();
closegraph();
restorecrtmode();
}
void second(int x,int y,int x1,int y1,int color)
{
setcolor(color);
line(x,y,x1,y1);
}
void minute(int x,int y,int x1,int y1,int color)
{
setcolor(color);
line(x,y,x1,y1);
}
void hour(int x,int y,int x1,int y1,int color)
{
setcolor(color);
line(x,y,x1,y1);
}
int d()
{
int x=cx,y=cy-r,y1=cy-r1,y2=cy-r2;
char ch=0;
int new_x_s=cx,new_y_s=cy,new_x_m=cx;
int new_y_m=cy,new_x_h=cx,new_y_h=cy;
float theta;
struct dosdate_t d;
struct dostime_t t;
while(!kbhit())
{
_dos_getdate(&d);
_dos_gettime(&t);
itoa(d.year,myear,10);
itoa(d.month,mmonth,10);
itoa(d.day,mday,10);
settextstyle(11,0,9);
outtextxy(280-50,270,"CURRENT YEAR:");
outtextxy(280-50,290,"CURRENT MONTH:");
outtextxy(280-50,310,"CURRENT DAY:");
outtextxy(280+70,270,myear);
outtextxy(280+70,290,mmonth);
outtextxy(280+70,310,mday);
setcolor(3);
settextstyle(0,0,2);
outtextxy(150,340,"Date:");
outtextxy(240,340,mday);
outtextxy(269,340,"-");
outtextxy(283,340,mmonth);
outtextxy(322,340,"-");
outtextxy(350,340,myear);
setcolor(11);
if(ch!=t.second)
{
circle(cx,cy,1);
setlinestyle(0,1,1);
second(cx,cy,new_x_s,new_y_s,0);
//----------------------------------------STARTS
theta=(3.1415962*6*t.second)/180;
new_x_s=x+r*sin(theta);
new_y_s=y+r*(1-cos(theta));
second(cx,cy,new_x_s,new_y_s,11);
//----------------------------------------ENDS
sound(246.94*15);
delay(20);
nosound();
setlinestyle(0,1,3);
ch=t.second;
minute(cx,cy,new_x_m,new_y_m,0);
theta=(3.1415962*6*t.minute)/180;
new_x_m=x+r1*sin(theta);
new_y_m=y1+r1*(1-cos(theta));
minute(cx,cy,new_x_m,new_y_m,11);
hour(cx,cy,new_x_h,new_y_h,0);
theta=(3.1415962*30*t.hour)/180+(3.1415962*0.5*t.minute)/180;
new_x_h=x+r2*sin(theta);
new_y_h=y2+r2*(1-cos(theta));
hour(cx,cy,new_x_h,new_y_h,11);
}
}
return 0;
}
void address(void)
{
setcolor(6);
rectangle(107,255,539,330);
rectangle(109,257,537,328);
rectangle(110,258,536,327);
}
No comments:
Post a Comment