# Make Analog Clock in C Using Graphics

In this tutorial you will learn how you can create an analog clock in C using graphics. This tutorial is written in a way that a beginner C graphics programmer can also understand.

Before getting into the main let me explain the functions I have used in the program.

clockLayout()
I’ve used this function to print the clock layout i.e. clock dial and the markings on the clock. If we observe clearly, the clock has hours marking each separated by 30 degrees and each hour is divided into 5 markings each making an angle of 6 degrees. So, iterating the markings for every 30 degrees gives hours and iterating markings with 6 degrees give minutes markings on the clock. The clock would look like this after executing this function.

secHand()
It is clear from the name that this gonna do something with the seconds hand. This function is going to get the present second from the system clock and incline the line according to a particular angle. Eg: if the present seconds is 5 then the angle of the seconds hand with respect to the vertical must be 30 degrees, i.e. 5*6=30.

minHand()
This function fulfills the task of moving the minutes hand based on the system clock. The minutes hand must be inclined 6 degrees for every minute passing. Eg: if the elapsed minutes are 30 then the minutes hand angle must be making 180 degrees with the vertical.

hrHand()
This function is going to print an inclined hours line. The function is designed to get the present hour and also the no. of elapsed minutes from the system clock and incline the line according to a particular angle. For every hour elapsed the hour hand moves 30 degrees and every 12 minutes it moves 6 degrees.

main()
The first lines in main are graphic initialization, you must change the path “c:\turboc3\bgi\” to your compiler’s BGI file path otherwise program will not work. Coming to the while loop, the while loop iterates for every 100 milliseconds reprinting all the functions. This program is like getting the static picture of clock every second and combining all the pictures to make a moving analog clock.

Also Read: Simple program to create a moving car in graphics

## Program for Analog Clock in C

Prathap is a passionate blogger and a very good programmer presently studying B.Tech in Computer Science. He is fascinated of latest technology, gadgets and also love to exploit technology and learn new tips and tricks in internet. He is the founder of Tech Google.

## 10 thoughts on “Make Analog Clock in C Using Graphics”

1. Dman

how would you go about changing the line drawn for the watch hands with pictures, such a .png?

2. Programmer

The output displays for a short period of time. Half a second I guess. Huhuhuh

3. Apurva

Hey I want to decrease the size and change the position of the clock so that i can show it as wall clock by giving a house background.

4. aashish kumar

the above written code of analog clock get comiled in my computer but whenever I try to run it it shows one error , it says– undefined symbol hrHand () in module

5. sk

Hi,
I need to get analog clock developed that has date, month, year hands along with hr, min, sec . Any way you could develop it? I can send more detail specs. I am prepared to pay for it.

Thanks.
Regards.
sk7403776@gmail.com

6. Raj

if u are still active on your blog , i’ve got his problem , i wann know how can i find the coordinates of the line whose length is of radius and also start from the center point of the circle i dont remember much of the trigonometry i learned in 10th basically i just wann create a for loop which prints the image like ashoka chakra from our nations flag i saw the formula you used but i dont have the angle and i didnt understood the way you get the angle so it’lll be really helpful if you elaborate it a little bit