/*Program for analog CLock*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <graphics.h>
#include <time.h>
#include <dos.h>
void minSecPos(int xrad, int midx, int midy, int x[60], int y[60])
{
int i, j=45;
for (i=360; i>=0; i=i-6)
{
x[j] = midx-(xrad*cos((i*3.14)/180));
y[j--] = midy-(xrad*sin((i*3.14)/180));
j = (j==-1)?59:j;
}
return;
}
void calcPoints(int radius, int midx, int midy, int x[12], int y[12])
{
int x1, y1;
x[0] = midx, y[0] = midy-radius;
x[6] = midx, y[6] = midy+radius;
x[3] = midx+radius, y[3] = midy;
x[9] = midx-radius, y[9] = midy;
x1 = (int) ((radius/2)*sqrt(3));
y1 = (radius/2);
x[2] = midx+x1, y[2] = midy-y1;
x[4] = midx+x1, y[4] = midy+y1;
x[8] = midx-x1, y[8] = midy+y1;
x[10] = midx-x1, y[10] = midy-y1;
x1 = radius/2;
y1 = (int) ((radius/2)*sqrt(3));
x[1] = midx+x1, y[1] = midy-y1;
x[5] = midx+x1, y[5] = midy+y1;
x[7] = midx-x1, y[7] = midy+y1;
x[11] = midx-x1, y[11] = midy-y1;
return;
}
int main() {
int gd=DETECT, gm, err, tmp;
initgraph(&gd, &gm, "C:\\tc\\bgi");
int i, j, midx, midy, radius, hr, min, sec;
int x[12], y[12], minx[60], miny[60];
int hrx[12], hry[12], secx[60], secy[60];
int secx1, secy1;
char str[256];
time_t t1;
struct tm*data;
err = graphresult();
if (err != grOk)
{
printf("Graphics Error: %s",
grapherrormsg(err));
return 0;
}
midx = getmaxx()/2;
midy = getmaxy()/2;
radius = 200;
calcPoints(radius-30, midx, midy, x, y);
calcPoints(radius-90, midx, midy, hrx, hry);
minSecPos(radius-50, midx, midy, minx, miny);
minSecPos(radius-70, midx, midy, secx, secy);
while (!kbhit())
{
setlinestyle(SOLID_LINE, 1, 3);
settextstyle(GOTHIC_FONT, 0, 3);
circle(midx, midy, radius);
for (j=0; j<12; j++)
{
if (j==0)
{
sprintf(str, "%d", 12);
} else {
sprintf(str, "%d", j);
}
settextjustify(CENTER_TEXT, CENTER_TEXT);
moveto(x[j], y[j]);
outtext(str);
}
t1 = time(NULL);
data = localtime(&t1);
sec = data->tm_sec % 60;
line(midx, midy,
[sec], secy[sec]);
min = data->tm_min % 60;
line(midx, midy, minx[min], miny[min]);
hr = data->tm_hour % 12;
line(midx, midy, hrx[hr], hry[hr]);
delay(1000);
cleardevice();
}
getch();
closegraph();
return 0;
}
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <graphics.h>
#include <time.h>
#include <dos.h>
void minSecPos(int xrad, int midx, int midy, int x[60], int y[60])
{
int i, j=45;
for (i=360; i>=0; i=i-6)
{
x[j] = midx-(xrad*cos((i*3.14)/180));
y[j--] = midy-(xrad*sin((i*3.14)/180));
j = (j==-1)?59:j;
}
return;
}
void calcPoints(int radius, int midx, int midy, int x[12], int y[12])
{
int x1, y1;
x[0] = midx, y[0] = midy-radius;
x[6] = midx, y[6] = midy+radius;
x[3] = midx+radius, y[3] = midy;
x[9] = midx-radius, y[9] = midy;
x1 = (int) ((radius/2)*sqrt(3));
y1 = (radius/2);
x[2] = midx+x1, y[2] = midy-y1;
x[4] = midx+x1, y[4] = midy+y1;
x[8] = midx-x1, y[8] = midy+y1;
x[10] = midx-x1, y[10] = midy-y1;
x1 = radius/2;
y1 = (int) ((radius/2)*sqrt(3));
x[1] = midx+x1, y[1] = midy-y1;
x[5] = midx+x1, y[5] = midy+y1;
x[7] = midx-x1, y[7] = midy+y1;
x[11] = midx-x1, y[11] = midy-y1;
return;
}
int main() {
int gd=DETECT, gm, err, tmp;
initgraph(&gd, &gm, "C:\\tc\\bgi");
int i, j, midx, midy, radius, hr, min, sec;
int x[12], y[12], minx[60], miny[60];
int hrx[12], hry[12], secx[60], secy[60];
int secx1, secy1;
char str[256];
time_t t1;
struct tm*data;
err = graphresult();
if (err != grOk)
{
printf("Graphics Error: %s",
grapherrormsg(err));
return 0;
}
midx = getmaxx()/2;
midy = getmaxy()/2;
radius = 200;
calcPoints(radius-30, midx, midy, x, y);
calcPoints(radius-90, midx, midy, hrx, hry);
minSecPos(radius-50, midx, midy, minx, miny);
minSecPos(radius-70, midx, midy, secx, secy);
while (!kbhit())
{
setlinestyle(SOLID_LINE, 1, 3);
settextstyle(GOTHIC_FONT, 0, 3);
circle(midx, midy, radius);
for (j=0; j<12; j++)
{
if (j==0)
{
sprintf(str, "%d", 12);
} else {
sprintf(str, "%d", j);
}
settextjustify(CENTER_TEXT, CENTER_TEXT);
moveto(x[j], y[j]);
outtext(str);
}
t1 = time(NULL);
data = localtime(&t1);
sec = data->tm_sec % 60;
line(midx, midy,
[sec], secy[sec]);
min = data->tm_min % 60;
line(midx, midy, minx[min], miny[min]);
hr = data->tm_hour % 12;
line(midx, midy, hrx[hr], hry[hr]);
delay(1000);
cleardevice();
}
getch();
closegraph();
return 0;
}
Output:
awesome !!
ReplyDeletethanks a lot.. great work!
ReplyDeleteawesome
ReplyDeleteNo errors but..not running the clock..while clicking on run it automatically exits.. :(
ReplyDeleteplease make your graphic path right if you get error
ReplyDeletehey bro you got a minor error out there:
ReplyDeleteline(midx, midy,secx
[sec], secy[sec]);
in the last
yes
Deletemake it line(midx, midy, secx[sec], secy[sec]); delete the space
DeleteBro t1 undefined symbol telling bro what should i do
ReplyDeleteNo errors but..not running the clock..while clicking on run it automatically exits.
ReplyDeleteclock is showing errors
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSource code plz
ReplyDeleteSource code plz
ReplyDeletehe just forgot
ReplyDeletemade this line
it will work
line(midx, midy, secx[sec], secy[sec]);
what? hhhh
Deletesaya sangat terkesan dengan program ini! pemikiran luar biasa, trimakasih salam saya dari indonesia!
ReplyDeleteBro i need answer for some can you slove it
ReplyDeleteBro i need source code to make analog clock in c oc c++
ReplyDeleteThe number 8 is missing in my clock
ReplyDeleteError hai expression syntax or while statement missing
ReplyDeletesetcolor(BLACK);
ReplyDeleteline(midx, midy, secx[sec], secy[sec]);
sec = data->tm_sec % 60;
setcolor(WHITE);
line(midx, midy, secx[sec], secy[sec]);
if (sec == 0)
{
setcolor(BLACK);
line(midx, midy, minx[min], miny[min]);
}
min = data->tm_min % 60;
setcolor(WHITE);
line(midx, midy, minx[min], miny[min]);
if (min == 0)
{
setcolor(BLACK);
line(midx, midy, hrx[hr], hry[hr]);
}
hr = data->tm_hour % 12;
setcolor(WHITE);
line(midx, midy, hrx[hr], hry[hr]);
delay(1000);
/* cleardevice(); <-- Causes flicker */