Professional Documents
Culture Documents
CHAPTER - 1
INTRODUCTION
1.1 Aim of the project
1.3 Outcome
Creation of a visually accurate and interactive analog clock: The project may
result in the development of a program or application that accurately represents an
analog clock, including the movement of the hour, minute, and second hands. Users
may be able to interact with the clock, such as setting the time or changing the clock
face design.
CHAPTER – 2
Step 2:
Initialize Variables: Set up the necessary variables, such as the clock's radius, center
coordinates, and time-related variables (hours, minutes, seconds).
Step 3:
Draw Clock Face: Draw the circular shape representing the clock face using the
specified radius and center coordinates.
Step 4:
Draw Hour Markers: Position and draw the hour markers evenly around the clock
face.
Step 5:
Draw Hour Hand: Calculate the angle for the hour hand based on the current hour,
and then draw a line representing the hand's length and position.
Step 6:
Draw Minute Hand: Calculate the angle for the minute hand based on the current
minute, and then draw a line representing its length and position.
Step 7:
Draw Second Hand: Calculate the angle for the second hand based on the current
second, and then draw a line representing its length and position.
Step 8:
Update Time: Increment the time variables (hours, minutes, seconds) to reflect the
passage of time.
Step 9:
Clear Screen: Clear the screen or canvas to prepare for the next frame.
Step 10:
Repeat: Return to the step of drawing the clock face and continue the process to
create an animated effect.
2.2 Flowchart
is a function used in the OpenGL graphics library to specify the current matrix mode. OpenGL
provides different matrix modes for different types of transformations, such as modelview,
projection, and texture transformations. This allows you to switch between these modes to
perform different types of matrix operations.
glShadeModel() :
is a function used in the OpenGL graphics library to specify the shading model used for
rendering polygons. The shading model determines how lighting calculations are performed
and how colors are interpolated across the surface of a polygon.
glLightfv() :
is a function used in the OpenGL graphics library to set various parameters of a light source.
It allows you to specify different properties of a light, such as its position, color, intensity, and
attenuation.
glEnable():
is a function used in the OpenGL graphics library to enable various OpenGL features and
capabilities. It is typically used to enable specific capabilities or functionality that you want to
utilize in your rendering pipeline.
glPushMatrix():
glPushMatrix() and glPopMatrix(): These functions push and pop the current matrix
stack, respectively. You would use them to save and restore the transformation state
when rendering the clock's hands or dial.
glTranslate():
This function applies a translation to the current matrix. You would use it to position
the clock's hands at the desired locations.
glRotatef():
This function applies a rotation to the current matrix. You would use it to rotate the
clock's hands based on the current time.
gluQuadricDrawStyle():
function is used to specify the drawing style of a quadric object created with glNewQuadric
A quadric object is a geometric primitive like a sphere, cylinder, or disk, which can be rendered
using OpenGL.
gluQuadricOrientation():
gluCylinder():
is a function from the legacy OpenGL Utility Library that allows you to render a
cylinder primitive in the OpenGL rendering pipeline. It is used to generate the vertices,
normals, and texture coordinates necessary to render a cylinder.
glDisk():
is a function from the legacy OpenGL Utility Library (GLU) that allows you to render
a disk or a partial disk primitive in the OpenGL rendering pipeline. It is used to generate
the vertices, normals, and texture coordinates necessary to render a disk.
glClearColor():
Graphics are sent to the screen through this functions and registered with the windows
system.
glutCreateMenu():
glutAddMenuEntry():
glutMainLoop():
glutAttachMenu():
it attaches a mouse button for the current window to the identifier of the current menu.
Dept. of CS&E, MIT Mysore 2022-2023 5
Analog clock Computer Graphics Laboratory with Mini-Project [ 18CSL67 ]
#include <GL/glut.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include <time.h>
char buf[LEN];
char* ch=buf;
vsnprintf(buf,LEN,format,args);
while (*ch)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*ch++);
va_list args;
glWindowPos2i(x,y);
va_start(args,format);
printv(args,format);
va_end(args);
int i;
glRasterPos3f(x,y,-1);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,string[i]);
};
void num()
print(-0.195,-5.9,"12");
print(-0.1,6.1,"6");
print(5.9,0.1,"3");
print(5.0, 3.2,"4");
print(2.9,5.45,"5");
print(-3.2,5.45,"7");
print(-5.4, 3.2,"8");
print(-5.5, -2.8,"10");
print(-3.3,-5.05,"11");
print(5.1, -2.8,"2");
print(2.9,-5.05,"1");
int i;
glPushMatrix();
glTranslatef(0,0,1);
glScaled(scalex,scaley,scalez);
glPopMatrix();
glPushMatrix();
glScaled(scalex,scaley,scalez);
glutSolidCube( 1.0 );
glPopMatrix();
glPushMatrix();
glTranslatef(cx,cy,cz);
glScaled(scalex,scaley,scalez);
glTranslatef( 0, 0, 1.0);
glScaled(scalex,scaley,scalez);
glPopMatrix();
void about()
glClear(GL_COLOR_BUFFER_BIT);
printAt(0,80," is displayed");
glFlush();
if(key == '+')
scalex += 0.1;
scaley += 0.1;
scalez += 0.1;
if(key == '-')
scalex -= 0.1;
scaley -= 0.1;
scalez -= 0.1;
void display_clock()
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
if(about_int != 0)
{ about(); }
printAt(120,10, asctime(newtime));
if (light_state == 1)
glEnable(GL_LIGHTING);
}else
glDisable(GL_LIGHTING);
glutSwapBuffers();
void display(void)
glClear(GL_COLOR_BUFFER_BIT);
display_clock();
glFlush();
glMatrixMode (GL_PROJECTION);
glLoadIdentity (); }
switch(id)
case 1:
break;
case 2:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
break;
case 3 :
exit(0);
glutInit(&argc, argv);
glutCreateWindow (argv[0]);
glutSetWindowTitle("GLclock");
init ();
glutCreateMenu(options);
glutAddMenuEntry("Light on/off",2);
glutAddMenuEntry("Quit",3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(myKey);
glutMainLoop();
return 0;
CHAPTER-3
RESULT ANALYSIS
3.1 Snap shots
3.2 Discussion
The specific steps and code required will vary depending on the programming
language and graphics library you choose. It's important to refer to the documentation
and examples provided by the library to understand the specific syntax, functions, and
APIs required for creating an analog clock in computer graphics using that particular
technology.
• Choose a Programming Language:
Determine which programming language you want to use for creating the analog clock
in computer graphics. Common options GLUT ,OpenGL project depending on your
preferences and the graphics libraries available for that language.
• Select a Graphics Library
Identify a graphics library or framework that supports drawing and animation
capabilities. Some popular libraries include OpenGL, WebGL, DirectX, JavaFX, or
HTML5 Canvas, depending on the programming language you choose.
• Set up the Development Environment:
Install the necessary tools, libraries, and dependencies required for your chosen
programming language and graphics library. Refer to the documentation and resources
provided by the specific library for installation instructions.
• Write the Code:
Use the programming language and graphics library of your choice to write the code for
the analog clock. This typically involves defining the clock face, hands, and any other
visual elements, as well as implementing the animation and time-related functionality.
• Built and Run:
Once you have written the code, save the file with the appropriate file extension for the
chosen programming language (e.g., .c, .java, .py, .js). Compile the code using the
appropriate command or IDE-specific compilation options. Then, run the compiled
program or execute the script.
• Observe the Analog Clock:
The analog clock should now be displayed on your screen, showing the current time
and updating the clock hands accordingly. Interact with the clock as per the
functionality you have implemented (e.g., setting the time manually, adjusting
appearance).
CHAPTER-4
4.1 Conclusion
Analog clocks in computer graphics provide an engaging and visually appealing way
to represent time. By considering design principles, implementing appropriate
transformations, and incorporating additional features, we can create realistic and
customizable analog clocks. Whether used in educational tools, user interfaces, or
visualizations, analog clocks serve as valuable components, bridging the gap between
digital representations and our real-world understanding of time.
CHAPTER-5
REFERENCES
➢ http://en.wikipedia.org/wiki/Clock
➢ https://github.com/mukulms123/Analog-clock
➢ http://www.w3schools.com