Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

KANTIPUR ENGINEERING COLLEGE

Dhapakhel, Lalitpur

Report for Computer Graphics

On

“GRAPHICALLY DESIGNATED WALL CLOCK”

Submitted to:

DEPARTMENT OF COMPUTER AND ELECTRONICS ENGINEERING

KANTIPUR ENGINEERING COLLEGE

Submitted by:

Aakash Raj Shrestha(2068/BEX/01)

Ajit Bom Mall(2068/BEX/03)

Darsan Kandel(2068/BEX/15)

Santosh Poudel (2068/BEX/35)

23th March , 2014

(i)
PREFACE

This report has been prepared to the “Graphically Designated Clock”. This document is
the final report of the findings and recommendations of the Computer Graphics for III year I
part. Computer graphics remains one of the most exciting and rapidly growing computer fields.
Computer graphics has now become a common element in user interfaces, data visualization,
television commercial, motion pictures, and many-many other application. With the advantages
of Graphics, modern subject, we can be able to design different applications and tools which can
be beneficial in our daily life. Besides, some entertaining applications can also be designed using
Graphics such as Games, Photo Effects etc. We are trying to apply the Graphics applications on
designing Wall Clock. It will display give the time by the synchronization with system time i.e.
our program will get the system time and displays the time same to that of Wall Clock.

(ii)

ACKNOWLEDGEMENT
Many people have contributed to this project in variety of ways. To all of them we would like to
express our appreciation. We also acknowledge the many helpful comments from our friends and
co-workers on many ideas. We are indebted to all those who provided reviews or suggestion for
improving the material covered in this report and we extend our apologies to anyone who may
have failed to mention. Firstly we would like to give lots of thanks to the course maker of IOE,
Pulchowk Lalitpur for giving us such a wonderful opportunity. Secondly also to our college
Kantipur Engineering College and Electronics and Computer Department for giving us this
platform and at last but the most important to our course teachers Er. Bikash Banjara, Er. Samir
Thapa, Er. Prakash Shrestha and Er. Pavan Paudel for their motivation and encouragement in our
project.

(iii)
TABLE OF CONTENTS

Title Pages no.

1) Title (i)

2) Preface (ii)

3) Acknowledgement (iii)

4) Introduction 1

5) Objectives 2

6) Features and Scopes 3

7) Methodology 4

8) Source Code 9

9) Conclusion 19

10) References 20

INTRODUCTION
Computer has become a powerful tool for the rapid and economical production of
pictures. Computer Graphics remains one the most exciting and rapidly growing fields. Old
Chinese saying” One picture is worth of thousand words” can be modified in this computer era
into “One picture is worth of many kilobytes of data”. It is natural to expect that graphical
communication will often be more convenient when computers are utilized for this purpose.
Many people for different domain of applications use interactive graphics. For example
structural engineering use for efficient design of structures on the basis of the analysis of stress in
various elements of the structure. From the survey it is evident that in future, engineers,
designers etc. will be using computer graphics quite extensively. There is virtually no area in
which graphical displays cannot be used to some advantage, and so it is not surprising to find the
use of computer graphics so widespread. Today, we find Computer Graphics used routinely in
such diverse areas such as science, engineering, medicine, business, industry, government, art,
entertainment, advertising, education, training, etc.

So for understanding the depth of this subject and for gaining sound knowledge in this
field we had an attempted to the first step on this current field. We tried to make a graphically
designated wall clock. The Graphic Designated Clock is made with the application of Graphics
codes. This project applied the subject and made the wall clock which displays the system time.
It has round frame shape and hour, minute and second needles. We hoped with our project the
illiterate (who cannot read the letters) can be benefitted in day to day life.

(1)

OBJECTIVES
The main objectives of this project are:

 To implement the features of graphics.

 To interface the applications of graphics to the real world.

 To give some benefits to the disability.

 To make the life easier.

 To become familiarization with Graphics and its logical coding.

(2)
FEATURES AND SCOPES

Computer Graphics has revolutionized almost every computer-based application in


science and technology. Information technology is a trend today. As the volume of information
increases, problem of storage arises. As time is money, in the 21st century people doesn’t have
the time to read huge number of pages. So this problem is solved by Computer Graphics. Picture
can represent a huge database like bar charts, pie charts etc. suppose, we have to show the
performance of some factory related with profit since 1980. One requires large number of pages
to store this huge information related with financial, numerical and statistical information. A
common man requires a lot of time to understand it. There is an alternative to show or represent
this information with the help of graphical tools such as bar chart or pie chart i.e. we can express
this data in pictorial forms.

The importance of computer graphics lies in its applications. In engineering applications


(e.g. automotive and aerospace) the ability to quickly visualize newly designed shapes is
indispensible. Computer graphics has also expanded the boundaries of art and entertainment.
Movies such as Jurassic Park make extensive use of computer graphics to create images that test
the bounds of imagination. The development of computer graphics has made possible virtual
reality, a synthetic reality that exists only inside a computer. Virtual reality is fast becoming an
indispensable tool in education. Flight simulators are used to train pilot for extreme conditions.
Surgical simulators are used to train novice surgeons without endangering patients.

Our project is one of the examples for the above mentation features and scope of computer
graphics and its applications. Applications like our projects can be further improved with more
features and can be implemented in our day-to-day life. We can take many advantages of this
subject in the future. It is probable that at present situation also, it is anyhow utilized in modern
technical gadgets.

(3)
METHODOLOGY
This project was done with the help of C-Programming Language. Different methods are
performed in order to make it more applied and efficient. C Graphics programming is very easy
and interesting. We used graphics programming for developing our projects, for designing,
animation etc. It's not like traditional C programming in which you have to apply complex logic
in your program and then you end up with a lot of errors and warnings in your program. In C
graphics programming you have to use standard library functions ( need not worry if you don't
know functions ) to get your task done. Just you pass arguments to the functions and it's done. 
Many graphic functions are coded on its header file <graphics.h>.

Sample Graphics Code:

This program initializes graphics mode and then closes it after a key is pressed. To begin
with we have declared two variables of int type gd and gm for graphics driver and graphics mode
respectively, you can choose any other variable name as you wish. DETECT is a macro defined
in "graphics.h" header file, then we have passed three arguments to initgraph function first is the
address of gd, second is the address of gm and third is the path where your BGI files are present
(we have adjusted this accordingly where our turbo compiler is installed). Initgraph function
automatically decides an appropriate graphics driver and mode such that maximum screen
resolution is set, getch() helps us to wait until a key is pressed, closegraph() function closes the
graphics mode and finally return statement returns a value 0 to main indicating successful
execution of your program.

(4)
Some of the function included in< graphics.h> used in our project:

i) Line function:

line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e.


(x1,y1) and(x2,y2) are end points of the line.The code given below draws a line.

Declaration :- void line(int x1, int y1, int x2, int y2);

ii) Circle function:

Circle function is used to draw a circle with center (x,y) and third
parameter specifies the radius of the circle. The code given below draws a circle.

Declaration :- void circle(int x, int y, int radius);

iii) Setcolor function:

In Turbo Graphics each color is assigned a number. Total 16 colors are


available. Strictly speaking number of available colors depends on current
graphics mode and driver.For Example :- BLACK is assigned 0, RED is assigned
4 etc. setcolor function is used to change the current drawing color.e.g.
setcolor(RED) or setcolor(4) changes the current drawing color to RED.
Remember that default drawing color is WHITE.

Declaration :- void setcolor(int color);

iv) Outtextxy function:

outtextxy function display text or string at a specified point(x,y) on the


screen.
Declaration :- void outtextxy(int x, int y, char *string);
x, y are coordinates of the point and third argument contains the address of string
to be displayed.

(5)
v) Getmaxx function:

getmaxx function returns the maximum X coordinate for current graphics


mode and driver.
Declaration :- int getmaxx();

vi) Grtmaxy function:

getmaxy function returns the maximum Y coordinate for current graphics


mode and driver.
Declaration :- int getmaxy();

vii) Setlinestyle function:

Setlinestyle function sets line style, thickness, unsigned upattern etc.

Declaration:
void setlinestyle( int linestyle, unsigned upattern, int thickness );

viii) Putpixel function:

putpixel function plots a pixel at location (x, y) of specified color.


Declaration :- void putpixel(int x, int y, int color);
For example if we want to draw a GREEN color pixel at (35, 45)
then we will write putpixel(35, 35, GREEN); in our c program, putpixel
function can be used to draw circles, lines and ellipses using various
algorithms.

ix) Setfillstyle function:

setfillstyle function sets the current fill pattern and fill color.

Declaration :- void setfillstyle( int pattern, int color);

(6)
OTHER HEADER FILE USED:

 <stdio.h>:
The C programming language provides many standard
library functions for file input and output. These functions make up the bulk of
the C standard library header <stdio.h>.The I/O functionality of C is fairly low-
level by modern standards; C abstracts all file operations into operations
on streams of bytes, which may be "input streams" or "output streams". Unlike
some earlier programming languages, C has no direct support for random-
access data files; to read from a record in the middle of a file, the programmer
must create a stream, seek to the middle of the file, and then read bytes in
sequence from the stream.

Stdio.h functions used in our project:

 Sprint
 If/else
 Break
 While
 Struct

 <conio.h>:
conio.h header used in c programming contains functions for console
input/output. Some of the most commonly used functions of conio.h are clrscr,
getch, getche, kbhit etc. Functions of conio.h can be used to clear screen, change
color of text and background, move text, check if a key is pressed or not and
many more. conio.h file is provided by Borland turbo c compiler and GCC
compiler doesn't support it.

Conio.h functions used in our project:

 clrscr
 getch
 kbhit

(7)
 <math.h>:
Math.h header file (<math.h>) of c programming language contains
constants and functions to perform mathematical operations. You can use
functions of math.h in your c programs to calculating absolute value of a number,
calculating logarithms and using trigonometric functions to calculate sine, cosine
of an angle.

Math.h functions used in our project:

 cos
 Sin
 Pow

 <dos.h>:
dos.h header file of c language contains functions for handling interrupts,
producing sound, date and time functions etc. It is borland specific and works in
turbo c compiler.

dos.h functions used in our project:

 delay
 getdate
 gettime
 nosound
 setdate
 sleep
 sound
(8)

SOURCE CODE:

#include<stdio.h>

#include<conio.h>

#include<dos.h>

#include<graphics.h>

#include<math.h>

#include<process.h>

#include<stdlib.h>

void frame();

void draw_numbers(int,int,int);

void line_at_angle(int,float,int);

void beep(int,int);

void clear(int,int,int,int,int);

void main()

int gdriver=DETECT,gmode,errorcode;

struct time t,i;

int key,k=0,x,y,t_sec,t_min,midx,midy;

char tim[5];

float hour,ang_sec,ang_min,ang_hour;

initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

errorcode=graphresult();

if(errorcode!=grOk)

printf("Graphics error");
(9)

printf("Press any key to halt:");

exit(1);

gettime(&t);

midx=getmaxx()/2;

midy=getmaxy()/2;

frame();

while(1)

gettime(&t);

if(t.ti_hour>=12)

hour=t.ti_hour-12;

else

hour=t.ti_hour;

ang_sec=t.ti_sec*6;

ang_min=(t.ti_min*6)+(ang_sec/60);

ang_hour=(hour*30)+(ang_min/12);

setcolor(4);

circle(midx,midy,6);

line_at_angle(150,ang_min,2);

setcolor(12);

setfillstyle(1,4);

line_at_angle(130,ang_hour,3);

setcolor(14);

line_at_angle(170,ang_sec,1);
(10)

line_at_angle(20,180+ang_sec,1);

setcolor(13);

x=520,y=460;

gettime(&t);

if(t.ti_hour>12)

outtextxy(x+80,y,"PM");

sprintf(tim,"%d",t.ti_hour-12);

else

outtextxy(x+80,y,"AM");

sprintf(tim,"%d",t.ti_hour);

outtextxy(x,y,tim);

outtextxy(x+16,y,":");

outtextxy(x+42,y,":");

sprintf(tim,"%d",t.ti_min);

outtextxy(x+26,y,tim);

sprintf(tim,"%d",t.ti_sec);

outtextxy(x+50,y,tim);

k++;

if(k==10)

k=0;
(11)

beep(100,50);

else

delay(100);

t_sec=t.ti_sec;

t_min=t.ti_min;

clear(x+50,y,x+70,y+8,0);

if(t_sec>=59)

clear(x+26,y,x+46,y+8,0);

if(t_min>=59)

clear(x,y,x+20,y+8,0);

setcolor(0);

line_at_angle(130,ang_hour-6,1);

line_at_angle(150,ang_min-4,1);

line_at_angle(170,ang_sec,1);

line_at_angle(20,180+ang_sec,1);

ang_sec++;

if(kbhit())

break;

closegraph();

getch();

}
(12)

//////////////////////////////////////////////////

void frame()

int midx,midy,i;

float angle=0;

float x,y;

midx=getmaxx()/2;

midy=getmaxy()/2;

setcolor(2);

circle(midx,midy,223);

setcolor(15);

circle(midx,midy,220);

setcolor(12);

circle(midx,midy,217);

setcolor(4);

for(i=0;i<=60;i++)

x=cos((angle/180)*M_PI)*190;

y=sin((angle/180)*M_PI)*190;

if((int)angle%30!=0)

circle(midx+x,midy+y,2);

angle+=6;

angle=0;
(13)

for(i=0;i<12;i++)

setcolor(13);

x=cos((angle/180)*M_PI)*190;

y=sin((angle/180)*M_PI)*190;

setcolor(10);

draw_numbers(midx+x,midy+y,i);

angle+=30;

//////////////////////////////////////////////////

void line_at_angle(int radius,float angle,int flag)

float x,y,x1,y1,x2,y2,x3,y3;

int midx,midy;

int poly1[10];

angle-=90;

midx=getmaxx()/2;

midy=getmaxy()/2;

x=cos((angle/180)*M_PI)*radius;

y=sin((angle/180)*M_PI)*radius;

setlinestyle(0,1,3);

if(flag==1)

line(midx,midy,midx+x,midy+y);

if(flag==2)
(14)

setcolor(12);

setlinestyle(0,1,1);

x2=cos(((angle+3)/180)*M_PI)*(radius-25);

y2=sin(((angle+3)/180)*M_PI)*(radius-25);

x3=cos(((angle-3)/180)*M_PI)*(radius-25);

y3=sin(((angle-3)/180)*M_PI)*(radius-25);

line(midx,midy,midx+x2,midy+y2);

line(midx,midy,midx+x3,midy+y3);

line(midx+x-2,midy+y-2,midx+x3,midy+y3);

line(midx+x-2,midy+y-2,midx+x2,midy+y2);

line(midx,midy,midx+x2,midy+y2);

line(midx,midy,midx+x3,midy+y3);

//line(midx+x-2,midy+y-2,midx+x3,midy+y3);

poly1[0]=midx;

poly1[1]=midy;

poly1[2]=midx+x2;

poly1[3]=midy+y2;

poly1[4]=midx+x;

poly1[5]=midy+y;

poly1[6]=midx+x3;

poly1[7]=midy+y3;

poly1[8]=midx;

poly1[9]=midy;

fillpoly(3,poly1);
(15)

x2=cos(((angle)/180)*M_PI)*(radius+1);

y2=sin(((angle)/180)*M_PI)*(radius+1);

x3=cos(((angle-6)/180)*M_PI)*(radius-25);

y3=sin(((angle-6)/180)*M_PI)*(radius-25);

setcolor(0);

line(midx+x2,midy+y2,midx+x3,midy+y3);

line(midx+x,midy+y,midx+x3,midy+y3);

else if(flag==3)

setcolor(10);

setlinestyle(0,1,1);

x2=cos(((angle+5)/180)*M_PI)*(radius-30);

y2=sin(((angle+5)/180)*M_PI)*(radius-30);

x3=cos(((angle-5)/180)*M_PI)*(radius-30);

y3=sin(((angle-5)/180)*M_PI)*(radius-30);

poly1[0]=midx;

poly1[1]=midy;

poly1[2]=midx+x2;

poly1[3]=midy+y2;

poly1[4]=midx+x;

poly1[5]=midy+y;

poly1[6]=midx+x3;

poly1[7]=midy+y3;
(16)

poly1[8]=midx;

poly1[9]=midy;

fillpoly(5,poly1);

line(midx,midy,midx+x2,midy+y2);

line(midx,midy,midx+x3,midy+y3);

line(midx+x-2,midy+y-2,midx+x3,midy+y3);

line(midx+x-2,midy+y-2,midx+x2,midy+y2);

setcolor(0);

x2=cos(((angle)/180)*M_PI)*(radius+1);

y2=sin(((angle)/180)*M_PI)*(radius+1);

x3=cos(((angle-6)/180)*M_PI)*(radius-30);

y3=sin(((angle-6)/180)*M_PI)*(radius-30);

line(midx+x2,midy+y2,midx+x3,midy+y3);

line(midx+x,midy+y,midx+x3,midy+y3);

/////////////////////////

void beep(int fre,int wait) //gives beep

sound(fre);

delay(wait);

nosound();

///////////////////////////////////////

void draw_numbers(int x,int y,int position) //Draws numbers on clock


(17)

char stpos[5]="";

position+=3;

if(position>12)

position=position%12;

itoa(position,stpos,10);

outtextxy(x,y,stpos);

//////////////////////////////////

void clear(int x1,int y1,int x2,int y2,int col)

int x, y;

for(x=x1;x<=x2;x++)

for(y=y1;y<=y2;y++)

putpixel(x,y,col);

(18)
CONCLUSION

This project is one of the sample project on Computer Graphics.. Though many
difficulties were faced during the project as well as many errors occurred, we became succeed to
compile and run the program. There may be some limitations on this project as well, so, in the
near future we would like to be hopeful in further improvements. We are highly obliged to all
helping hands and to all inspirations to make this project successful. Well this project will be
applicable to most of all. As well as, we are more hopeful for more advice, new ideas and
inspiration to make more other projects.

To had tried our best to include each and every basic features of graphics in our projects.
We aimed it to be an interfacing application to the real world that means our project must not be
an project for any examination but also applicable for real world use. We have able to give some
benefits to the disability. It somehow makes our life easier in this or that way. From this very
project we were able to achieve various knowledge in computer graphics and also in logical
coding. We refresh our knowledge in C Programming. Moreover we also gained an experience
of group work, team coordination. We learned how team work is very much important in
engineering field.

(19)
REFERENCES

 Donald, Hearn. Computer Graphics. Pearson Education: 2005, Pearson

Education.

 www.learnstreet.com

 http://www.sourcecodesworld.com/

(20)

You might also like