Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 17

Introduction to C++ Graphics

functions of graphics.h
• C graphics using graphics.h functions can be used
to draw different shapes, display text in different
fonts, change colors and many more.

• Using functions of graphics.h in turbo c compiler


you can make graphics programs, animations,
projects and games.
Geometric primitive

• The term geometric primitive in


computer graphics and CAD systems is used in
various senses, with the common meaning of
the simplest geometric objects that the
system can handle (draw, store).
Commonly used geometric primitives include:

• points
• lines and line segments
• planes
• circles and ellipses
• triangles and other polygons
• spline curves
The C++ graphics plane
(0,0) X plane

Y plane
InitGraph
• InitGraph initializes the graph package.

Implementations

int gd = DETECT, gm;  


initgraph(&gd, &gm, "C:\\TC\\BGI");
closegraph function in c
• closegraph function closes the graphics mode,
deallocates all memory allocated by graphics
system and restores the screen to the mode it was
in before you called initgraph.

• Declaration :- void closegraph();


line function in c
• 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.

• Declaration :- void line(int x1, int y1, int x2, int y2);
// program draws a line from (100, 100) to (200, 200).
#include<graphics.h>
#include<conio.h>  
main() {
int gd = DETECT, gm;  
initgraph(&gd, &gm, "C:\\TC\\BGI");  

line(100, 100, 200, 200);  


getch();
closegraph();
return 0;
}
circle function in c
• circle function is used to draw a circle with center
(x,y) and third parameter specifies the radius of the
circle.

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


//In the above program (100, 100) are coordinates of
center of the circle and 50 is the radius of circle.

#include<graphics.h>
#include<conio.h>  

main() {
int gd = DETECT, gm;  
initgraph(&gd, &gm, "C:\\TC\\BGI");  
circle(100, 100, 50);  
getch();
closegraph();
return 0;
}
rectangle function
• Declaration :- void rectangle(int left, int top, int
right, int bottom);

• rectangle function is used to draw a rectangle.


Coordinates of left top and right bottom corner are
required to draw the rectangle. left specifies the X-
coordinate of top left corner, top specifies the Y-
coordinate of top left corner, right specifies the X-
coordinate of right bottom corner, bottom specifies
the Y-coordinate of right bottom corner.
arc function
• Declaration :- void arc(int x, int y, int stangle, int
endangle, int radius);

arc function is used to draw an arc with center (x,y)


and stangle specifies starting angle, endangle
specifies the end angle and last parameter specifies
the radius of the arc. arc function can also be used
to draw a circle but for that starting angle and end
angle should be 0 and 360 respectively.
sector function
• Sector function draws and fills an elliptical pie
slice.
• Declaration :- void sector( int x, int y, int
stangle, int endangle, int xradius, int yradius);
bar function
• Declaration :- void bar(int left, int top, int right, int
bottom);

• Bar function is used to draw a 2-dimensional,


rectangular filled in bar .
• Coordinates of left top and right bottom corner are
required to draw the bar.
• Left specifies the X-coordinate of top left corner, top
specifies the Y-coordinate of top left corner, right
specifies the X-coordinate of right bottom corner,
bottom specifies the Y-coordinate of right bottom
corner. Current fill pattern and fill color is used to fill the
bar.
getx function
• getx function returns the X coordinate of current
position.

• Declaration :- int getx();


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.

You might also like