basics of computer graphics lab
DESCRIPTION
basic concepts of computer graphics lab.TRANSCRIPT
Computer Graphics LabBy Priya Goyal
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.
Basic functions to draw shapes in graphicsShape 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
Structure of graphics program
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main( )
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
……………………
…………………….
getch( );
closegraph( );
}
Location of BGI folder, where
display files are saved. Write the
location of (C:-TC-BGI)
Initialization of
graph
Draw a Pixel
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
Putpixel(100,100,RED)
getch( );closegraph( );}
Putpixel(X1,Y1,Color)
Draw a line
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
Line(100,100,200,200)
getch( );closegraph( );}
Line(X1,Y1,X2,Y2)
Draw a Rectangle
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
Rectangle(100,100,200,200)
getch( );closegraph( );}
rectangle(X1,Y1,X2,Y2)
Draw a circle
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
Circle(100,100,10)
getch( );closegraph( );}
circle(X1,Y1,radius)
Draw an ellipse
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
ellipse(100,100,0,360,20,10);
getch( );closegraph( );}
ellipse(x1,y1,0,360,xAxisRadius,yAxisRadius)
Draw an Arc
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
arc(100,100,90,280,10);
getch( );closegraph( );}
arc(x1,y1,StartingAngle,EndingAngle,Radius)
Draw a Bar
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
bar(100,100,200,200);
getch( );closegraph( );}
Bar(Left,Top,Right,Bottom)
Draw a 3D bar
#include<graphics.h>#include<stdio.h>#include<conio.h>void main( ){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");
bar3d(100,100,200,200,10,1);
getch( );closegraph( );}
Bar3d(left,top,right,bottom,depth,topflag)
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.