Practical File CGM
Practical File CGM
Practical File CGM
VISHWAVIDHYALAYA,INDORE
PRACTICAL FILE
Computer Graphics and Multimedia
SESSION:JUL-DEC 2022
Shri VaishnavVidyapeethVishwavidyalaya
Shri Vaishnav Institute of Information Technology
Department of Computer Science & Engineering
Computer Graphics & Multimedia(BTCS303)
LIST OF EXPERIMENTS
7.
8.
9.
10
Note :-
Student you must complete your practical file according to all instruction given before.
Font style :-Times New Roman, text size 12,heading size 14 and bold,proper justify.
You must come for internal viva with lab file hard copy in proper format. Submit file as
instructed you in proper format.
1. Front page
2. Index page
3. List of experiments
Computer Graphics & Multimedia [BTCS303]
Experiment No.:- 1
Aim: - To Study various in build graphics functions in C library.
Ans: - 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 we can make graphics programs, animations, projects, and games. We
can draw circles, lines, rectangles, bars and many other geometrical figures. We can
change their colors using the available functions and fill them.
Initgraph
Getpixel
Putpixel
Floodfill
Arc
"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.
Declaration: void arc(int x, int y, int stangle, int endangle, int radius);
Circle
Circle function is used to draw a circle with center (x,y) and third parameter
specifies the radius of the circle. The code given below draws a circle.
Pieslice
Pieslice function is used to draw and fill a pie slice with center at (x, y) and
given radius r. The slice travels from s_angle to e_angle which are starting
and ending angles for the pie slice. The angles for pie-slice are given in
degrees and are measured counterclockwise.
Declaration: void pieslice(int x, int y, int s_angle, int e_angle, int r);
Eclipse
Declaration:
void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);
Fillelipse
Fillellipse function use to draw and fill an ellipse with center at (x, y) and
(x_radius, y_radius) as x and y radius of ellipse.
Sector
Declaration: void sector( int x, int y, int stangle, int endangle, int xradius, int
yradius);
Getcolor
Setcolor
Line
Declaration: void line(int x1, int y1, int x2, int y2);
Linerel
Linerel function draws a line from the current position(CP) to a point that is
a relative distance (x, y) from the CP, then advances the CP by (x, y). You
can use getx and gety to find the current position.
Lineto
Function lineto draws a line from the current position (CP) to the point (x,
y), you can get current position using getx and gety function.
Experiment No.:- 2
Aim: - Write a program to draw a line using DDA algorithm.
Program: -
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
void main()
{
clrscr();
int gd=DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
cout << " Digital Differential Analyzer Algorithm \n"<<endl;
int x1, y1, x2, y2, del_x, del_y, steps, i, x_inc, y_inc;
cout << "Enter value for x1 : " ;
cin >> x1;
cout << "Enter value for y1 : " ;
cin >> y1;
cout << "Enter value for x1 : " ;
cin >> x2;
cout << "Enter value for y2 : " ;
cin >> y2;
del_x = x2 - x1 ;
del_y = y2 - y1 ;
cout << "The Value of del_x : " << del_x << endl ;
cout << "The Value of del_y : " << del_y << endl ;
if (del_x > del_y)
steps = del_x ;
else
steps = del_y ;
Output:-
Experiment No.:- 3
Aim: - Write a program to draw a line using Bresenham‘s algorithm.
Program:-
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
void main()
{
clrscr();
int gd=DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
int x1, y1, x2, y2, del_x, del_y,p;
cout << " BRESENHAM ALGORITHM \n"<<endl;
cout << "Enter value for x1 : " ;
cin >> x1;
cout << "Enter value for y1 : " ;
cin >> y1;
cout << "Enter value for x1 : " ;
cin >> x2;
cout << "Enter value for y2 : " ;
cin >> y2;
del_x = x2 - x1 ;
del_y = y2 - y1 ;
cout << "The Value of del_x : " << del_x << endl ;
cout << "The Value of del_y : " << del_y << endl ;
p = 2*del_y-del_x;
while(x1<x2)
{
if(p>=0)
{
putpixel(x1,y1,WHITE);
y1=y1+1;
p=p+(2*del_y)-(2*del_x);
}
else
{
putpixel(x1,y1,RED);
p=p+(2*del_y);
}
x1=x1+1;
}
delay(100);
getch();
}
Output:-
Experiment No.:- 4
Aim: - Write a program to draw a line using Mid Point Line Drawing
algorithm.
Program:-
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
putpixel(x,y,WHITE);
cout << x << "," << y << "\n";
}
}
else if(dx<dy)
{
int d = dx - (dy/2);
int x = X1, y = Y1;
putpixel(x,y,CYAN);
cout << x << "," << y << "\n";
while (y < Y2)
{
y++;
// E or East is chosen
if (d < 0)
d = d + dx;
else
{
d += (dx - dy);
x++;
}
putpixel(x,y,BLUE);
cout << x << "," << y << "\n";
}
}
}
int main()
{
int gd = DETECT, gm;
Output:-
Experiment No.:- 5
Aim: - Write a program to draw a circle using Mid Point Circle Drawing
algorithm.
Program:-
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
void main()
{
clrscr();
int gd=DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
float r=100,a=340,b=280,x,y,p0;
cout<<" Mid Point Circle Drawing Algorithm \n"<<endl;
cout<<"Center of the Circle lie at "<<endl;
cout<<"x co-ordinate = "<<a<<endl;
cout<<"y co-ordinate = "<<b<<endl;
cout<<"Radius of the circle = "<<r<<endl;
x=0;
y=r;
putpixel (a, b+r, WHITE);
putpixel (a, b-r, WHITE);
putpixel (a-r, b, WHITE);
putpixel (a+r, b, WHITE);
p0=(5/4)-r;
while(x<=y)
{
if(p0<0)
{
x=x+1;
p0 = p0+(4*x)+6;
}
else
{
y=y-1;
p0 = p0+2*(x-y)+5;
}
x=x+1;
putpixel(a + x, b + y, WHITE);
putpixel(a + y, b + x, WHITE);
putpixel(a - y, b + x, WHITE);
putpixel(a - x, b + y, WHITE);
putpixel(a - x, b - y, WHITE);
putpixel(a - y, b - x, WHITE);
putpixel(a + y, b - x, WHITE);
putpixel(a + x, b - y, WHITE);
}
getch();
Output:-