The Ultimate Guide to Choosing WordPress Pros and Cons
Computer Graphics Practical
1. PUNJAB COLLEGE OF
TECHNICAL EDUCATION
PRACTICAL
FILE BC-507
SUBMITTED BY: SUBMITTED BY:
Ms.Richa Sharma Neha Sharma
Assistant Professor (94972346352)
P.C.T.E. BCA-5th Sem
Page | 0
2. Index
S.No Contents Page no. Remarks
1. Introduction to graphics 2
2. Applications of graphics 3-5
3. Graphics In-built functions 6-15
4. Programs of Algorithm 16-26
a) Direct method of line
b) DDA Algorithm
c) Bresenham algorithm
d) Direct method of Circle
e) Polar Circle
f) Bresenham Circle
g) Midpoint Circle
h) Direct Ellipse
i) Polar Ellipse
j) Mid point Ellipse
5. Static Application
6. Ist dynamic Application
7. IInd Dynamic Application
Page | 1
3. 1. Introduction To Graphics
Computer graphics are graphics created using computers and, more generally, the
representation and manipulation of image data by a computer with help from specialized
software and hardware.
The development of computer graphics has made computers easier to interact with, and
better for understanding and interpreting many types of data. Developments in computer
graphics have had a profound impact on many types of media and have revolutionized
animation, movies and the video game industry.
the term computer graphics refers to several different things:
the representation and manipulation of image data by a computer
the various technologies used to create and manipulate images
the images so produced, and
the sub-field of computer science which studies methods for digitally synthesizing and
manipulating visual content
Page | 2
4. 2. Application of Graphics
Computer graphics may be used in the following areas:
COMPUTER AIDED DESIGN
PRESENTATION GRAPHICS
COMPUTER ART
ENTERTAINMENT
EDUCATION AND TRAINING
VISUALIZATION
IMAGE PROCESSING
GRAPHICAL USER INTERFACE
VIDEO GAMES
Computers have become a powerful tool for the rapid and economical production of
pictures. Advances in computer technology have made interactive computer graphics a
practical tool. Today, computer graphics is used in the areas as science, engineering,
medicine, business, industry, government, art, entertainment, advertising, education, and
training.
COMPUTER AIDED DESIGN
A major use of computer graphics is in design processes, particularly for
engineering and architectural systems. For some design applications; objects are first
displayed in a wireframe outline form that shows the overall sham and internal features of
objects.
Software packages for CAD applications typically provide the designer with a multi-
window environment. Each window can show enlarged sections or different views of
objects. Standard shapes for electrical, electronic, and logic circuits are often supplied by
the design package. The connections between the components have been mad
automatically.
Animations are often used in CAD applications.
Real-time animations using wire frame displays are useful for testing performance
of a vehicle.
Wire frame models allow the designer to see the interior parts of the vehicle during
motion.
When object designs are complete, realistic lighting models and surface rendering
are applied.
Manufacturing process of object can also be controlled through CAD.
Page | 3
5. Interactive graphics methods are used to layout the buildings.
Three-dimensional interior layouts and lighting also provided.
With virtual-reality systems, the designers can go for a simulated walk inside the
building.
PRESENTATION GRAPHICS
It is used to produce illustrations for reports or to generate slide for with
projections.
Examples of presentation graphics are bar charts, line graphs, surface graphs, pie
charts and displays showing relationships between parameters.
3-D graphics can provide more attraction to the presentation.
COMPUTER ART
Computer graphics methods are widely used in both fine are and commercial art
applications.
The artist uses a combination of 3D modeling packages, texture mapping, drawing
programs and CAD software.
Pen plotter with specially designed software can create “automatic art”.
“Mathematical Art” can be produced using mathematical functions, fractal
procedures.
These methods are also applied in commercial art.
Photorealistic techniques are used to render images of a product.
Animations are also used frequently in advertising, and television commercials are
produced frame by frame. Film animations require 24 frames for each second in the
animation sequence.
A common graphics method employed in many commercials is morphing, where
one object is transformed into another.
ENTERTAINMENT
CG methods are now commonly used in making motion pictures, music videos and
television shows.
Many TV series regularly employ computer graphics method.
Graphics objects can be combined with a live action.
EDUCATION AND TRAINING
Computer-generated models of physical, financial and economic systems are often
used as educational aids.
Page | 4
6. For some training applications, special systems are designed.
Eg. Training of ship captains, aircraft pilots etc.,
Some simulators have no video screens, but most simulators provide graphics
screen for visual operation. Some of them provide only the control panel.
VISUALIZATION
The numerical and scientific data are converted to a visual form for analysis and to
study the behavior called visualization.
Producing graphical representation for scientific data sets are calls scientific
visualization.
And business visualization is used to represent the data sets related to commerce
and industry.
The visualization can be either 2D or 3D.
IMAGE PROCESSING
Computer graphics is used to create a picture.
Image processing applies techniques to modify or interpret existing pictures.
To apply image processing methods, the image must be digitized first.
Medical applications also make extensive use of image processing techniques for
picture enhancements, simulations of operations, etc.
GRAPHICAL USER INTERFACE
Nowadays software packages provide graphics user interface (GUI) for the user to
work easily.
A major component in GUI is a window.
Multiple windows can be opened at a time.
To activate any one of the window, the user needs just to check on that window.
Menus and icons are used for fast selection of processing operations.
Icons are used as shortcut to perform functions. The advantages of icons are which
takes less screen space.
And some other interfaces like text box, buttons, and list are also used.
Page | 5
7. 3. Inbuilt Functions:
1. Arc
Arc draws a circular arc in the current drawing color.
Declaration:
Void arc(int x, int y , int Stangle, int endangle , int radius )
ARGUMENT What it is Does
(x,y) Center point of arc
Stangle Start angle in degrees
Endangle End angle in degrees
Radius Radius of arc
The arc travels from Stangle to Endangle
If Stangle =0 and Endangle = 360 , the call to arc draws a complete circle
2. Initgraph
Initializes the graphic system
Decalaration:
Void far initgraph(int far * graphdriver);
Int far * graphmode , char far *pathdriver);
Remarks:
To start the graphics system , you must first call the initgraph
Initgraph initializes the graphics system by loading a graphics the driver from disk (or
validating a registered driver ) then putting the system into graphics mode .
Page | 6
8. Initgraph also resets all the graphics settings (color ,palette ,current position , viewport
,etc) to their defaults , then resets graphresult to 0 .
Argument What it is does
*graphdriver Integer that specifies the graphic driver to be used . you can give
graphdriver a value using a constant of the graphics_drivers
enumeration
type .
*graphmode Integer that specifies the initial graphics mode .(unless *graphdriver
=DETECT).
If *graphdriver =DETECT , initgraph sets *graphmode to the highest resolution available
for the detected driver . You can give the *graphmode a value using a constant of the
graphics_modes enumeration type .
*graphdriver and *graphmode must be set to the valid graphics _drivers and
graphics_mode values or you will get unpredictable results . ( the exception is graphdriver
= DETECT).
After a call to the initgraph , *graphdriver is set to the current graphics driver , and
*graphmode is set to the current graphics mode .
3. closegraph
Shuts down the graphics system
Declaration :
void far closegraph( void );
Remarks :
Closegraph deallocates all memory allocated by the graphics system . It then restores the
screen to the mode it was in before you called initgraph .
( the graphics system deallocates memory such as the drivers , fonts , and an internal
buffer , through a call to the _graphfreemem)
Page | 7
9. Return Value : None
4.line
Line draws a line between the two specified points
Declaration :
Void far line ( int x1, int y1 , int x2 , int y2 );
Remarks :
Line draws a line from the ( x1, y1 ) to ( x2,y2 ) using the current color , line style nad thick
ness . it does not the update the current position (cp).
5. setcolor
Setcolor sets the current drawing color
Declaration:
Void far setcolor( int color)
Remarks :
Setcolor sets the current drawing color to color , which can range from 0 to getmaxcolor
To select a drawing color is the value that pixels are set to the when the program draws
lines etc.
Return value :
Setcolor does not return
6.setbkcolor
Page | 8
10. Setbkcolor sets the current background the color using the palette
Declaration :
Void far setbkcolor( int color );
Remarks :
Setbkcolor sets the background to the color specified by color
Color :
color is either a number or symbolic name specifying the color to set
For example , if you want to set the background color to blue , you can call
setbkcolor (BLUE) /* or */ setbkcolor(1)
On CGA and EGA systems , setbkcolor changes the background color by changing the first
entry in the palette.
Return:
Setbkcolor does not return
7.Ellipse
Ellipse draws an elliptical arc
Declaration :
Void far ellipse ( int x, int y , int stangle , int endangle , int xradius , int yradius ) ;
Remarks :
Ellipse draws an elliptical arc in the current drawing color .
Argument What it is
( x,y) Center of ellipse
Xradius Horizontal axis
Yradius Vertical axis
Page | 9
11. Stangle starting angle
Endangle ending angle
The ellipse travels from stangle to endangle .
If stangle = 0 and endangle = 360 , the call to the ellipse draws a complete ellipse .
The linestyle parameter does not affect the arcs , circles , ellipse or pie slices . only the
thickness parameter is used .
Return value :
None
8.Flood fill :
Flood fills a bounded region
Declaration :
void far floodfill( int x, int y , int border );
Remarks :
Floodfill fills an enclosed area on bitmap devices .
The area bounded by the color border is flooded with the current fill pattern and fill color .
(x,y) is the “seed point ”.
If the seed is within an enclosed area , the inside will be filled .
If the seed is outside the enclosed area, the exterior will be filled .
Use fillpoly instead of floodfill whenever possible so you can maintain code compatibility
with future versions .
9.Outtextxy
Page | 10
12. Outtextxy displays a string at the specified location ( graphics mode )
Declaration :
Void far outtextxy (int x , int y , char far * textstring );
Remarks :
Outtextxy displays a text string using the current justification settings and the current font
, direction and size .
Outtextxy displays the textstring in the viewport at the position ( x,y)
To maintain the code compatibility when using the several fonts , use textwidth and
textheight to determine the dimensions of the string .
If a string is printed with the default font using the outtext ot outtextxy ,any part of the
string that extends outside the current viewport is truncated .
Outtextxy for use in graphics mode , they will not work in the text mode.
Return value :
None
10.Settextjustify
Sets text justification for graphics mode .
Decalration :
void far settextjustify ( int horiz , int vert ) ;
Remarks :
Text output after a call to settextjustify is justified around the current position (CP)
horizontally and vertically , as specified .
The default justification settings are :
LEFT_TEXT ( for horizontal )
TOP_TEXT ( for vertical )
Page | 11
13. The enumeration text_justify in GRAPHICS. H provides names for the horiz and vert
settings passed to the settextjustify .
Settextjusitfy affects the text written with outtext and cant be used with text – mode and
stream functions .
Return Values :
If invalid input is passed to the settextjustify , graph result returns -11 and the current text
justification remains unchanged .
11.Circle
Circle draws a circle
Decalration :
Void far circle(int x , int y , int radius );
ARGUMENT What it is Does
(x,y) Center point of circle
Radius Radius of circle
Remarks :
It draws a circle in the current drawing color.
12.Rectangle:
Draws a rectangle ( graphics mode )
Declaration :
Void far rectangle (int left , int top , int right , int bottom );
Remarks :
Rectangle draws a rectangle in the current line style , thickness and drawing color.
Page | 12
14. (left , top ) is the upper left corner of the rectangle , and (right , bottom ) is the lower right
corner .
Return Values :
None
13.Setlinestyle:
Set the current line style and width or pattern
Declaration :
void far setlinestyle ( int line style , unsigned upattern , int thickness);
Remarks :
Setlinestyle sets the style for all lines drawn by line , rectangle etc.
Return Values :
If invalid input is passed to setlinestyle , graphresult returns -11 , the current line style
remains unchanged .
14.Getmaxx ()and Getmaxy()
Return maximum x or y co-ordinates of screen.
Declaration :
Int far getmaxx (void );
Int far getmaxy (void );
Remarks :
1 . getmaxx returns the maximum X value (screen relative ) for the current graphics
driver and mode .
Page | 13
15. 2. getmaxy returns the maximum Y value ( screen relative ) for the current graphics
drivers and mode .
For Example :
On a CGA in 320 * 200 mode , getmaxx returns 319 and getmaxy returns the 199
Return Values :
1) Getmaxx : maximum x screen co-ordinates.
2) Getmaxy : maximum y screen co-ordinates .
15.Cleardevice()
Clears the graphic screen .
Declaration :
Void far cleardevice (void);
Remarks :
Cleardevice erases the entire graphics screen and moves the CP (Current Position ) to
home (0,0).
Return Values : None.
16.Setfillstyle()
Set the fill pattern and color .
Declaration :
void far setfillstyle (int pattern , int color);
Remarks :
Setfillstyle set the current fill pattern and fill color
To set a user defined fill pattern , do not give a pattern of 12 (USER_FILL) to setfillstyle ,
instead , call setfillpattern .
Page | 14
16. Return Values : None.
If invalid input is passed to the setfillstyle ,graphresult return -11 and the current fill
pattern and fill color remain unchanged .
17. delay
Delay function is used to suspend execution of a program for a particular time.
Declaration :- void delay(unsigned int);
Here unsigned int is the number of milliseconds ( remember 1 second = 1000 milliseconds
). To use delay function in your program you should include the dos.h header file.
Page | 15
17. Programs of Algorithms
Program1: Direct Method Of Line Drawing
CODING:
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
int x1,x2,c,y1,y2,dy,dx,m;
cout<<"tttt-----------------------------n";
cout<<"tttt DIRECT LINE BY NEHA SHARMAn";
cout<<"tttt-----------------------------n";
cout<<"enter the coordinatesn";
cin>>x1>>y1>>x2>>y2;
dy=y2-y1;
dx=x2-x1;
m=dy/dx;
c=y1-m*x1;
while(x1<=x2)
Page | 16
23. Program 4: Direct MethodPolynomial
MethodCartesian Co-Ordinate Algortihm For
Circle Drawing
CODING:
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<iostream.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
int x1,y1,xc,yc,r,x2;
cout<<"tttt-----------------------------n";
cout<<"tttt DIRECT CIRCLE BY NEHA SHARMAn";
cout<<"tttt-----------------------------n";
cout<<"enter the x center y center and radiusn";
cin>>xc>>yc>>r;
x1=0;
x2=r/sqrt(2);
while(x1<=x2)
{
y1=sqrt(r*r-x1*x1);
putpixel(y1+xc,x1+yc,WHITE);
Page | 22
25. Program 5: Polar Circle Drawing Algorithm
CODING:
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<iostream.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float x1,y1,xc,yc,r,t;
cout<<"enter the x center y center and radius";
cin>>xc>>yc>>r;
x1=0;
y1=r;
t=1/r;
while(x1<=y1)
{
putpixel(y1+xc,x1+yc,WHITE);
putpixel(x1+yc,y1+xc,WHITE);
putpixel(x1+yc,-y1+xc,WHITE);
putpixel(-y1+xc,x1+yc,WHITE);
putpixel(-y1+xc,-x1+yc,WHITE);
putpixel(-x1+yc,-y1+xc,WHITE);
Page | 24
27. Program 6: Bresenham Circle Drawing
Algorithm
CODING:
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<iostream.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float x1,y1,f,xc,yc,r,t;
cout<<"enter the x center y center and radius";
cin>>xc>>yc>>r;
x1=0;
y1=r;
f=3-(2*r);
while(x1<=y1)
{
if(f<=0)
{
f=f+6+4*x;
x=x+1;
}
Page | 26
29. Program 7: Mid Point Circle Drawing Algorithm
CODING:
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<iostream.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float x1,y1,f,xc,yc,r;
cout<<"MIDPOINT CIRCLEBY NEHA SHARMAn";
cout<<"enter the x center y center and radiusn";
cin>>xc>>yc>>r;
x1=0;
y1=r;
f=1-r;
while(x1<=y1)
{
if(f<=0)
{
f=f+3+2*x1;
x1=x1+1;
}
Page | 28