Computer Graphics LAB FILE
Computer Graphics LAB FILE
Submitted To:
Submitted By:
Ashish
A2305214229
ASET(AUUP)
B.Tech CSE
4-CSE-4X
INDEX
S.NO
Category
Code
of
assignment
Exp
no.
Name
Of Experiment
Date of Date of
allotmen Evaluatio
t
n
MaxMark
s
Mandatory
Experimen
t
LR(10) 1
Mandatory
Experimen
t
LR(10) 2
Mandatory
Experimen
t
LR(10) 3
Mandatory
Experimen
t
LR(10) 4
Mandatory
Experimen
t
LR(10) 5
Marks
Obtaine
d
Signatur
of
Faculty
Mandatory
Experimen
t
LR(10) 6
Mandatory
Experimen
t
LR(10) 7
Mandatory
Experimen
t
LR(10) 8
Mandatory
Experimen
t
LR(10) 9
Mandatory
Experimen
t
LR(10) 10
Mandatory
Experimen
t
LR(10) 11
Mandatory
Experimen
t
LR(10) 12
Mandatory
Experimen
t
LR(10) 13
14
Design
PR(10) 15
based open
Ended
Experimen
t
Design
PR(10) 16
based open
Ended
Experimen
t
Viva
Viva(5
)
15.
10
16.
10
Criteria
Clarity of the
subject
Quality of
theoretical
discussion
Total
Total Marks
2
Marks Obtained
Comments
A Pre-Note:
1. INITGRAPH:
Initializes the graphics system.
FUNCTION PROTOTYPE
void far initgraph(int far* graphdriver)
WORKING
To start the graphics system, you must first call the initgraph function
Initgraph initializes the graphic system by loading a graphics driver
from disk (or validating a registered driver) then putting the system into
the graphics mode.
Initgraph also resets all the graphic settings (colour, pallete, current
position, viewport, etc) to their deports and then resets graph.
2. CLOSEGRAPH:
Shuts down the graphics system
FUNCTION PROTOTYPE
void far closegraph(void)
WORKING
Closegraph deallocates all memory allocated by the graphics system
It then restores the screen to the mode it was in before you called
initgraph
RETURN VALUE
None
3. FLOODFILL:
FUNCTION PROTOTYPE
void far floodfill(int x, int y, int border)
WORKING
Floodfill fills an enclosed area on a bitmap device
The area bounded by the colour border is flooded with the current fill
pattern and fil colour
Use fillpoly instead of floodfill wherever possible so you can maintain
code compatibility with future versions
Floodfill does not work with the IBM-8514 driver
(x, y) is seed point:
If the seed is within an enclosed area, the inside will be filled.
If the seed is outside an enclosed area, the exterior will be filled.
RETURN VALUE
If an error occurs while filling the region,, graph result returns 1
FUNCTION PROTOTYPE
Int far getclour(void)
WORKING
Getcolour returns the current drawing colour
Setcolour sets the current drawing colour to colour, which can range
from 0 to getmaxcolour
To set a drawing colour with setcolor, you can pass either the colour
number or the equivalent colour name
FUNCTION PROTOTYPE
Unsigned far getpixel(int x, int y)
Void far putpixel(int x, int y, int colour)
WORKING
Getpixel gets the colour of a specified pixel located at (x, y)
Putpixel plots a point in the colour defined at (x, y)
RETURN VALUE
Getpixel returns the colour of the given pixel
Putpixel does not return anything
Implementation:
Here we printed a line by choosing a starting a point and using PUTPIXEL.
FUNCTION PROTOTYPE:
Void far arc(int x, int y, int stangle, int endangle, int radius)
Void far circle(int x, int y, int radius)
Void far pieslice(int x, int y, int stangle, int endangle, int radius)
WORKING
Arc draws a circular arc in the current drawing colour
Circle draws a circle in the current drawing colour
Pieslice draws a pie slice in the current drawing colour, then fills it
using, the current fill pattern and fill colour
FUNCTION PROTOTYPE
Void far ellipse(int x, int y, int stangle, int endangle, int xradius, int
yradius)
Void far fillellipse(int x, int y, int xradius, int yradius)
Void far sector(int x, int y, int stangle, int endangle, int xradius, int
yradius)
WORKING
Ellipse draws an elliptical arc in the current drawing colour
Fillellipse draws an elliptical arc in the current drawing colour and then
fills it with fill colour and fill pattern
Sector draws an elliptical pie slice in the current drawing colour and
then fills it using
Implementation:
Code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
int main()
{
clrscr();
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
setfillstyle(EMPTY_FILL, getmaxcolor());
pieslice(100, 100, 45, 135, 100);
arc(500, 100,45,135, 100);
sector(100, 450, 45, 135,50,100);
ellipse(525, 400, stangle, endangle,xradius, yradius);
for(int i=0;i<5;i++)
{
delay(400);
circle(midx, midy, radius+i);
}
getch();
closegraph();
return 0;
}
Output:
Various Geometrical Figures Drawn using their respective functions
FUNCTION PROTOTYPE
Void far line(int x1, int y1, int x2, int y2)
void far lineto(int x, int y)
WORKING
Line draws a line from (x1, y1) to (x2, y2) using the current colour, line
style and thickness. It does not update the current position CP.
Linerel draws a line from the CP to the point that is relative distance (dx,
dy) from CP, then advances the CP by (dx, dy)
Lineto draws a line from CP to (x, y) and the advances the CP to (x, y)
RETURN VALUE
None
Implementation:
Code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
moveto(600, 30);
lineto(260, 120);
outtextxy(260,120,"THIS IS A LINE FROM LINETO() FUNCTION");
/* clean up */
getch();
closegraph();
return 0;
Output:
9. RECTANGLE:
Draws a rectangle in graphics mode
DECALARTION
void far rectangle(int left, int top, int right, int bottom)
WORKING
It draws a rectangle in the current line style, thickness and drawing
colour
(left, top) is the upper left corner of the rectangle and (right, bottom) is
its lower right corner
RETURN VALUE
None
Implementation:
Code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int left, top, right, bottom;
/* draw a rectangle */
rectangle(left,top,right,bottom);
/* clean up */
getch();
closegraph();
return 0;
}
Output:
Criteria
Total Marks
Concept (A)
Implementation
(B)
Performance (C)
Total
2
2
Marks
Obtained
2
6
Comments
int main( )
{
float x,y,x1,y1,x2,y2,dx,dy,pixel;
int i,gd,gm;
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
detectgraph(&gd,&gm);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
pixel=dx;
else
pixel=dy;
Xinc = dx/pixel;
Yinc = dy/pixel;
x=x1;
y=y1;
i=1;
while(i<=pixel)
{
putpixel(x,y,1);
x=x+Xinc;
y=y+Yinc;
i=i+1;
delay(100);
}
getch();
closegraph();
return 0;
}
Output:
SIGNATURE :
Criteria
Total Marks
Concept (A)
Implementation
(B)
Performance (C)
Total
2
2
Marks
Obtained
2
6
Comments
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int main()
{
int x1, x2, y1, y2;
int i,gd,gm;
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
detectgraph(&gd,&gm);
initgraph(&gdriver, &gmode, "c://TURBOC3//BGI");
dy = y2 - y1;
p = 2*dy - dx;
if(x1 > x2)
{
x = x2;
y = y2;
xend = x1;
}
else
{
x = x1;
y = y1;
xend = x2;
}
putpixel(x, y, RED);
while(x < xend)
{
if(p < 0)
{
x = x + 1;
putpixel(x, y, 10);
p = p + (2*dy);
}
else
{
x = x + 1;
y = y + 1;
putpixel(x, y, 10);
p = p + (2*dy) - (2*dx);
}
}
}
Output :
SIGNATURE :
Criteria
Total Marks
Concept (A)
Implementation
(B)
Performance (C)
Total
2
2
Marks
Obtained
2
6
Comments
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void circlemid(int,int,int);
void circlepixel(int,int,int,int);
void main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int r=200;
int x=250,y=250;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
circlemid(x,y,r);
getch();
}
void circlemid(int xcenter, int ycenter, int radius)
{
int x=0;
int y=radius;
int f=1-radius;
circlepixel(xcenter,ycenter,x,y);
while(x<y)
{
x++;
if(f<0)
f+=2*x+1;
else
{
y--;
f+=2*(x-y)+1;
}
circlepixel(xcenter,ycenter,x,y);
}
}
void circlepixel(int xcenter, int ycenter,int x,int y)
{
putpixel(xcenter + x,ycenter + y,RED);
putpixel(xcenter - x,ycenter + y,YELLOW);
putpixel(xcenter + x,ycenter - y,CYAN);
Output :
Criteria
Total Marks
Concept (A)
Implementation
(B)
Performance (C)
Total
2
2
Marks
Obtained
2
6
Comments
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
}
}
}
int main()
{
float a,b;
int xc,yc;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
xc=getmaxx()/2;
yc=getmaxy()/2;
Eclipse(xc,yc,a,b);
system("pause");
closegraph();
return 0;
}
Output :
SIGNATURE :
Criteria
Total Marks
Concept (A)
Implementation
(B)
Performance (C)
Total
2
2
2
6
Marks
Obtained
Comments