Analog-Digital clock with interactive animation using TurboC graphics.

0
432

Download Source Code

This is mini projects Analog and Digital clock with interactive animation for Turbo C / C++ graphics.

Background

Hello! This is a sample Clock application with animation that was my graduate level 3rd semester project and it was developed by TurboC compiler. Now I want to share my project with codeproject community. So Let get started…

Introduction

This article is for especially for student who are developing to interested mini project with help of TurboC graphics. My present project is a simple Clock application project that is developed by the TurboC graphics. In this project I was used keyboard event to control the interface and also shown some interactive animation for the turboC graphics.

Requirement

Firstly, you need to TurboC compiler to execute and run the code.

Secondly, to graphic mode functions require a graphics monitor (at least 640×480) and adapter card such as CGA, EGA and VGA.

Thirdly, to start graphics programming then you need two files which are GRAPHICS.H and GRAPHICS.LIB. These files are provided as part of TurboC compiler.

Graphics Initialization

As C Program execution starts with main() function similarly Graphics Environment Starts with the graphics initializes function. initgraph() initializes the graphics system by loading a graphics driver from disk then putting the system into graphics mode.

Initgraph() function accept three arguments; one is graphics driver(gd), second is graphics mode(gm) and third is path for bgi directory. The two int variables gd, gm are graphic driver and graphic mode respectively. The ” &” symbol is used for initgraph to pass address of the constants. Third variable specifies the directory path where initgraph looks for graphics drivers (*.BGI)

Following is the example code to draw a circle:-

Graphics Text

Different types of text can be set in your graphics window by using different graphics functions.
settextstyle() function set the current text characteristics. It accept three arguments: font, direction and charsize. setcolor() function set the number of a color from the 16 number of colors. outtextxy() function display an string for a particular (x,y) point. delay() function frizz the execution according to the argument in ms.

Time countdown animation for the intro project

Keyboard Event

To happen an event after press any key then you can use kbhit() function. And you can check the keyboard press by while kbhit()=0. Here I have shown an window that is will not be exits while kbhit() is false.

Event press for to start the clock

Interactive Animation

Here I have shown a spark star that include three stages. First is up a boll, second bust the ball and third widespread number of balls in a circle motion.

To up a ball from ground call init_circle() function. And secondly bust the ball call BIG_CIR() function. And at last widespread the numbers of ball in a circular direction.

Intro spark animation

Sound

Sound turns the PC speaker on at the specified frequency by the sound() function. Here I have generate a random value and play the corresponding oc[] array value where index value is previously generated an random value.

Clock background

Set background color red by the setfillstyle() function with solid fill in 2d bar. Next by the circular shape(using fillellipse() function) set dial border color yellow, set dial of the clock Light-blue, set inside of the clock dark-gray with solid fill by the setfillstyle() function.

Set clock time font

Now to show the clock time 12(XII), 3(III), 6(VI), 9(IX) using outtextxy() function and set the text color black using setcolor() function.

Set the date

First initialize the date, month, weekday as a string.

Now create an textbox for to show the Date like as Week_Day Name, Month_Name, Date, Year.

Load System time

Fetch the system date using gettime() function and second, minutes, hour can be store within a variable.

Get Hours, Minutes, Seconds

Now time to convert the second, minutes and hour to a string.

Rotate Hours, Minutes, Seconds hand

To rotate the clock second, minutes, hour hand, read the date from sec, min and hr variable. And rotate as a line using line() function which argument is depend on the time value.

The clock by the TurboC animation

Goodbye

After exiting the clock window are ready to uninstaling and unloading different properties. To show the different properties name text by using cprintf() function and set a color for the text by the textcolor() function and to set the background color is used to textbackground() function.

Here, cprintf() function sends formatted output to the text window on the screen and wherey() funciton gives current vertical cursor position.

System load and unload animation

Special note is that, actually here no one is uninstalling or unloading. It’s only for show :t :t

Now here is shown the ending text from the project. Using cprintf() function text is shown in the window, text color is set by the textcolor() function and text display pixel is shown by the gotoxy() function.

At last, “PRESS ANY KEY TO EXIT… …” text is blink. To do this change the screen mode in the text mode textmode() function. Go to pixel position 5,20 and set text color as a BLINK where text background color is set as black.

Outro Text by TurboC graphics

Conclusion

This is simple graphic application for Analog-Digital clock program. So download the source code and run it to enjoy. Happy Coding…

LEAVE A REPLY