CGR MP
CGR MP
A
MICRO PROJECT
REPORT ON
“Simple Clock using Circles and Lines”
Subject Name : Computer Graphics using C
Subject Code : 313014
SUBMITTED BY
Name : Enrollment No :
1. Zariwala Sheza 23612410167
2. Almira khan 23612410156
GUIDED BY
Ms. Nazera Anjum
CERTIFICATE
This is to certify that Miss.
1. Zariwala Sheza 23612410167
2. Almira khan 23612410156
VISION
MISSION
1 INTRODUCTION 01-02
2 THEORY 03
ALGORITHM
3 04
FLOWCHART
4 05
CODE EXPLANATION
5 06
SOURCE CODE
6 07-10
7 OUTPUT 11
8 CONCLUSION 12
9 REFERENCES 13
Introduction
About C :
The history of the C programming language is closely tied to the history of the
development of the Unix Operating System. If we look back to understand what led to
the development of the operating system that changed the world of computing, we'll
see the steps that led to the development of C. Simply put, C was derived from the
need to initially find and eventually create a language to apply on the Unix Operating
system.
It all started in 1965 when the experimental project MAC was completed at MIT – the
first system of its kind. This was the beginning of the MULTICS era. It used something
called CTSS, or the Compatible Time Sharing System. This was a key innovation at that
time. Up to this point, we were in the early mainframe era, where massive, powerful, and
extremely costly computers used to take up entire rooms. To get tasks done,
programmers would write code by hand. Then they'd punch a deck of paper tape cards
that were encoded with the program written by hand. They did this by handing the sheets
of paper the program was written on to operators who used a key punch machine that
would punch the card's holes and represent the data and instructions on the card.The
idea of time sharing changed everything. Instead of using cards, it attached multiple
consoles (which at the time were mechanical terminals called teletypes) to a main
computer. This allowed many people to use the same computer simultaneously. Over 100
typewriter terminals spread around MIT's campus could be attached to one main big
computer. This system supported up to 30 remote users at the same time, each using one
of those terminals. The operating system of the main computer multitasked and circled
the people who wanted to perform computing tasks from their connected terminals and
gave a few seconds to each one. It provided what seemed like a continuous service,
appearing to be loading and running many programs simultaneously. But in reality, it
just went through each user's program very quickly. This gave the illusion that one
person had the whole computer to themselves. This system proved to be extremely
efficient, effective, and productive, saving time and in the long run money, since those
computers were extremely expensive.
Something that might have taken days to complete now took much less time. And this
started enabling greater access to computing. Following the success of the CTSS, MIT
decided it was time to build upon this system and take the next step. This next step
would be to create a more advanced time-sharing system. But they imagined a more
ambitious endeavor than that: they wanted to build a system that would serve as a
computing utility for programmers that would be capable of supporting hundreds of
users accessing the mainframe at the same time. And it would share data and resources
between them.
This would require more resources, so they joined forces with General Electric and Bell
Labs. This new project was named MULTICS, which stood for 'Multiplexed Information
and Computing Service' and was implemented on one of General Electric's mainframes,
the GE 635. This team worked on MULTICS for a number of years. But in 1969 Bell
Labs left the project because it was taking too long and was too expensive.
What is clock? :
Clocks are an essential part of our modern lives. In our daily life, we can’t survive
without knowledge of time. We get the exact time by using of clock. A clock is a device
used to measure and display the exact time. Clock has been used for thousands of years
to help people keep track of time and organize their daily lives. There are several types of
clocks you can see in daily life. They are Analog Clock, Digital Clock, Mechanical
Clock, Quartz Clock, Atomic Clock, Solar Clock, Radio Clock, Smart Clock etc.
In this post, I discuss with you about Analog and Digital Clock. Analog clock is
traditional clocks with a circular dial or face with hour, minute and second hands that
point to the numbers or symbols on the dial. Analog clock uses a mechanical
mechanism that moves the hands at a constant rate to keep the current time. There are
some examples of analog clock are wrist watch, wall clock and tower clock etc.
Theory
About program :
In this program, I use the graphics.h library to draw a clock face by drawing a circle and
dividing it into 12 parts to represent the hours and then draw the hour, minute and second
hands on the clock face to create an analog clock. I also create a digital clock by draw a
rectangle to represent the digits and then display the time by updating the digits every
second.
The logic of this program is very simple. In the program, I use a while loop where the
second hand of a clock moves around the circle fixed to the center of the circle. When the
second hand completes the round means it moves 360 degrees, the minute hand moves 6
degrees and when the minute hand completes the round means it moves 360 degrees, the
hour hand moves 0.5 degrees. This process is run continues.
Advantages :
Disadvantages :
1. Lack of Precision: Not as precise as digital clocks, especially for timing to the second.
2. Reading Speed: Takes longer to read compared to a quick glance at a digital display.
3. No Extra Features: Typically lacks additional features like alarms, backlighting, or date.
displays.
4. Maintenance: May require occasional adjustments to ensure accuracy.
Algorithm
In this program I use the graphics.h, stdio.h, conio.h, dos.h header files to create both
analog and digital clocks in C or C++ programing language. You have to declare integer
variables (xmax, ymax, x, y, i, j, k, m, s, h, m1, graphic_driver and graphic_mode) and
float variable (l) in the main() function. Before start drawing, you have to initialize the
graphics mode using initgraph() function. Then, get the x and y coordinate using
getmaxx() and getmaxy() functions. Here, you can use setcolor() function to set the color
of different shape and setbkcolor() to set background color. Using rectangle() and line()
function, you can create a rectangular box to show the digital clock. To create face of the
analog clock, use circle() function.
The setfillstyle() and floodfill() functions are used to fill the different shapes. Using
settextstyle() and outtextxy() functions, write the hour from one (1) to twelve (12) at the
border of circle (face of the analog clock). In the while loop, draw hour, minute and
second hand using pieslice() function. You can use kbhit() function to get a key press
from users.
Using sound() and nosound() functions produces sound when update position of the
hands of the clock. You can use delay() function to maintain the time for updating. The
gotoxy() function use for go to the digital clock. Here, use printf() function to print the
digit of time on the digital clock. You have to use closegraph() function to stop the
graphics mode.
The header file graphics.h contains circle() function which draws a circle with center at (x, y) and given radius:
Syntax :
Circle (x, y, radius);
where,
(x, y) is center of the circle.
' radius' is the Radius of the circle
The header file graphics.h contains lineto() function which draws a line from current position to the point(x,y).
Note : Use getx() and gety() to get the current position.
Syntax :
lineto(int x, int y);
where,
(x, y) are the coordinates upto which the
line will be drawn from previous point.
.
Source Code
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
int xmax, ymax, x, y, i = 0, j = 0, k = 0, m = 0, s = 0, h = 0, m1 = 0;
float l = 0.0;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
xmax = getmaxx();
ymax = getmaxy();
x = xmax / 2;
y = ymax / 2;
setcolor(15);
setbkcolor(0);
rectangle(x + 150, y - 200, x + 300, y - 170);
line(x + 200, y - 200, x + 200, y - 170);
line(x + 250, y - 200, x + 250, y - 170);
circle(x, y, 179);
circle(x, y, 180);
setfillstyle(0, 0);
floodfill(x, y, 0);
settextstyle(1, 0, 4);
outtextxy(x - 200, y - 25, "9");
outtextxy(x + 186, y - 25, "3");
outtextxy(x - 20, y - 220, "12");
outtextxy(x - 10, y + 176, "6");
outtextxy(x + 90, y - 195, "1");
outtextxy(x + 165, y - 120, "2");
outtextxy(x + 155, y + 80, "4");
outtextxy(x + 86, y + 152, "5");
outtextxy(x - 109, y + 148, "7");
outtextxy(x - 180, y + 72, "8");
outtextxy(x - 195, y - 120, "10");
outtextxy(x - 120, y - 195, "11");
settextstyle(1, 0, 3);
outtextxy(0, ymax - 30, "PRESS ANY KEY FOR STOP");
outtextxy(x + 150, y + 210, "PUSKAR JASU");
settextstyle(1, 0, 6);
outtextxy(0, 0, "CLOCK");
while (!kbhit())
{
setcolor(14);
if (m == 60)
{
if (k <= 90)
{
setcolor(14);
pieslice(x, y, 91 - k, 90 - k, 175);
sound(440);
delay(10);
nosound();
setcolor(0);
pieslice(x, y, 97 - k, 96 - k, 175);
}
if (k > 90)
{
setcolor(14);
pieslice(x, y, 451 - k, 450 - k, 175);
sound(440);
delay(10);
nosound();
setcolor(0);
pieslice(x, y, 457 - k, 456 - k, 175);
}
if (k == 360)
k = 0;
k = k + 6;
}
else
{
if (k <= 90)
{
pieslice(x, y, 91 - k, 90 - k, 175);
setcolor(0);
pieslice(x, y, 97 - k, 96 - k, 175);
}
if (k > 90)
{
setcolor(14);
pieslice(x, y, 451 - k, 450 - k, 175);
setcolor(0);
pieslice(x, y, 457 - k, 456 - k, 175);
}
}
ssetcolor(4);
if (j == 60 * 5)
{
if (l <= 90)
{
setcolor(4);
pieslice(x, y, 91 - l, 90 - l, 175);
sound(880);
delay(20);
nosound();
setcolor(0);
pieslice(x, y, 93.5 - l, 92.5 - l, 175);
}
if (l > 90)
{
setcolor(4);
pieslice(x, y, 451 - l, 450 - l, 175);
sound(880);
delay(20);
nosound();
setcolor(0);
pieslice(x, y, 453.5 - l, 452.5 - l, 175);
}
if (l == 360)
l = 0;
l = l + 2.5;
}
else
{
if (l <= 90)
{
setcolor(4);
pieslice(x, y, 91 - l, 90 - l, 175);
setcolor(0);
pieslice(x, y, 93.5 - l, 92.5 - l, 175);
}
if (l > 90)
{
setcolor(4);
pieslice(x, y, 451 - l, 450 - l, 175);
setcolor(0);
pieslice(x, y, 453.5 - l, 452.5 - l, 175);
}
}
if (i <= 90)
{
setcolor(10);
pieslice(x, y, 91 - i, 90 - i,);
}
if (i > 90)
{
setcolor(10);
pieslice(x, y, 451 - i, 450 -
i, 175);
delay(1000);
sound(220);
delay(5);
nosound();
setcolor(0);
pieslice(x, y, 451 - i, 450 -
i, 175);
}
if (i == 360)
i = 0;
i = i + 6;
s = i / 6;
if (j == 60 * 5)
j = 0;
j++;
if (m == 60)
m = 0;
m++;
if (s == 60)
{
m1++;
s =
0;
}
if (h == 24)
h = 0;
if (m1 == 60)
{
h++;
m1 = 0;
}
gotoxy(62, 4);
printf("%02d", h);
gotoxy(68, 4);
printf("%02d", m1);
gotoxy(74, 4);
printf("%02d", s);
s++;
}
closegraph();
return 0;
}
Output
References
1. Geeksforgeeks.com
2. Scribd.com
3. Turbo C++
4. Javatpoint.com
Conclusion
This microproject not only reinforced our understanding of the subject matter but also
prepared us for more complex challenges in future endeavours. The insights gained from
this project will undoubtedly be valuable assets as we continue to grow and develop in
our field of study. Thank you for the opportunity to explore and innovate.