basics of computer graphics lab

13
Computer Graphics Lab By Priya Goyal

Upload: priya-goyal

Post on 29-Jun-2015

2.049 views

Category:

Education


6 download

DESCRIPTION

basic concepts of computer graphics lab.

TRANSCRIPT

Page 1: Basics of Computer graphics lab

Computer Graphics LabBy Priya Goyal

Page 2: Basics of Computer graphics lab

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.

Page 3: Basics of Computer graphics lab

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

Page 4: Basics of Computer graphics lab

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

Page 5: Basics of Computer graphics lab

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)

Page 6: Basics of Computer graphics lab

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)

Page 7: Basics of Computer graphics lab

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)

Page 8: Basics of Computer graphics lab

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)

Page 9: Basics of Computer graphics lab

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)

Page 10: Basics of Computer graphics lab

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)

Page 11: Basics of Computer graphics lab

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)

Page 12: Basics of Computer graphics lab

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)

Page 13: Basics of Computer graphics lab

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.