Laboratory Manual: Computer Graphics Lab
Laboratory Manual: Computer Graphics Lab
Laboratory Manual: Computer Graphics Lab
Computer graphics are pictures and films created using computers. Usually, the term refers to
computer-generated image data created with the help of specialized graphical hardware and
software. It is a vast and recently developed area of computer science. The phrase was coined in
1960, by computer graphics researchers Verne Hudson and William Fetter of Boeing. It is often
abbreviated as CG, though sometimes erroneously referred to as computer-generated imagery
(CGI).
Some topics in computer graphics include user interface design, sprite graphics, vector graphics,
3D modelling, shaders, GPU design, implicit surface visualization with ray tracing, and computer
vision, among others. The overall methodology depends heavily on the underlying sciences of
geometry, optics, and physics.
Computer graphics is responsible for displaying art and image data effectively and meaningfully
to the consumer. It is also used for processing image data received from the physical world.
Computer graphics development has had a significant impact on many types of media and has
revolutionized animation, movies, advertising, video games, and graphic design in general.
Pixel
In digital imaging, a pixel is a single point in a raster image. Pixels are placed on a regular 2-
dimensional grid, and are often represented using dots or squares. Each pixel is a sample of an
original image, where more samples typically provide a more accurate representation of the
original. The intensity of each pixel is variable; in color systems, each pixel has typically three
components such as red, green, and blue.
Graphics are visual presentations on a surface, such as a computer screen. Examples are
photographs, drawing, graphics designs, maps, engineering drawings, or other images. Graphics
often combine text and illustration. Graphic design may consist of the deliberate selection,
creation, or arrangement of typography alone, as in a brochure, flier, poster, web site, or book
without any other element. Clarity or effective communication may be the objective, association
with other cultural elements may be sought, or merely, the creation of a distinctive style.
Primitives
Primitives are basic units which a graphics system may combine to create more complex images
or models. Examples would be sprites and character maps in 2d video games, geometric
primitives in CAD, or polygons or triangles in 3d rendering. Primitives may be supported in
hardware for efficient rendering, or the building blocks provided by a graphics application.
Rendering
Rendering is the generation of a 2D image from a 3D model by means of computer programs. A
scene file contains objects in a strictly defined language or data structure; it would contain
geometry, viewpoint, texture, lighting, and shading information as a description of the virtual
scene. The data contained in the scene file is then passed to a rendering program to be processed
and output to a digital image or raster graphics image file. The rendering program is usually built
into the computer graphics software, though others are available as plug-ins or entirely separate
programs. The term "rendering" may be by analogy with an "artist's rendering" of a scene.
Although the technical details of rendering methods vary, the general challenges to overcome in
producing a 2D image from a 3D representation stored in a scene file are outlined as the graphics
pipeline along a rendering device, such as a GPU. A GPU is a device able to assist the CPU in
Computer Graphics Lab (RCS-653) Manual (CS, VI SEM) Page 8
calculations. If a scene is to look relatively realistic and predictable under virtual lighting, the
rendering software should solve the rendering equation. The rendering equation does not account
for all lighting phenomena, but is a general lighting model for computer-generated imagery.
'Rendering' is also used to describe the process of calculating effects in a video editing file to
produce final video output.
3D projection
3D projection is a method of mapping three dimensional points to a two dimensional plane. As
most current methods for displaying graphical data are based on planar two dimensional media,
the use of this type of projection is widespread, especially in computer graphics, engineering and
drafting.
In order to develop efficient software systems, it is essential that efficient algorithms and
appropriate graphics are used. The purpose of this laboratory manual is to introduce
undergraduate students to techniques for developing efficient graphics and algorithms in a
systematic manner. The manual serves as a guide for learning and implementing the 2-
Diemensional and 3-Diemensional transformation in a programming language (C/C++). It
basically focuses on translation, scaling, rotation and various other operations on computer
graphics with algorithm analysis and design. The manual contains procedures, and pre-
experiment questions to help students prepare for experiments.
This practical manual will be helpful for students of Computer Science & Engineering for
understanding the course from the point of view of applied aspects. Though all the efforts
have been made to make this manual error free, yet some errors might have crept in
inadvertently. Suggestions from the readers for the improvement of the manual are most
welcomed.
DO’s
DONT’S
1. Know the location of the fire extinguisher and the first aid box and how to use them
in case of an emergency.
2. Report fire or accidents to your faculty /laboratory technician immediately.
3. Report any broken plugs or exposed electrical wires to your
faculty/laboratory technician immediately.
4. Do not plug in external devices without scanning them for computer viruses.
While preparing the lab records, the student is required to adhere to the following guidelines:
Name
Roll No.
Section- Batch
Students are provided with the details of the experiment (Aim, pre-experimental questions,
procedure etc.) to be conducted in next lab and are expected to come prepared for each lab
class.
Faculty ensures that students have completed the required pre-experiment questions and they
complete the in-lab programming assignment(s) before the end of class. Given that the lab
programs are meant to be formative in nature, students can ask faculty for help before and
during the lab class.
Students’ performance will be assessed in each lab based on the following Lab Assessment
Components:
Assessment Criteria-1: Performance (Max. marks = 5)
Assessment Criteria-2: VIVA (Max. marks = 5)
Assessment Criteria-3: Record (Max. marks = 5)
In each lab class, students will be awarded marks out of 5 under each component head,
making it total out of 15 marks.
Description:
To graph a linear equation in slope-intercept form, we can use the information given by that
form. For example, y=2x+3 tells us that the slope of the line is 2 and the y-intercept is at (0,3).
This gives us one point the line goes through, and the direction we should continue from that
point to draw the entire line.
Pre-Experiment Questions:
Q3. What is the slope intercept form of the equation of the line?
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int dx,dy,x1,x2,y1,y2,m,b,x,y,xnd;
clrscr();
printf("enter x1,x2,y1,y2");
scanf("%d%d%d%d", &x1,&x2,&y1,&y2);
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
b=y1-m*x1;
if(dx<0)
{
x=x2;
xnd=x1;
y=y2;
}
if(dx>0)
{
x=x1;
xnd=x2;
y=y1;
}
while(x<xnd)
{
putpixel(x,y,5);
x=x+1;
y=m*x+b;
}
getch();
}
Post-Experiment Questions:
Q3. How do you find the equation of a line with two coordinates?
Description:
In computer graphics, a digital differential analyzer (DDA) is hardware or software used for interpolation of
variables over an interval between start and end point. DDAs are used for rasterization of lines, triangles and
polygons. They can be extended to non linear functions, such as perspective correct texture mapping, quadratic
curves, and traversing voxels.
In its simplest implementation for linear cases such as lines, the DDA algorithm interpolates values in interval
by computing for each xi the equations xi = xi−1 + 1, yi = yi−1 + m, where Δx = xend − xstart and Δy = yend − ystart
and m = Δy/Δx
Pre-Experiment Questions:
Source Code:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int dx,dy,x1,x2,y1,y2,xin,yin,l;
float x,y,i;
clrscr();
printf("enter x1,x2,y1,y2\n");
scanf("%d%d%d%d", &x1,&x2,&y1,&y2);
l=x2-x1;
dx=x2-x1;
dy=y2-y1;
for(i=1;i<=l;i++)
{
putpixel(x,y,5);
x=x+xin;
y=y+yin;
}
getch();
}
Output:-
Post-Experiment Questions:
Descriptions:
While algorithms such as Wu's algorithm are also frequently used in modern computer
graphics because they can support antialiasing, the speed and simplicity of Bresenham's line
algorithm means that it is still important. The algorithm is used in hardware such as plotters
and in the graphics chips of modern graphics cards. It can also be found in many software
graphics libraries. Because the algorithm is very simple, it is often implemented in either the
firmware or the graphics hardware of modern graphics cards.
The label "Bresenham’s" is used today for a family of algorithms extending or modifying
Bresenham's original algorithm.
Pre-Experiment Questions:
Q1. Explain Bresenham’s Algo?.
Q2. How you compare between DDA and Bresenham’s line algo?
Source Code:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int dx,dy,x1,x2,y1,y2,ds,d,x,y,xnd,ynd,dt;
clrscr();
printf("enter x1,x2,y1,y2\n");
scanf("%d%d%d%d", &x1,&x2,&y1,&y2);
dx=x2-x1;
dy=y2-y1;
dt=2*(dy-dx);
ds=2*dy;
d=2*dy-dx;
if(dx<0)
{
x=x2;
xnd=x1;
y=y2;
ynd=y1;
}
else
{
x=x1;
xnd=x2;
y=y1;
ynd=y2;
}
while(x<xnd)
{
putpixel(x,y,0);
if(d<0)
{
d=d+2*dy;
}
else
{
d=d+2*(dy-dx);
y=y+1;
}
Output:-
Post-Experiment Questions:
Descriptions:
The reference point (analogous to the origin of a Cartesian coordinate system) is called the
pole, and the ray from the pole in the reference direction is the polar axis. The distance from
the pole is called the radial coordinate or radius, and the angle is called the angular coordinate,
polar angle,
Scan conversion or scan converting rate is a video processing technique for changing the
vertical / horizontal scan frequency of video signal for different purposes and applications.
The device which performs this conversion is called a scan converter.
The application of scan conversion is wide and covers video projectors, cinema equipment,
TV and video capture cards, standard and HDTV televisions, LCD monitors, radar displays
and many different aspects of picture processing.
Pre-Experiment Question:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int h,k,r,ang=0, angnd=2.1214;
float i=0.1;
clrscr();
printf("enter h,k,r\n");
scanf("%d%d%d", &h,&k,&r);
while(angnd>ang)
{
x = r * cos ( ang) ;
y = r * sin (ang);
putpixel(x+h,y+k,5);
putpixel(y+h,x+k,5);
putpixel(-y+h,x+k,5);
putpixel(-x+h,y+k,5);
putpixel(-x+h,-y+k,5);
putpixel(-y+h,-x+k,5);
putpixel(y+h,-x+k,5);
putpixel(x+h,-y+k,5);
ang= ang + i;
}
getch();
}
Post-Experiment Questions
Descriptions:
Pre-Experiment Questions:
Q1. What is the difference between Bresenham’s circle drawing and midpoint circle?
Q2. What is symmetry concept of Circle? .
clrscr();
printf("enter h,k,y\n");
scanf("%d%d%d", &h,&k,&y);
r=y;
d=3-2*r;
x=0;
while(x<y)
{
if(d<0)
{
d=d+4*x+6;
x=x+1;
}
else
{
d=d+4*(x-y)+10;
y=y-1;
x=x+1;
}
putpixel(x+h,y+k,5);
putpixel(y+h,x+k,5);
putpixel(-y+h,x+k,5);
putpixel(-x+h,y+k,5);
putpixel(-x+h,-y+k,5);
putpixel(-y+h,-x+k,5);
putpixel(y+h,-x+k,5);
putpixel(x+h,-y+k,5);
}
getch();
}
Post-Experiment Questions:
Descriptions:
In computer graphics, the midpoint circle algorithm is an algorithm used to determine the
points needed for rasterizing a circle. Bresenham's circle algorithm is derived from the
midpoint circle algorithm. The algorithm can be generalized to conic sections.
This algorithm draws all eight octants simultaneously, starting from each cardinal direction
(0°, 90°, 180°, 270°) and extends both ways to reach the nearest multiple of 45° (45°, 135°,
225°, 315°). It can determine where to stop because when y = x, it has reached 45°. The
reason for using these angles is shown in the above picture: As y increases, it does not skip
nor repeat any y value until reaching 45°. So during the while loop, y increments by 1 each
iteration, and x decrements by 1 on occasion, never exceeding 1 in one iteration. This changes
at 45° because that is the point where the tangent is rise=run. Whereas rise>run before and
rise<run after.
Pre-Experiment Questions:
Q1. Compare between Bresenham’s circle drawing and midpoint circle.
Q2. What is the application of circle generating Algo?
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int h,k,x=0,y,r,d;
clrscr();
printf("enter h,k,y\n");
scanf("%d%d%d", &h,&k,&y);
r=y;
d=1-r;
while(x<y)
{
if(d<0)
{
d=d+2*x+3;
}
else
{
d=d+2*(x-y)+5;
y=y-1;
}
x=x+1;
putpixel(x+h,y+k,5);
putpixel(y+h,x+k,5);
putpixel(-y+h,x+k,5);
putpixel(-x+h,y+k,5);
putpixel(-x+h,-y+k,5);
putpixel(-y+h,-x+k,5);
putpixel(y+h,-x+k,5);
putpixel(x+h,-y+k,5);
}
getch();
}
Post-Experiment Questions:
Q1. What is decision parameter computer graphics?
Q2. Why midpoint circle algorithm is so called?
Aim: To Perform 2D Transformations such as Translation, Rotation, Scaling, Reflection and shearing
Descriptions:
Translation
A translation moves an object to a different position on the screen. You can translate a point in
2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new
coordinate (X’, Y’).
Rotation
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the following
figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X coordinate
with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will
get a new point P’ (X’, Y’).
Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you either
expand or compress the dimensions of the object. Scaling can be achieved by multiplying the
original coordinates of the object with the scaling factor to get the desired result.
Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a rotation
operation with 180°. In reflection transformation, the size of the object does not change.
Shear
A transformation that slants the shape of an object is called the shear transformation. There are
two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and other
shifts Y coordinate values. However; in both the cases only one coordinate changes its
coordinates and other preserves its values. Shearing is also termed as Skewing.
Pre-Experiment Questions:
Q1. The essential condition which is checked before insertion in a linked queue is?
Q2. The essential condition which is checked before deletion in a linked queue is?
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
#include<graphics.h>
void scaleline(int x1,int y1,int x2,int y2)
{
float sx,sy;
printf("enter scaling factor(sx,sy):");
scanf("%f%f",&sx,&sy);
line(x1,y1,x2,y2);
x1=sx*x1;
y1=sy*y1;
x2=sx*x2;
y2=sy*y2;
sleep(1);
line(x1,y1,x2,y2);
}
void translateline(int x1,int y1,int x2,int y2,int tx,int ty)
{
x1=x1+tx;
x2=x2+tx;
y1=y1+ty;
y2=y2+ty;
line(x1,y1,x2,y2);
}
void rotateline(int x1,int y1,int x2,int y2,int a)
{
x1=x1*cos(a)+y1*sin(a);
y1=-1*x1*sin(a)+y1*cos(a);
x2=x2*cos(a)+y2*cos(a);
y2=-1*x2*sin(a)+y2*cos(a);
line(x1,y1,x2,y2);
}
\\
switch(m)
{
case 1:switch(n)
{
case 1:scaleline(x1,y1,x2,y2);;
break;
case 2:scalecircle(xc,yc,r);
break;
}
break;
Post-Experiment Questions:
Description:
The Cohen–Sutherland algorithm is a computer-graphics algorithm used for line clipping. The
algorithm divides a two-dimensional space into 9 regions and then efficiently determines the lines
and portions of lines that are visible in the central region of interest
Both endpoints are in the viewport region (bitwise OR of endpoints = 00): trivial accept.
Both endpoints share at least one non-visible region, which implies that the line does not
cross the visible region. (Bitwise AND of endpoints ≠ 0): trivial reject.
➢
Both endpoints are in different regions: in case of this nontrivial situation the algorithm
finds one of the two points that is outside the viewport region (there will be at least one
point outside). The intersection of the outpoint and extended viewport border is then
calculated (i.e. with the parametric equation for the line), and this new point replaces the
outpoint. The algorithm repeats until a trivial accepts or reject occurs.
The numbers in the figure below are called outcodes. An outcode is computed for each of
the two points in the line. The outcode will have 4 bits for two-dimensional clipping, or 6
bits in the three-dimensional case. The first bit is set to 1 if the point is above the
viewport. The bits in the 2D outcode represent: top, bottom, and right, left. For example,
the outcode 1010 represents a point that is top-right of the viewport.
The Cohen–Sutherland algorithm can be used only on a rectangular clip window. For
other convex polygon clipping windows, use the Cyrus–Beck algorithm.
Pre-Experiment Questions:
Source Code:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void clip(float,float,float);
int i,j=0,n;
int rx1,rx2,ry1,ry2;
float x1[8],y1[8];
void main()
int gd=DETECT,gm;
int i,n;
float x[8],y[8],m;
clrscr();
initgraph(&gd,&gm,"");
scanf("%d%d%d%d",&rx1,&ry1,&rx2,&ry2);
printf("coordinates : ");
for(i=0;i<n;i++)
scanf("%f%f",&x[i],&y[i]);
cleardevice();
outtextxy(10,10,"Before clipping");
rectangle(rx1,ry1,rx2,ry2);
for(i=0;i<n-1;i++)
line(x[i],y[i],x[i+1],y[i+1]);
line(x[i],y[i],x[0],y[0]);
getch();
cleardevice();
for(i=0;i<n-1;i++)
m=(y[i+1]-y[i])/(x[i+1]-x[i]);
clip(x[i],y[i],m);
clip(x[0],y[0],m);
outtextxy(10,10,"After clipping");
rectangle(rx1,ry1,rx2,ry2);
for(i=0;i<j-1;i++)
line(x1[i],y1[i],x1[i+1],y1[i+1]);
getch();
if(e<rx1)
f+=m*(rx1-e);
e=rx1;
else if(e>rx2)
f+=m*(rx2-e);
e=rx1;
if(f<ry1)
e+=(ry1-f)/m;
f=ry1;
else if(f>ry2)
e+=(ry2-f)/m;
f=ry2;
x1[j]=e;
y1[j]=f;
j++;
Output:-
Enter the x1 & y1 coordinates:
X1:70
Y1:80
Enter the x2 & y2 coordinates:
X2 : 250
Y2 : 280
Post-Experiment Questions:
Descriptions:
In computer graphics, the Liang–Barsky algorithm (named after You-Dong Liang and Brian A.
Barsky) is a line clipping algorithm. The Liang–Barsky algorithm uses the parametric equation of a
line and inequalities describing the range of the clipping window to determine the intersections
between the line and the clip window. With these intersections it knows which portion of the line
should be drawn. This algorithm is significantly more efficient than Cohen–Sutherland. The idea of
the Liang–Barsky clipping algorithm is to do as much testing as possible before computing line
intersections.
1. A line parallel to a clipping window edge has {\displaystyle p_{i}=0}for that boundary.
2. If for that{\displaystyle i} {\displaystyle q_{i}<0}then the line is completely outside and can be
eliminated.
3. When {\displaystyle p_{i}<0}the line proceeds outside to inside the clip window, and
when {\displaystyle p_{i}>0} the line proceeds inside to outside.
4. For nonzero{\displaystyle p_{k}} {\displaystyle u=q_{i}/p_{i}}gives the intersection point.
Pre-Experiment Questions
#include<iostream>
#include<graphics.h>
#include<math.h>
float q1 = x1 - xmin;
float q2 = xmax - x1;
float q3 = y1 - ymin;
float q4 = ymax - y1;
xn1 = x1 + p2 * rn1;
yn1 = y1 + p4 * rn1; // computing new points
xn2 = x1 + p2 * rn2;
Computer Graphics Lab (RCS-653) Manual (CS, VI SEM) Page 46
yn2 = y1 + p4 * rn2;
setcolor(CYAN);
line(xn1, 467 - yn1, xn2, 467 - yn2); // the drawing the new line
setlinestyle(1, 1, 0);
int main() {
cout << "\nLiang-barsky line clipping";
cout << "\nThe system window outlay is: (0,0) at bottom left and (631,
467) at top right";
cout << "\nEnter the co-ordinates of the window(wxmin, wxmax,
wymin, wymax):";
float xmin, xmax, ymin, ymax;
cin >> xmin >> ymin >> xmax >> ymax;
cout << "\nEnter the end points of the line (x1, y1) and (x2,
y2):"; float x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
Post-Experiment Questions:
Description:.
Pre-Experiment Questions:
Source Code:-
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
float tx,ty,tz,sx,sy,sz,r;
float x[15][15],y[15][15],z[15][15];
int i,j=2,ch;
void transform()
{
x[i][j-1]=x[i][j-1]+tx;
x[i][j]=x[i][j]+tx;
y[i][j-1]=y[i][j-1]+ty;
y[i][j]=y[i][j]+ty;
z[i][j-1]=z[i][j-1]+tz;
z[i][j]=z[i][j]+tz;
}
void rotate()
{
if(i<=8)
{
x[i][j-1]=(x[i][j-1]*cos(r))-(y[i][j-1]*sin(r));
y[i][j-1]=(x[i][j-1]*sin(r))+(y[i][j-1]*cos(r));
x[i][j]=(x[i][j]*cos(r))-(y[i][j]*sin(r));
y[i][j]=(x[i][j]*sin(r))+(y[i][j]*cos(r));
}
else
Computer Graphics Lab (RCS-653) Manual (CS, VI SEM) Page 49
z[i][j-1]=(z[i][j-1]*cos(r))-(y[i][j-1]*sin(r));
y[i][j-1]=(z[i][j-1]*sin(r))+(y[i][j-1]*cos(r));
z[i][j]=(z[i][j]*cos(r))-(y[i][j]*sin(r));
y[i][j]=(z[i][j]*sin(r))+(y[i][j]*cos(r)); }
}
void scale()
{
x[i][j-1]=x[i][j-1]*sx;
x[i][j]=x[i][j]*sx;
y[i][j-1]=y[i][j-1]*sy;
y[i][j]=y[i][j]*sy;
z[i][j-1]=z[i][j-1]*sz;
z[i][j]=z[i][j]*sz;
}
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
x[1][1]=200,x[1][2]=250,y[1][1]=200,y[1][2]=200;
x[2][1]=200,x[2][2]=200,y[2][1]=200,y[2][2]=150;
x[3][1]=200,x[3][2]=250,y[3][1]=150,y[3][2]=150;
x[4][1]=250,x[4][2]=250,y[4][1]=150,y[4][2]=200;
x[5][1]=220,x[5][2]=270,y[5][1]=140,y[5][2]=140;
x[6][1]=270,x[6][2]=270,y[6][1]=140,y[6][2]=190;
x[7][1]=220,x[7][2]=220,y[7][1]=140,y[7][2]=190;
x[8][1]=220,x[8][2]=270,y[8][1]=190,y[8][2]=190;
z[9][1]=200,z[9][2]=220,y[9][1]=150,y[9][2]=140;
z[10][1]=250,z[10][2]=270,y[10][1]=150,y[10][2]=140;
z[11][1]=250,z[11][2]=270,y[11][1]=200,y[11][2]=190;
z[12][1]=220,z[12][2]=200,y[12][1]=190,y[12][2]=200;
textattr(0);
for(i=1;i<=12;i++)
{
if(i<=8)
line(x[i][j-1],y[i][j-1],x[i][j],y[i][j]);
else
line(z[i][j-1],y[i][j-1],z[i][j],y[i][j]);
}
for(i=1;i<=12;i++)
{
transform();
scale();
if(i<=8)
line(x[i][j-1],y[i][j-1],x[i][j],y[i][j]);
else
line(z[i][j-1],y[i][j-1],z[i][j],y[i][j]);
delay(500);
Computer Graphics Lab (RCS-653) Manual (CS, VI SEM) Page 51
}
break;
case 3:
printf("\nENTER X Y & Z VECTORS:");
scanf("%f%f%f",&sx,&sy,&sz);
printf("\nENTER ROTATION ANGLE:");
scanf("%f",&r);
clrscr();
r=(r*3.14/180);
for(i=1;i<=12;i++)
{
scale();
rotate();
if(i<=8)
line(x[i][j-1],y[i][j-1],x[i][j],y[i][j]);
else
line(z[i][j-1],y[i][j-1],z[i][j],y[i][j]);
delay(500);
}
break;
case 4:
printf("\nEND OF PROGRAM");
exit(0);
break;
}
}
getch();
return 0;
}
OUTPUT:
Post-Experiment Questions:
Q1. What is viewing transformation in computer graphics?
Q2. What is a scaling transformation?
Description:
A figure drawing is a drawing of the human form in any of its various shapes and postures using any of the
drawing media. The term can also refer to the act of producing such a drawing. The degree of representation
may range from highly detailed, anatomically correct renderings to loose and expressive sketches. A "life
drawing" is a drawing of the human figure from observation of a live model. A figure drawing may be a
composed work of art or a figure study done in preparation for a more finished work such as a painting
Figure drawing is arguably the most difficult subject an artist commonly encounters, and entire courses are
dedicated to the subject. The human figure is one of the most enduring themes in the visual arts, and the
human figure can be the basis of portraiture, illustration, sculpture, medical illustration, and other fields.
Pre-Experiment Questions:
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<process.h>
void main()
{
int graphdriver=DETECT,graphmode;
initgraph(&graphdriver,&graphmode,"...\\bgi");
line(100,100,150,50);
line(150,50,200,100);
line(100,100,200,100);
line(150,50,350,50);
line(200,100,350,100);
line(350,50,350,100);
circle(150,75,10);
rectangle(100,100,200,300);
rectangle(200,100,350,300);
rectangle(250,175,300,225);
line(250,175,300,225);
line(300,175,250,225);
line(125,300,125,225);
line(175,300,175,225);
arc(150,225,0,180,25);
getch();
closegraph();
Post-Experiment Questions
Pre-Experiment Questions:
Q1. Describe blobby objects?
Algorithm
Source Code:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
line(100,100,200,20);
line(200,20,25,250);
line(25,250,175,175);
line(175,175,230,330);
line(230,330,132,123);
line(132,123,210,190);
line(210,190,321,234);
line(321,234,345,267);
line(345,267,324,354);
line(324,354,100,100);
getch();
}
Post-Experiment Questions:
Q1. What do you understand by color filing?
Q2. What is B-Spline?
Description
Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with
particular colors, you need to determine the pixels falling on the border of the polygon and those which
fall inside the polygon. In this chapter, we will see how we can fill polygons using different techniques.
1. Scan line Algo
2. Flood fill Algo
3. Boundary fill Algo
Source Code:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
int i,maxx,maxy
clrscr();
int poly[8];
maxy=getmaxy();
poly[0]=20;
poly[1]=maxy/20;
poly[2]=maxx-20;
poly[3]=20;
poly[4]=maxx-50;
poly[5]=maxx-20;
poly[6]=maxx-2;
poly[7]=maxx-2;
setfillstyle(i,getmaxcolor());
fillpoly(4,poly);
getch();
closegraph();
return;
Output:-
2. Amrendra N Sinha and Arun D Udai,” Computer Graphics”, Tata MCGraw Hill.
3. Donald Hearn and M Pauline Baker, “Computer Graphics with OpenGL”, Pearson
education
AKTU SYLLABUS
11. To perform basic operations on image using any image editing software
12. To draw different shapes such as hut, face, kite, fish etc.