2. How to run the graphics program in Turbo C++
• Open turbo C++
• Click on Option => Linker => Library
• Click on Graphics(mark it as ‘X’)
• Click on OK
Now you can run your graphics programs.
3. Basic functions to draw shapes in graphics
Shape Function syntax
pixel Draw a pixel Putpixel (X1,Y1,Color)
Line Draw a line Line(X1,Y1,X2,Y2)
Rectangle Draw a rectangle Rectangle(Left,Top,Right,Bottom)
Circle Draw a circle Circle(X,Y,Radius)
Ellipse Draw a ellipse Ellipse(X1,Y1,0,360,XaxisRadius,YaxisRadius)
Arc Draw a arc Arc(X1,Y1,StartingAngle,EndingAngle,Radius)
Bar Draw a filled rectangle Bar(Left,Top,Right,Bottom)
Bar3d Draw a filled 3d rectangle Bar3d(Left,Top,Right,Bottom,depth,topflag)
**topflag will be 0 or 1**
Here X1=distance of first point of shape from X axis,
X2=Distance of last point of shape from X axis
Here Y1=distance of first point of shape from Y axis,
Y2=Distance of last point of shape from Y axis
4. Structure of graphics program
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main( )
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:TCBGI");
……………………
…………………….
getch( );
closegraph( );
}
Location of BGI folder, where
display files are saved. Write the
location of (C:-TC-BGI)
Initialization of
graph
12. Draw a 3D bar
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main( )
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:TCBGI");
bar3d(100,100,200,200,10,1);
getch( );
closegraph( );
}
Bar3d(left,top,right,bottom,depth,topflag)
13. Assignment
Q.1 Draw a flag using line and circle.
Q.2 Draw a hut using line, rectangle and circle.
Q.3 Draw a smiley face using ellipse, circle and arc.
Q.4 Draw a fish using arc, circle and line.