Making Analogue Clock with C-Language using Graphics

Hi Friends here is another small project Analogue Clock made with C-Language. Here I have used Graphics of turbo C, and for the hand of houres and minute and second use pie slice.

Screenshot:

Code for Analogue Clock.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<alloc.h>
#include<dos.h>
#include<graphics.h>
void main(void)
{
char choice; /*--variable for input choice--*/
int gdriver =DETECT, gmode; /*--select driver & mode--*/
float red1=100,stan=90,endan=91,mred=80,hred=50,mstar=90,mend=92,hstar=60,hend=63;
int md=300,sd=17,hd=1,red=90;
struct time t;
gettime(&t);
stan=stan-(t.ti_sec*6);
stan=stan-16;
endan=stan+1;
mstar=mstar-(t.ti_min*6);
mstar=mstar-2;
mend=mstar+2;
hstar=hstar-(t.ti_hour*30);
hstar=hstar-(t.ti_min*0.1)+14;
hend=hstar+3;
clrscr();
initgraph(&gdriver, &gmode, "c:\\TURBOC3/BGI/"); //Change as per your turbo C Graphics Path /*--initialized driver--*/
setfillstyle(SOLID_FILL,WHITE);
bar(0,0,getmaxx(),getmaxy());
setfillstyle(SOLID_FILL,BLUE);
// bar(3,1,635,17);
setfillstyle(SOLID_FILL,LIGHTBLUE);
setcolor(RED);
outtextxy(getmaxx()/2-10,130,"12");
outtextxy(210,getmaxy()/2,"9");
outtextxy(getmaxx()/2-10,340,"6");
outtextxy(420,getmaxy()/2,"3");
circle(getmaxx()/2,getmaxy()/2,red1+11);
setcolor(WHITE);
while(!kbhit())
{
gettime(&t);
gotoxy(3,10);
printf("time is: %2d:%02d:%02d.%02d\n",t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
setfillstyle(SOLID_FILL,LIGHTBLUE);
fillellipse(getmaxx()/2,getmaxy()/2,red1,red1);
setcolor(YELLOW);
outtextxy(280,getmaxy()/2-50,"Subu Watch");
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
pieslice(getmaxx()/2,getmaxy()/2,stan,endan,red);
pieslice(getmaxx()/2,getmaxy()/2,mstar,mend,mred);
pieslice(getmaxx()/2,getmaxy()/2,hstar,hend,hred);
delay(1000);
setfillstyle(SOLID_FILL,LIGHTGREEN);
setcolor(YELLOW);
outtextxy(280,getmaxy()/2-50,"Subu Watch");
setcolor(WHITE);
pieslice(getmaxx()/2,getmaxy()/2,stan,endan,red);
pieslice(getmaxx()/2,getmaxy()/2,mstar,mend,mred);
pieslice(getmaxx()/2,getmaxy()/2,hstar,hend,hred);
stan=stan-6;
endan=endan-6;
mstar=mstar-0.1;
mend=mend-0.1;
hstar=hstar-(0.1/60);
hend=hend-(0.1/60);
}
getch();
}
#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> #include<alloc.h> #include<dos.h> #include<graphics.h> void main(void) { char choice; /*--variable for input choice--*/ int gdriver =DETECT, gmode; /*--select driver & mode--*/ float red1=100,stan=90,endan=91,mred=80,hred=50,mstar=90,mend=92,hstar=60,hend=63; int md=300,sd=17,hd=1,red=90; struct time t; gettime(&t); stan=stan-(t.ti_sec*6); stan=stan-16; endan=stan+1; mstar=mstar-(t.ti_min*6); mstar=mstar-2; mend=mstar+2; hstar=hstar-(t.ti_hour*30); hstar=hstar-(t.ti_min*0.1)+14; hend=hstar+3; clrscr(); initgraph(&gdriver, &gmode, "c:\\TURBOC3/BGI/"); //Change as per your turbo C Graphics Path /*--initialized driver--*/ setfillstyle(SOLID_FILL,WHITE); bar(0,0,getmaxx(),getmaxy()); setfillstyle(SOLID_FILL,BLUE); // bar(3,1,635,17); setfillstyle(SOLID_FILL,LIGHTBLUE); setcolor(RED); outtextxy(getmaxx()/2-10,130,"12"); outtextxy(210,getmaxy()/2,"9"); outtextxy(getmaxx()/2-10,340,"6"); outtextxy(420,getmaxy()/2,"3"); circle(getmaxx()/2,getmaxy()/2,red1+11); setcolor(WHITE); while(!kbhit()) { gettime(&t); gotoxy(3,10); printf("time is: %2d:%02d:%02d.%02d\n",t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); setfillstyle(SOLID_FILL,LIGHTBLUE); fillellipse(getmaxx()/2,getmaxy()/2,red1,red1); setcolor(YELLOW); outtextxy(280,getmaxy()/2-50,"Subu Watch"); setcolor(WHITE); setfillstyle(SOLID_FILL,RED); pieslice(getmaxx()/2,getmaxy()/2,stan,endan,red); pieslice(getmaxx()/2,getmaxy()/2,mstar,mend,mred); pieslice(getmaxx()/2,getmaxy()/2,hstar,hend,hred); delay(1000); setfillstyle(SOLID_FILL,LIGHTGREEN); setcolor(YELLOW); outtextxy(280,getmaxy()/2-50,"Subu Watch"); setcolor(WHITE); pieslice(getmaxx()/2,getmaxy()/2,stan,endan,red); pieslice(getmaxx()/2,getmaxy()/2,mstar,mend,mred); pieslice(getmaxx()/2,getmaxy()/2,hstar,hend,hred); stan=stan-6; endan=endan-6; mstar=mstar-0.1; mend=mend-0.1; hstar=hstar-(0.1/60); hend=hend-(0.1/60); } getch(); }
 #include<stdio.h>
 #include<conio.h>
 #include<stdlib.h>
 #include<string.h>
 #include<alloc.h>
 #include<dos.h>
 #include<graphics.h>




 void main(void)
 {
	char choice;                 /*--variable for input choice--*/
	int gdriver =DETECT, gmode;            /*--select driver & mode--*/
		 float red1=100,stan=90,endan=91,mred=80,hred=50,mstar=90,mend=92,hstar=60,hend=63;
	int md=300,sd=17,hd=1,red=90;
	struct time t;
	gettime(&t);
	stan=stan-(t.ti_sec*6);
	stan=stan-16;
	endan=stan+1;
	mstar=mstar-(t.ti_min*6);
	mstar=mstar-2;
	mend=mstar+2;
	hstar=hstar-(t.ti_hour*30);
	hstar=hstar-(t.ti_min*0.1)+14;
	hend=hstar+3;
	clrscr();
	initgraph(&gdriver, &gmode, "c:\\TURBOC3/BGI/");   //Change as per your turbo C Graphics Path        /*--initialized driver--*/
	setfillstyle(SOLID_FILL,WHITE);
	bar(0,0,getmaxx(),getmaxy());
	setfillstyle(SOLID_FILL,BLUE);
		 //	bar(3,1,635,17);
	setfillstyle(SOLID_FILL,LIGHTBLUE);
	setcolor(RED);
	outtextxy(getmaxx()/2-10,130,"12");
	outtextxy(210,getmaxy()/2,"9");
	outtextxy(getmaxx()/2-10,340,"6");
	outtextxy(420,getmaxy()/2,"3");
	circle(getmaxx()/2,getmaxy()/2,red1+11);
	setcolor(WHITE);

	while(!kbhit())
	{
		gettime(&t);
	gotoxy(3,10);
	 printf("time is: %2d:%02d:%02d.%02d\n",t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
		setfillstyle(SOLID_FILL,LIGHTBLUE);
		fillellipse(getmaxx()/2,getmaxy()/2,red1,red1);
		setcolor(YELLOW);
		outtextxy(280,getmaxy()/2-50,"Subu Watch");
		setcolor(WHITE);
		setfillstyle(SOLID_FILL,RED);
		pieslice(getmaxx()/2,getmaxy()/2,stan,endan,red);
		pieslice(getmaxx()/2,getmaxy()/2,mstar,mend,mred);
		pieslice(getmaxx()/2,getmaxy()/2,hstar,hend,hred);
		delay(1000);
		setfillstyle(SOLID_FILL,LIGHTGREEN);
		setcolor(YELLOW);
		outtextxy(280,getmaxy()/2-50,"Subu Watch");
		setcolor(WHITE);
		pieslice(getmaxx()/2,getmaxy()/2,stan,endan,red);
		pieslice(getmaxx()/2,getmaxy()/2,mstar,mend,mred);
		pieslice(getmaxx()/2,getmaxy()/2,hstar,hend,hred);
		stan=stan-6;
		endan=endan-6;

		mstar=mstar-0.1;
		mend=mend-0.1;
		hstar=hstar-(0.1/60);
		hend=hend-(0.1/60);

	}
	getch();
 }


 

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.