CG Project
CG Project
A Project submitted on
Implementation of a 3D Clock
by
Submitted to
SPRING 2024
Serial number Heading Page no.
1. Abstract 3
2. Introduction 4
3. Implementation 5-7
4. Source code 8-11
5. Output 12
6. Conclusion 12
Abstract :
The provided code implements an analog clock using the Turbo C graphics library. It
calculates the positions of the clock numbers and the positions of the clock hands
(hour, minute, and second) based on trigonometric functions. The calcPoints
function determines the positions for the clock numbers and the hour hand, while the
minSecCalc() function calculates the positions for the minute and second hands.
The main function initializes the graphics mode, calculates the midpoint of the
screen, and sets the radius of the clock. In a continuous loop, the program updates the
clock hands to reflect the current time using the time() and localtime()
functions. It draws the clock hands for seconds, minutes, and hours, and then updates
the display every second. The loop terminates when a key is pressed, and the graphics
mode is closed. This code demonstrates the use of graphics programming in C to
create a functional analog clock.
Introduction:
The Real-time Clock Simulation project aims to create a digital clock using C programming
language and graphics libraries. This project leverages concepts such as trigonometry, time
management, and graphical user interface (GUI) programming to simulate the behaviour of a real-
world clock on a computer screen.
The key features of this clock simulation include:
1. Real-time Updates: The clock updates in real-time, displaying the current hour, minute, and
second accurately.
2. Graphical Representation: The clock is visually represented with hour, minute, and second
needles, along with numerals for each hour on the clock face.
3. User Interaction: Users can interact with the clock by observing the time change
dynamically or by pausing the simulation.
4. Educational Value: This project serves as an educational tool for understanding concepts
such as graphics programming, time management, and mathematical calculations involved
in clock simulations.
By implementing this project, developers can enhance their skills in C programming, graphics
handling, and real-time data management, making it a valuable learning experience and a visually
appealing application.
Implementation Details: Real-time Clock Simulation
1. Header Files:
2. Graphics Initialization:
• Initialize the graphics mode using initgraph function and handle any errors using
graphresult to ensure the graphics environment is set up correctly.
3. Clock Elements Calculation:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <graphics.h>
#include <dos.h>
/*
* find the points at 0, 30, 60,.., 360 degrees
* on the given circle. x value correponds to
* radius * cos(angle) and y value corresponds
* to radius * sin(angle). Numbers in the clock
* are written using the above manipulated x and
* y values. And the hour needle movement
* is based on this
*/
void calcPoints(int radius, int midx, int midy, int x[12], int y[12]) {
int x1, y1;
return;
}
/*
* Calculates position for minute and second needle movement
* Each quadrant has 90 degrees. So, we need to split each
* quadrant into 15 parts(6 degree each) to get the minute
* and second needle movement
*/
void minSecCalc(int radius, int midx, int midy, int secx[60], int secy[60]) {
int i, j = 0, x, y;
char str[32];
return;
}
int main() {
/* request auto detection */
int gdriver = DETECT, gmode, err, tmp;
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;
if (err != grOk) {
/* error occurred */
printf("Graphics Error: %s",
grapherrormsg(err));
return 0;
}
radius = 200;
while (!kbhit()) {
setlinestyle(SOLID_LINE, 1, 3);
settextstyle(TRIPLEX_FONT, 0, 3);
getch();
Conclusion: