SlideShare a Scribd company logo
1 of 37
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
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
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
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
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
   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
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
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
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
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
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
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
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
(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
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
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
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
{

if(m<=1)

{

x1=x1+1;

y1=m*x1+c;

putpixel(x1,y1,WHITE);

}

else

{

y1=y1+1;

x1=(y1-c)/m;

putpixel(x1,y1,WHITE);

}

}

getch();

}

OUTPUT:




                         Page | 17
Program 2. Digital Differential Analyzer For 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<<"ttt------------------n";

cout<<"tttDDA By Neha Sharman";

cout<<"ttt------------------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)

{

if(m<=1)

{


                                            Page | 18
x1=x1+1;

y1=y1+m;

putpixel(x1,y1,WHITE);

}

else

{

y1=y1+1;

x1=x1+(1/m);

putpixel(x1,y1,WHITE);

}

}

getch();

closegraph();

}

OUTPUT:




                         Page | 19
Program3: Bresenham Line Drawing Algorithm
CODING:

#include<graphics.h>

#include<iostream.h>

#include<conio.h>

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"");

int f,fe,fne,x1,x2,y1,y2,dy,dx,m;

cout<<"-----------------";

cout<<"nBy Neha Sharman";

cout<<"-----------------";

cout<<"nenter the cordinatesn";

cin>>x1>>y1>>x2>>y2;

dy=y2-y1;

dx=x2-x1;

f=(2*dy)-dx;

while(x1<=x2)

{

if(f<=0)

{

x1=x1+1;

//y1=y1;


                                      Page | 20
f=2*dy;

putpixel(x1,y1,WHITE);

f=f+fe;

}

else

{

y1=y1+1;

x1=x1+1;

f=(2*dy)-(2*dx);

putpixel(x1,y1,WHITE);

f=f+fne;

}

}

getch();

closegraph();

}

OUTPUT:




                         Page | 21
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
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);

putpixel(-x1+yc,y1+xc,WHITE);

putpixel(y1+xc,-x1+yc,WHITE);

x1=x1+1;

}

getch();

}

OUTPUT:




                                 Page | 23
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
putpixel(-x1+yc,y1+xc,WHITE);

putpixel(y1+xc,-x1+yc,WHITE);

float temp=y1;

y1=(y1*cos(t))+(x1*sin(t));

x1=(x1*cos(t))-(temp*sin(t));

}



getch();

}

OUTPUT:




                                Page | 25
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
else

{

f=f+10+(4*x)-(4*y);

x=x+1;

y=y-1;

}

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);

putpixel(-x1+yc,y1+xc,WHITE);

putpixel(y1+xc,-x1+yc,WHITE);

}

getch();

closegraph();

                                 }




                                     Page | 27
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
else

{

f=f+5+(2*x1)-(2*y1);

x1=x1+1;

y1=y1-1;

}

putpixel(y1+xc,x1+yc,WHITE);

putpixel(x1+xc,y1+yc,WHITE);

putpixel(x1+xc,-y1+yc,WHITE);

putpixel(-y1+xc,x1+yc,WHITE);

putpixel(-y1+xc,-x1+yc,WHITE);

putpixel(-x1+xc,-y1+yc,WHITE);

putpixel(-x1+xc,y1+yc,WHITE);

putpixel(y1+xc,-x1+yc,WHITE);

}

getch();

closegraph();

}

OUTPUT:




                                 Page | 29
Program 8: DirectPolynomial Algorithm Of
Ellipse Drawing
CODING:

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

#include<math.h>

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"");

float xc,yc,rx,ry,x1,y1,x2;



cout<<"DIRECT ELLIPSE BY NEHA SHARMAn";

cout<<"enter xc,yc,x radius,y radiusn" ;

cin>>xc>>yc>>rx>>ry;

x1=0;

x2=rx;

while(x1<=x2)

{

y1=(ry/rx)*sqrt((rx*rx)-(x1*x1));

putpixel(x1+xc,y1+yc,WHITE);

putpixel(x1+xc,-y1+yc,WHITE);

putpixel(-x1+xc,-y1+yc,WHITE);


                                            Page | 30
putpixel(-x1+xc,y1+yc,WHITE);

x1=x1+1;

}



getch();

closegraph();

}



OUTPUT:




                                Page | 31
Program 9: Polar Ellipse Drawing Algorithm
CODING:

#include<conio.h>

#include<iostream.h>

#include<graphics.h>

#include<math.h>

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"");

float xc,yc,rx,ry,t1,t2,x1,y1,x2;



cout<<"POLAR ELLIPSE BY NEHA SHARMAn";

cout<<"enter xc,yc,x radius,y radiusn" ;

cin>>xc>>yc>>rx>>ry;

t1=0;

t2=90;

while(t1<=t2)

{

y1=ry*sin(t1);

x1=rx*cos(t1);

putpixel(x1+xc,y1+yc,WHITE);

putpixel(x1+xc,-y1+yc,WHITE);

putpixel(-x1+xc,-y1+yc,WHITE);


                                            Page | 32
putpixel(-x1+xc,y1+yc,WHITE);

t1=t1+1;

}



getch();

closegraph();

}



OUTPUT:




                                Page | 33
10. Program To Draw Ellipse Using Midpoint
Ellipse Algorithm
Coding:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT, gm;
initgraph(&gd,&gm,"");
float xc,yc,x,y,xr,yr,f;
cout<<”tttt------------------------------------”;
cout<<"ntttMID POINT ELLIPSE BY MOHITn";

cout<<”ntttt---------------------------------------”;
cout<<"nEnter the coordinates xc,yc,xr ,yr";
cin>>xc>>yc>>xr>>yr;
x=0;
y=yr;
f=(yr*yr)+(xr*xr)/4-(xr*xr)*yr;
while(2*(yr*yr)*x<=2*(xr*xr)*y)
{
if(f<=0)
{
f=f+(3+(2*x))*(yr*yr);
x++;
putpixel(x+xc,y+yc,WHITE);
putpixel(-x+xc,y+yc,WHITE);
putpixel(-x+xc,-y+yc,WHITE);

                                                             Page | 34
putpixel(x+xc,-y+yc,WHITE);
}
else
{
f=f+3*(yr*yr)+2*x*(yr*yr)+2*(xr*xr)-2*y*(xr*xr);
x++;
y--;
putpixel(x+xc,y+yc,WHITE);
putpixel(-x+xc,y+yc,WHITE);
putpixel(-x+xc,-y+yc,WHITE);
putpixel(x+xc,-y+yc,WHITE);
}
}
f=(yr*yr)/4-2*(xr*xr)*yr+(xr*xr);
while(y>=0)
{
if(f<=0)
{
f=f+(3-(2*y))*(xr*xr);
x++;
y--;
putpixel(x+xc,y+yc,WHITE);
putpixel(-x+xc,y+yc,WHITE);
putpixel(-x+xc,-y+yc,WHITE);
putpixel(x+xc,-y+yc,WHITE);
}
else
{
f=f+2*(yr*yr)+2*x*(yr*yr)+3*(xr*xr)-2*y*(xr*xr);
y--;


                                                   Page | 35
putpixel(x+xc,y+yc,WHITE);
putpixel(-x+xc,y+yc,WHITE);
putpixel(-x+xc,-y+yc,WHITE);
putpixel(x+xc,-y+yc,WHITE);
}
}
getch();
closegraph();
}



OUTPUT:



    Mid Point Ellipse Drawing Algorithm




                                          Page | 36

More Related Content

What's hot

Application of computer graphic
Application of computer graphicApplication of computer graphic
Application of computer graphic
alldesign
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
Mohd Arif
 
Computer Animation PowerPoint
Computer Animation PowerPointComputer Animation PowerPoint
Computer Animation PowerPoint
oacore2
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
rajivagarwal23dei
 
Face recognition
Face recognitionFace recognition
Face recognition
bharath55
 

What's hot (20)

Car Price prediction final pdf1.docx
Car Price prediction final pdf1.docxCar Price prediction final pdf1.docx
Car Price prediction final pdf1.docx
 
Application of computer graphic
Application of computer graphicApplication of computer graphic
Application of computer graphic
 
lecture1 introduction to computer graphics(Computer graphics tutorials)
lecture1 introduction to computer graphics(Computer graphics tutorials)lecture1 introduction to computer graphics(Computer graphics tutorials)
lecture1 introduction to computer graphics(Computer graphics tutorials)
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docx
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
UNIT-IV
UNIT-IVUNIT-IV
UNIT-IV
 
Face detection presentation slide
Face detection  presentation slideFace detection  presentation slide
Face detection presentation slide
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Introduction to 3D Animation
Introduction to 3D AnimationIntroduction to 3D Animation
Introduction to 3D Animation
 
Computer Animation PowerPoint
Computer Animation PowerPointComputer Animation PowerPoint
Computer Animation PowerPoint
 
computer Graphics
computer Graphics computer Graphics
computer Graphics
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Online E-Voting System
Online E-Voting SystemOnline E-Voting System
Online E-Voting System
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
 
Face recognition
Face recognitionFace recognition
Face recognition
 

Viewers also liked

Computer graphics file
Computer graphics fileComputer graphics file
Computer graphics file
aman1001
 
Computer Graphics Applications
Computer Graphics ApplicationsComputer Graphics Applications
Computer Graphics Applications
Saravana Priya
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
Mohd Arif
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
amitsarda3
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
Mohd Arif
 

Viewers also liked (20)

Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programming
 
Computer graphics file
Computer graphics fileComputer graphics file
Computer graphics file
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Computer Graphics Applications
Computer Graphics ApplicationsComputer Graphics Applications
Computer Graphics Applications
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)Graphics Programming in C under GNU Linux (Ubuntu distribution)
Graphics Programming in C under GNU Linux (Ubuntu distribution)
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Applications of computer graphics
Applications of computer graphicsApplications of computer graphics
Applications of computer graphics
 
Computer Graphics 471 Project Report Final
Computer Graphics 471 Project Report FinalComputer Graphics 471 Project Report Final
Computer Graphics 471 Project Report Final
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 

Similar to Computer Graphics Practical

Applications of cg
Applications of cgApplications of cg
Applications of cg
Ankit Garg
 
Computer graphics 9068
Computer graphics  9068Computer graphics  9068
Computer graphics 9068
1061992
 

Similar to Computer Graphics Practical (20)

Graphics file
Graphics fileGraphics file
Graphics file
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
computer graphics unit 1.ppt
computer graphics unit 1.pptcomputer graphics unit 1.ppt
computer graphics unit 1.ppt
 
Digital design
Digital designDigital design
Digital design
 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System Overview
 
topic_- introduction of computer graphics.
   topic_- introduction of computer graphics.   topic_- introduction of computer graphics.
topic_- introduction of computer graphics.
 
CG_1.pdf
CG_1.pdfCG_1.pdf
CG_1.pdf
 
computer graphics unit 1-I.pptx
computer graphics unit 1-I.pptxcomputer graphics unit 1-I.pptx
computer graphics unit 1-I.pptx
 
Computer graphics by bahadar sher
Computer graphics by bahadar sherComputer graphics by bahadar sher
Computer graphics by bahadar sher
 
Introduction to Computer Graphics
Introduction to Computer GraphicsIntroduction to Computer Graphics
Introduction to Computer Graphics
 
Compute graphics
Compute graphicsCompute graphics
Compute graphics
 
Cg
CgCg
Cg
 
Cg applications
Cg applicationsCg applications
Cg applications
 
Introduction_computer_graphics_unit-1.pptx
Introduction_computer_graphics_unit-1.pptxIntroduction_computer_graphics_unit-1.pptx
Introduction_computer_graphics_unit-1.pptx
 
Applications of cg
Applications of cgApplications of cg
Applications of cg
 
unit1_updated.pptx
unit1_updated.pptxunit1_updated.pptx
unit1_updated.pptx
 
Computer graphics 9068
Computer graphics  9068Computer graphics  9068
Computer graphics 9068
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
 
AutoCAD Tutorial AB.pptx
AutoCAD Tutorial AB.pptxAutoCAD Tutorial AB.pptx
AutoCAD Tutorial AB.pptx
 
Introduction of Computer aided Design
Introduction of Computer aided DesignIntroduction of Computer aided Design
Introduction of Computer aided Design
 

More from Neha Sharma

Transportation Problem in Operational Research
Transportation Problem in Operational ResearchTransportation Problem in Operational Research
Transportation Problem in Operational Research
Neha Sharma
 
Microsoft Surface
Microsoft SurfaceMicrosoft Surface
Microsoft Surface
Neha Sharma
 
Terrorist Attacks
Terrorist AttacksTerrorist Attacks
Terrorist Attacks
Neha Sharma
 
Microsoft Surface
Microsoft Surface Microsoft Surface
Microsoft Surface
Neha Sharma
 
Top Reality Shows
Top Reality ShowsTop Reality Shows
Top Reality Shows
Neha Sharma
 
Interesting Facts about Maths
Interesting Facts about MathsInteresting Facts about Maths
Interesting Facts about Maths
Neha Sharma
 

More from Neha Sharma (9)

Web Browsers
Web BrowsersWeb Browsers
Web Browsers
 
Transportation Problem in Operational Research
Transportation Problem in Operational ResearchTransportation Problem in Operational Research
Transportation Problem in Operational Research
 
Microsoft Surface
Microsoft SurfaceMicrosoft Surface
Microsoft Surface
 
Terrorist Attacks
Terrorist AttacksTerrorist Attacks
Terrorist Attacks
 
Microsoft Surface
Microsoft Surface Microsoft Surface
Microsoft Surface
 
Top Reality Shows
Top Reality ShowsTop Reality Shows
Top Reality Shows
 
IPv6
IPv6IPv6
IPv6
 
Steganography
SteganographySteganography
Steganography
 
Interesting Facts about Maths
Interesting Facts about MathsInteresting Facts about Maths
Interesting Facts about Maths
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

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
  • 19. Program 2. Digital Differential Analyzer For 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<<"ttt------------------n"; cout<<"tttDDA By Neha Sharman"; cout<<"ttt------------------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) { if(m<=1) { Page | 18
  • 21. Program3: Bresenham Line Drawing Algorithm CODING: #include<graphics.h> #include<iostream.h> #include<conio.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,""); int f,fe,fne,x1,x2,y1,y2,dy,dx,m; cout<<"-----------------"; cout<<"nBy Neha Sharman"; cout<<"-----------------"; cout<<"nenter the cordinatesn"; cin>>x1>>y1>>x2>>y2; dy=y2-y1; dx=x2-x1; f=(2*dy)-dx; while(x1<=x2) { if(f<=0) { x1=x1+1; //y1=y1; Page | 20
  • 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
  • 31. Program 8: DirectPolynomial Algorithm Of Ellipse Drawing CODING: #include<conio.h> #include<iostream.h> #include<graphics.h> #include<math.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,""); float xc,yc,rx,ry,x1,y1,x2; cout<<"DIRECT ELLIPSE BY NEHA SHARMAn"; cout<<"enter xc,yc,x radius,y radiusn" ; cin>>xc>>yc>>rx>>ry; x1=0; x2=rx; while(x1<=x2) { y1=(ry/rx)*sqrt((rx*rx)-(x1*x1)); putpixel(x1+xc,y1+yc,WHITE); putpixel(x1+xc,-y1+yc,WHITE); putpixel(-x1+xc,-y1+yc,WHITE); Page | 30
  • 33. Program 9: Polar Ellipse Drawing Algorithm CODING: #include<conio.h> #include<iostream.h> #include<graphics.h> #include<math.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,""); float xc,yc,rx,ry,t1,t2,x1,y1,x2; cout<<"POLAR ELLIPSE BY NEHA SHARMAn"; cout<<"enter xc,yc,x radius,y radiusn" ; cin>>xc>>yc>>rx>>ry; t1=0; t2=90; while(t1<=t2) { y1=ry*sin(t1); x1=rx*cos(t1); putpixel(x1+xc,y1+yc,WHITE); putpixel(x1+xc,-y1+yc,WHITE); putpixel(-x1+xc,-y1+yc,WHITE); Page | 32
  • 35. 10. Program To Draw Ellipse Using Midpoint Ellipse Algorithm Coding: #include<iostream.h> #include<conio.h> #include<graphics.h> #include<math.h> void main() { int gd=DETECT, gm; initgraph(&gd,&gm,""); float xc,yc,x,y,xr,yr,f; cout<<”tttt------------------------------------”; cout<<"ntttMID POINT ELLIPSE BY MOHITn"; cout<<”ntttt---------------------------------------”; cout<<"nEnter the coordinates xc,yc,xr ,yr"; cin>>xc>>yc>>xr>>yr; x=0; y=yr; f=(yr*yr)+(xr*xr)/4-(xr*xr)*yr; while(2*(yr*yr)*x<=2*(xr*xr)*y) { if(f<=0) { f=f+(3+(2*x))*(yr*yr); x++; putpixel(x+xc,y+yc,WHITE); putpixel(-x+xc,y+yc,WHITE); putpixel(-x+xc,-y+yc,WHITE); Page | 34