Вы находитесь на странице: 1из 69

CS2405 COMPUTER GRAPHICS LABORATORY

LAB MANUAL

Prepared by

Mr.S.Manikandan, M.E(Hons)
Assistant Professor
Department of Information Technology
EGS Pillay Engineering College, Nagapattinam

CS2405 Computer Graphics Lab

Page 1

E.G.S.PILLAY ENGINEERING COLLEGE NAGAPATTINAM


DEPARTMENT OF INFORMATION TECHNOLOGY

INFORMATION ON COURSE
Course : CS2405 Computer Graphics Lab
Course Designed By: Anna University, Chennai.
College Name : E.G.S.Pillay Engineering College,
Nagapattinam
Year/Semester: IV/VII Information Technology
REQUIRED
TEXT
AND
SUPPLIES

OPTIONAL
TEXT
REFERENCES

SOFTWARE
PRE LAB
REQUISITES
DATES

INFORMATION ON INSTRUCTOR
Course Incharge: Mr. S. Manikandan, M.E.,
Designation: Assistant Professor
Department
: Information Technology
Office Hours
: By appointment
Mobile: 9047902685
Email: profmaninvp@gmail.com

Text Book:
1. Donald Hearn, Pauline Baker, Computer Graphics C Version, second edition,
Pearson Education,2004.
2. F.S. Hill, Computer Graphics using OPENGL, Second edition, Pearson
Education,2002
Supplies:
EGSP Engineering College/IT/CS2405-CG Lab manual
1. James D. Foley, Andries Van Dam, Steven K. Feiner, John F. Hughes, Computer
Graphics- Principles and practice, Second Edition in C, Pearson Education, 2007..
1. http:// www.w3schools.com
2. http://www.sites.google.com/site/profmaniit
3. http://www.google.com
Turbo C, Visual C++ with OpenGL, Any 3D Animation software like 3DMAX,
Maya, Blendar
1. Computer Practice Laboratory 1 (C Language)
2. Engineering Graphics
Ref. Academic Calendar

CS2405 Computer Graphics Lab

Page 2

SYLLABUS
CS2405 - COMPUTER GRAPHICS LABORATORY
LT P C
0 0 3 2
1. Implementation of Bresenhams Algorithm Line, Circle, Ellipse.
2. Implementation of Line, Circle and ellipse Attributes
3. Two Dimensional transformations - Translation, Rotation, Scaling, Reflection, Shear.
4. Composite 2D Transformations
5. Cohen Sutherland 2D line clipping and Windowing
6. Sutherland Hodgeman Polygon clipping Algorithm
7. Three dimensional transformations - Translation, Rotation, Scaling
8. Composite 3D transformations
9. Drawing three dimensional objects and Scenes
10. Generating Fractal images
TOTAL: 45 PERIODS
LIST OF EQUIPMENTS:
1) Turbo C
2) Visual C++ with OPENGL
3) Any 3D Animation software like 3DSMAX, Maya, Blender

CS2405 Computer Graphics Lab

Page 3

List of Experiments
1. Study of Basic Graphics Functions
2. Implementation of Bresenhams Algorithm
2.a. Line Drawing using Bresenham Algorithm
2.b Circle Drawing using Bresenham Algorithm
2.c Ellipse Drawing using Bresenham Algorithm
3. Implementation of Line, Circle & Ellipse Attributes
4. Two Dimensional Transformations
5. 2D Composite Transformation
6. Cohen Sutherland 2D line clipping and Windowing
7. Sutherland Hodgeman Polygon clipping Algorithm
8. Three dimensional transformations - Translation, Rotation, Scaling
9. Composite 3D transformations
10. Drawing three dimensional objects and Scenes
11. Generating Fractal images

CS2405 Computer Graphics Lab

Page 4

Ex. No: 01

Study of Basic Graphics Functions

1) initgraph()
initgraph() function initializes the graphics mode and clears the screen.
Declaration:
void far initgraph(int far *driver, int far *mode, char far *path)
2) detectgraph()
Detectgraph function determines the graphics hardware in the system, if the function
finds a graphics adapter then it returns the highest graphics mode that the adapter supports.
Declaration:
void far detectgraph(int far *driver, int far *mode)
Integer that specifies the graphics driver to be used. You can give graphdriver a value using a
constant of the graphics_drivers enumeration type.
3) closegraph()
closegraph() function switches back the screen from graphcs mode to text mode. It clears
the screen also.
A graphics program should have a closegraph function at the end of graphics. Otherwise
DOS screen will not go to text mode after running the program.
4) getpixel()
getpixel function returns the color of pixel present at location(x, y).
Declaration :int getpixel(int x, int y);
5) putpixel()
putpixel function plots a pixel at location (x, y) of specified color.
Declaration :void putpixel(int x, int y, int color);
For example if we want to draw a GREEN color pixel at (35, 45) then we will write
putpixel(35, 35, GREEN); in our c program, putpixel function can be used to draw
circles, lines and ellipses using various algorithms.
6) line()
line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and
(x2,y2) are end points of the line.
Declaration :void line(int x1, int y1, int x2, int y2);
7) lineto()
lineto function draws a line from current position(CP) to the point(x,y), you can get
current position using getx and gety function.

CS2405 Computer Graphics Lab

Page 5

8) circle()
circle function is used to draw a circle with center (x,y) and third parameter specifies the
radius of the circle.
Declaration :void circle(int x, int y, int radius);
9)ellipse()
Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, stangle is
the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X
and Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and
360 respectively.
Declaration :void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);
10) drawpoly()
drawpoly function is used to draw polygons i.e. triangle, rectangle, pentagon, hexagon
etc.
Declaration :void drawpoly( int num, int *polypoints );
num indicates (n+1) number of points where n is the number of vertices in a polygon,
polypoints points to a sequence of (n*2) integers . Each pair of integers gives x and y
coordinates of a point on the polygon. We specify (n+1) points as first point coordinates should
be equal to (n+1)th to draw a complete figure.
To understand more clearly we will draw a triangle using drawpoly, consider for
example the array :int points[] = { 320, 150, 420, 300, 250, 300, 320, 150};
points array contains coordinates of triangle which are (320, 150), (420, 300) and (250,
300). Note that last point(320, 150) in array is same as first.
11) outtext ()
outtext function displays text at current position.
Declaration :void outtext(char *string);
12) outtextxy ()
outtextxy function display text or string at a specified point(x,y) on the screen.
Declaration :void outtextxy(int x, int y, char *string);
x, y are coordinates of the point and third argument contains the address of string to be
displayed.
13)rectangle()
Rectangle function is used to draw a rectangle. Coordinates of left top and right bottom
corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top

CS2405 Computer Graphics Lab

Page 6

specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom
corner, bottom specifies the Y-coordinate of right bottom corner.

Declaration :void rectangle(int left, int top, int right, int bottom);
14) floodfill()
floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used
to fill the area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be
filled otherwise outside will be filled,border specifies the color of boundary of area.
Declaration :void floodfill(int x, int y, int border);
15)fillpoly()
f illpoly function draws and fills a polygon. It require same arguments as drawpoly.
Declaration :void drawpoly( int num, int *polypoints );
16)fillellipse()
f illellipse function draws and fills a polygon.
Declaration:void fillellipse(int x, int y, int xradius, int yradius);
x and y are coordinates of center of the ellipse, xradius and yradius are x and y radius of
ellipse respectively.

Result:
Thus the basic graphics operations are studied and verified by using C Program.

CS2405 Computer Graphics Lab

Page 7

Ex. No: 2

Implementation of Bresenhams Algorithm

Ex.No. 2.a

Line Drawing using Bresenhams Algorithm

Aim:
To write a C program for Line Drawing Using Bresenham Algorithm.
Functions used:
line ()
The function line () is used to draw a line from(x1,y1)to (x2,y2)
Syntax:
line (x1,y1,x2,y2)
initgraph ()
This function takes thee arguments and they are
i)
The video driver to be used (gd).
ii)
The graphics mode (gm).
iii)
The path name.
Syntax:
initgraph (gd,gm,path)
Procedure:
1. Input the two endpoints (x1,y1) and (x2,y2).
2. Plot the pixel value (x1,y1) with a specified color.
3. Calculate the value of dx and dy and find the starting value of decision parameter as
dp=2*dy-dx;
4. Calculate the values of s1 and s2 depending on (x1,y1) and (x2,y2) values.
5. If dp<0, the next point to plot is (x,y+s2) and dp=+2*dy;
6. Otherwise the next point to plot is (x+s1,y+s2) and dp=dp+2*dx-2*dy.
7. Repeat steps 5 and 6 dx times.
Algorithm:
Step 1: Start
Step 2: Get the values of the end points as(x1, y1) &(x2, y2)
Step 3: Assign x=x1, y=y1;
Step 4: Compute dx=x2-x1
Step 5: Compute dy=y2-y1
Step 6: Assign sx=x2-x1, sy=y2-y1
Step 7: If dy>dx then interchange the values of dx and dy and assign exch=1
Step 8: Compute p=2xdy-dx
Step 9: Put a pixel on(x,y)
Step 10: If exch=1, y=sy else x=x+sx
Step 11: If p>0 and exch =1, x=x+sx else y=y+sy, p=p-2xdx
Step 12: Compute p=p+2xdy
Step 13: Do steps (9) t0 (12) for dx times
Step 14: Stop
Program:
#include<stdio.h>
#include<conio.h>

CS2405 Computer Graphics Lab

Page 8

#include<dos.h>
#include<math.h>
#include<graphics.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd=DETECT,gm;
clrscr();
printf("\n ENTER THE VALUE OF X1:");
scanf("%f",&x1);
printf("\n ENTER THE VALUES OF Y1:");
scanf("%f",&y1);
printf("\n ENTER THE VALUES OF X2 AND Y2:");
scanf("%f%f",&x2,&y2);
initgraph(&gd,&gm," ");
dx=abs(x2-x1);
dy=abs(y2-y1);
x=x1;
y-y1;
e=2*(dy-dx);
i=1;
do
{
putpixel(x,y,15);
while(e>=0)
{
y=y+1;
e=e-(2*dx);
}
x=x+1;
e=e+(2*dy);
i=i+1;
delay(100);
}while(i<=dx);
closegraph();
getch();
}
Output:

Result:
Thus the C Program for drawing line using Bresenham Algorithm was developed and
output verified using various samples.

CS2405 Computer Graphics Lab

Page 9

Ex.No. 2.b

Circle Drawing using Bresenhams Algorithm

Aim:
To write a C - Program to draw a circle using Bresenhams circle drawing Algorithm.
Functions used:
Circle()
The function circle () is used to draw a circle using(x,y) as centre point.
Syntax:
circle (x,y,radius)
initgraph ()
This function takes three arguments and they are
i)
The video driver to be used (gd).
ii)
The graphics mode (gm).
iii)
The path name.
Syntax:
initgraph (gd,gm,path)
Putpixel ()
The function putpixel() is used to place a pixel at particular coordinate
Syntax:
putpixel(x,y,color)
Procedure:
1. Input radius r and the midpoint of the circle (x,y) and obtain the first point on the
circumference for the circle as (0,r).
2. Calculate the initial value of the decision parameter as p=1-r.
3. At each position check the following conditions.
a) If p<0 then x=x+1 and p+=2*x+1
b) Else y=y-1 and p+=2*(x-y)+1.
4. Determine symmetry points at the other seven octants.
5. Move each calculated pixel position (x,y) onto the circular path centered on (xc,yc)
and plot the coordinate value as x=x+xc and y=y+yc.
6. Repeat step 3 until x<y.
Algorithm:
Step 1: Start
Step 2: Get the center point as (xc,yc),get the radius as r.
Step 3: Assign y=r,x=0
Step 4: Calculate p=3-2r
Step 5: If p<0,p=p+4x+6 else p=p+10+4(x-y) and y=y-1
Step 6: Increment x by 1
Step 7: Do steps (9) to (16)
Step 8: Repeat steps (5) to (9) until x<=y
Step 9: Put a pixel on (xc+x,yc+y,15);
Step 10: Put a pixel on (xc+x,yc-y,15);
Step 11: Put a pixel on (xc-x,yc+y,15);
Step 12: Put a pixel on (xc-x, yc-y, 15);

CS2405 Computer Graphics Lab

Page 10

Step 13: Put a pixel on (xc+y,yc+x,15);


Step14: Put a pixel on (xc+y, yc-x, 15);
Step 15: Put a pixel on (xc-y, yc+x, 15);
Step 16: Put a pixel on (xc-y, yc-x, 15);
Step 17: Stop.
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void circlefun(int xcenter, int ycenter,int x,int y);
void main()
{
int x=0,radius,xcenter,ycenter;
int y,p,gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm," ");
printf("\n ENTER THE XCENTER &YCENTER:");
scanf("%d%d",&xcenter,&ycenter);
printf("\n ENTER THE RADIUS:");
scanf("%d",&radius);
y=radius;
circlefun(xcenter,ycenter,x,y);
p=1-radius;
while(x<y)
{
if(p<0)
x=x+1;
else
{
x=x+1;
y=y-1;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
circlefun(xcenter,ycenter,x,y);
}
getch();
}
void circlefun(int xcenter,int ycenter,int x,int y)
{
putpixel(xcenter+x,ycenter+y,1);
putpixel(xcenter-x,ycenter+y,1);
putpixel(xcenter+x,ycenter-y,1);
putpixel(xcenter-x,ycenter-y,1);
putpixel(xcenter+y,ycenter+x,1);

CS2405 Computer Graphics Lab

Page 11

putpixel(xcenter-y,ycenter+x,1);
putpixel(xcenter+y,ycenter-x,1);
putpixel(xcenter-y,ycenter-x,1);
}
Output:
Result:
Thus the C Program for drawing Circle using Bresenham Algorithm was developed
and output verified using various samples.
Ex.No. 2.c

Ellipse Drawing using Bresenhams Algorithm

Aim:
To write a C - Program to draw a Ellipse using Bresenhams circle drawing
Algorithm.
Procedure:

CS2405 Computer Graphics Lab

Page 12

Algorithm:
Step 1: Start
Step 2: Get the center point as(x1, y1)
Step 3: Get the length of semi-major, semi-minor axes as r1 & r2
Step 4: Calculate t=pi/180
Step 5: Initialise i=0;
Step 6: Compute d=i*t
Step 7: Compute x=x1+y1*sin(d), y=y1+r2*cos(d).
Step 8: Put a pixel on(x,y)
Step 9: Increment I by 1
Step 10: Repeat steps(6) to (9) until i<360
Step 11: Stop
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp();
float x,y;
int xc,yc;
void main()
{
int gd=DETECT,gm;
int a,b;
float p1,p2;
clrscr();
initgraph(&gd,&gm,"");
scanf("%d%d",&xc,&yc);
scanf("%d%d",&a,&b);
x=0;y=b;
disp();
p1=(b*b)-(a*a*b)+(a*a)/4;
while((2.0*b*b*x)<=(2.0*a*a*y))
{
x++;
11
if(p1<=0)
p1=p1+(2.0*b*b*x)+(b*b);
else
{
y--;
p1=p1+(2.0*b*b*x)+(b*b)-(2.0*a*a*y);
}
disp();
x=-x;
disp();
x=-x;
}
x=a;

CS2405 Computer Graphics Lab

Page 13

y=0;
disp();
p2=(a*a)+2.0*(b*b*a)+(b*b)/4;
while((2.0*b*b*x)>(2.0*a*a*y))
{
y++;
if(p2>0)
p2=p2+(a*a)-(2.0*a*a*y);
else
{
x--;
p2=p2+(2.0*b*b*x)-(2.0*a*a*y)+(a*a);
}
disp();
y=-y;
disp();
y=-y;
}
getch();
closegraph();
}
void disp()
{
putpixel(xc+x,yc+y,10);
putpixel(xc-x,yc+y,10);
putpixel(xc+x,yc-y,10);
putpixel(xc+x,yc-y,10);}
Output:
Result:
Thus the C Program for drawing Ellipse using Bresenham Algorithm was developed
and output verified using various samples.
QUESTIONS
1. Difference between DDA and Bresenham's line drawing algorithm
DDA uses float numbers and uses operators such as division and multiplication in its
calculation. Bresenhams algorithm uses ints and only uses addition and subtraction. Due to the
use of only addition subtraction and bit shifting (multiplication and division use more resources
and processor power) bresenhams algorithm is faster than DDA in producing the line. Im not
sure, though if i remember right, they still produce the same line in the end.
2.What are the advantages of bresenhams algorithm?
The main advantage of Bresenham's algorithm is speed. It uses only integer addition/subtraction
and bit shifting.
3.What are the disadvantages of bresenhams algorithm?
The disadvantage of such a simple algorithm is that it is meant for basic line drawing.
4.What is the drawback of DDA? Time consuming and Orientation Dependent.
5. Define Computer graphics.
Computer graphics remains one of the most existing and rapidly growing computer fields.
Computer graphics may be defined as a pictorial representation or graphical representation of
objects in a computer

CS2405 Computer Graphics Lab

Page 14

Ex.No:03

Implementation of Line, Circle & Ellipse Attributes

Aim:
To implement the basic attributes of Line, Circle and Ellipse
Procedure:
line (x1,y1,x2,y2) :
Line function draws a line between two specified points (x,y) towards (x2,y2).This
function comes handy if you want to draw box like shapes or just plotting the graphs
etc. e.g. line(100,50,100,400);
You can set the line style using setlinestyle functions. This function specifies the type
of line, pattern & the thickness that is going to appear on the screen. You have options
like solid,dotted,centered,dashed etc.
The other attributes with the command are as follows:
setlinestyle(style,0,1);
SetLinetype(lt),
setLinewidthScaleFactor(lw),
sePolylinecolourIndex(lc)
Color palettes
The graphics.h has declaration about 16 colors.In order to use the color in your program you
have to use the functions like setcolor( ) ,setbkcolor( ) & setfillstyle().The function setcolor( )
sets the value of current drawing color to color.setfillstyle( )sets the current fill pattern and fill
color.setbkcolor( ) sets the value for background color,which is by default black.
Below is the table that describes the value for each color that are declared in the
graphics.h file.
Color Value
Black 0
Blue 1
GREEN 2
Cyan 3
RED 4
MAGENTA 5
BROWN
6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
Circle()
The function circle() is used to draw a circle using(x,y) as centre point.
Syntax:
circle (x,y,radius)
The other attributes with the command are as follows:
setfillstyle(style,lc),setcolor(lc)

CS2405 Computer Graphics Lab

Page 15

ellipse (x,y,stangle,endangle,xrad,yrad) :
This function draws an elliptical arc. Here (x,y) are the co-ordinates of center of the
ellipse. (stangle,endangle) are the starting and ending angles. If stangle=0 and endangle=360
then this function draws complete ellipse. eg.ellipse(100,150,0,360,100,50);
The other attributes with the command are as follows:
setfillcolor(lc),setfillstyle(ls),setlinecolor(lc),setlinewidth(lw)
Algorithm:
Line,Circle & Ellipse attributes
Step 1. Input n, number of vertices of polygon
Step 2. input x and y coordinated of all vertices i array x[n] and y[n]
Step 3. find ymin and ymax
Step 4. Store the initail x values(x1) y values y1 and y2 for two endpoints and x increment Dx
from scan line to scan line for each edge in the array edges [n] [4] while doing this check that
y1 > y2 , if not interchange y1 and y2 and corresponding x1 and x2 so that for each edge , y1
represents its maximum y coordinate and y2 represents it minimum y coordiante
Step 5. Sort the rows of array , edges [n] [4] in descending order of y1 ,descending order of y2
and ascending order of
Step 6. Set y = ymax
Step 7. Find the active edges and update active edge list:if( y > y2 and y<= y1 ) then edge is
active Otherwise edge is not active
Step 8. Compute the x intersects for all active edges for current y values [ initially x-intersect is
and x intersects for successive y values can be given asxi+1 = x i + Dx Where Dx = - 1/m and
m= y2 - y1 / x2 - x1 i.e slope of a line segment
Step 9. VertexxIf x intersects is vertex i.e. X-intersect = x1 and y = y1 then apply vertex test to
checkwhether to consider one intersect or two intersects. Store all x-intersect in the
x-intersect [ ] array
Step 10. Store x-intersect [ ] array in the ascending order
Step 11. Extract pairs of intersects from the sorted x-intersect [ ] array
Step 12. Pass pair of x values to line drawing routine to draw corresponding line segments
Program:
1. Generating Fish:
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int gd = DETECT,gm;
initgraph(&gd,&gm ,"");
ellipse(200,200,0,360,50,30);
line(250,200,280,170);
line(280,170,280,230);
line(280,230,250,200);
circle(160,190,3);
getch();
closegraph();}

CS2405 Computer Graphics Lab

Page 16

2. Fish Move
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm;
int x,y,r,c,mx,my;
initgraph(&gd,&gm," ");
cout<<"enter x, y ,c";
cin>>x>>y>>c;
mx=getmaxx();
my=getmaxy();
while
(!kbhit())
{
if((x>=mx)||(y>=my))
{
while((x>0)||(y>0))
{
cleardevice();
setcolor(c);
ellipse(x,y,0,360,50,20);
circle(x-40,y-5,2);
line(x+50,y,x+80,y-30);
line(x+80,y-30,x+80,y+30);
line(x+80,y+30,x+50,y);
setfillstyle(1,0);
floodfill(x,y,c);
x=x-rand()%10;
y=y-rand()%10;
}
}
else
{
while((x<=mx)||(y<=my))
{
cleardevice();
setcolor(c);
ellipse(x,y,0,360,50,20);
circle(x-40,y-5,2);
line(x+50,y,x+80,y-30);
line(x+80,y-30,x+80,y+30);
line(x+80,y+30,x+50,y);
setfillstyle(1,0);

CS2405 Computer Graphics Lab

Page 17

floodfill(x,y,c);
x=x+rand()%10;
y=y+rand()%10;
}
}
delay(200);
}
getch();
closegraph();
}
3. To Make a Flag
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int gd = DETECT,gm;
clrscr();
initgraph(&gd,&gm," ");
setcolor(5);
line(20,50,20,180);
line(20,50,100,50);
line(20,70,100,70);
line(20,90,100,90);
line(20,110,100,110);
line(100,50,100,110);
circle(60,80,10);
line(52,80,68,80);
line(60,72,60,88);
setfillstyle(SOLID_FILL,22);
floodfill(21,51,5);
setfillstyle(SOLID_FILL,7);
floodfill(21,75,5);
setfillstyle(SOLID_FILL,2);
floodfill(21,95,5);
setfillstyle(SOLID_FILL,7);
floodfill(81,75,5);
setfillstyle(SOLID_FILL,7);
floodfill(61,81,5);
getch();
closegraph();
}
4. To Make a Hut
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()

CS2405 Computer Graphics Lab

Page 18

{
int gd = DETECT,gm;
clrscr();
initgraph(&gd,&gm," ");
setcolor(6);
rectangle(50,180,150,300);
rectangle(150,180,320,300);
rectangle(80,250,120,300);
line(100,100,50,180);
line(100,100,150,180);
line(100,100,300,100);
line(300,100,320,180);
getch();
closegraph();
}
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int a,b,gd=DETECT,gm,i;
initgraph(&gd,&gm," ");
line(100,100,50,180);
line(100,100,150,180);
line(50,180,100,250);
line(150,180,100,250);
line(100,100,100,250);
line(50,180,150,180);
line(100,250,70,300);
line(100,250,130,300);
line(70,300,130,300);
line(100,300,120,320);
line(120,320,80,340);
line(80,340,120,360);
line(120,360,80,380);
setcolor(4);
getch();
closegraph();
}
5. To Make a Kite
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
#include<DOS.h>
#include<stdlib.h>
#include<math.h>
void main()

CS2405 Computer Graphics Lab

Page 19

{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
int x,y,xm;
cout<<"enter x,y";
cin>>x>>y;
xm=getmaxx();
circle(x,y,50);
ellipse(x-25,y-15,0,360,3,2);
ellipse(x+25,y-15,0,360,3,2);
line(x,y-10,x,y+10);
arc(x,y+15,180,360,15);
line(x,y+50,x,y+130);
line(x,y+130,x-30,y+180);
line(x-30,y+180,x-50,y+170);
line(x,y+130,x+30,y+180);
line(x+30,y+180,x+50,y+170);
line(x,y+75,x+75,y+75); line(x+75,y+75,x+170,y-10);
ellipse(x+170,y-50,0,360,28,40);
while(!kbhit())
{
if(x<=xm)
{
cleardevice();
x=x+20;
circle(x,y,50);
ellipse(x-25,y-15,0,360,3,2);
ellipse(x+25,y-15,0,360,3,2);
line(x,y-10,x,y+10);
arc(x,y+15,180,360,15);
line(x,y+50,x,y+130);
line(x,y+130,x-30,y+180);
line(x-30,y+180,x-50,y+170);
line(x,y+130,x+30,y+180);
line(x+30,y+180,x+50,y+170);
line(x,y+75,x+75,y+75);
line(x+75,y+75,x+170,y-10);
ellipse(x+170,y-50,0,360,28,40);
delay(100);
}
else
{
do
{
cleardevice();
x=x-20;
circle(x,y,50);
ellipse(x-25,y-15,0,360,3,2);
ellipse(x+25,y-15,0,360,3,2);

CS2405 Computer Graphics Lab

Page 20

line(x,y-10,x,y+10);
arc(x,y+15,180,360,15);
line(x,y+50,x,y+130);
line(x,y+130,x-30,y+180);
line(x-30,y+180,x-50,y+170);
line(x,y+130,x+30,y+180);
line(x+30,y+180,x+50,y+170);
line(x,y+75,x+75,y+75);
line(x+75,y+75,x+170,y-10);
ellipse(x+170,y-50,0,360,28,40);
delay(100);
}while(x!=0);
}
}
getch();
closegraph();
}
6. Road Animation
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int gd=DETECT, gm, c, d, e, f, g;
clrscr();
initgraph(&gd, &gm, " ");
cout<<"enter 5 colours";
cin>>c>>d>>e>>f>>g;
setcolor(c);
rectangle(100,100,300,150);
setfillstyle(SOLID_FILL,d);
floodfill(120,120,c);
rectangle(100,150,300,200);
setfillstyle(SOLID_FILL,e);
floodfill(120,160,c);
rectangle(100,200,300,250);
line(100,250,100,475);
setfillstyle(SOLID_FILL,f);
floodfill(120,220,c);
circle(200,175,20);
setcolor(g);
line(200,160,200,190);
line(180,175,220,175);
line(190,167,210,183);
line(190,183,210,167);
getch();
closegraph();}

CS2405 Computer Graphics Lab

Page 21

Output:

Result:
Thus the C Program for generating various images using line, circle and ellipse was
developed and output verified using various samples.
QUESTIONS
1. What is scan conversion?
A major task of the display processor is digitizing a picture definition given in an
application program into a set of pixel-intensity values for storage in the frame buffer.
This digitization process is called scan conversion.
2. Write the properties of video display devices?
Properties of video display devices are persistence, resolution, and aspect
ratio.
3. What is rasterization?
The process of determining the appropriate pixels for representing picture or graphics
object is known as rasterization.
4. Name any four input devices.
Four input devices are keyboard, mouse, image scanners, and trackball.
5. Write the two techniques for producing color displays with a CRT?
Beam penetration method, shadow mask method

CS2405 Computer Graphics Lab

Page 22

Ex.No: 04

Two Dimensional transformations


(Translation, Rotation, Scaling, Reflection, Shear)

Aim:
To perform the 2D transformation such as translation, rotation, scaling,
shearing and reflection.
Functions Used:
Line()
The function line() is used to draw a line from(x1,y1)to (x2,y2)
Syntax:
line (x1,y1,x2,y2)
initgraph()
This function takes three arguments and they are
i).the video driver to be used (gd).
ii).the graphics mode (gm).
iii).the path name.
Syntax:
initgraph(gd,gm,path)
Algorithm:
Step1. Declare the variables xa,ya,xa1,ya1 of array type.
Step2.Declare the variables gd,gm,n,i,op,tx,ty,xf,yf,rx,ry.
Step3. Initialise the graphics function.
Step4. Input the number of points.
Step5. Input the value of co-ordinate according to number of points.
Step6. Using switch statement selects the option to perform
translation, rotation, scaling, reflection and shearing.
Step7. Translation:
a).input the translation vector
b).add the translation vectors with the coordinates
xa1[i]=xa[i]=tx, ya1[i]=ya[i]=ty,
c).using the function line,display the object before and after translation.
Step8. Rotation:
a). input the rotation angle
b). using formula theta=(theta*3.14)/180
c).input the value of reference point
d). calculate new coordinate point using formula
xa1[i]=xf+(xa[i]-xf)*cos(theta)-(ya[i]-yf)*sin(theta),
ya1[i]=yf+(xa[i]-xf)*sin(theta)-(ya[i]-yf)*cos(theta),
e). using the function line,display the object before and after rotation.
Step9. Scaling:
a).input the scaling factor and reference point
b).calculate new coordinate point using formula
xa1[i]=(xa[i]*sx+rx*(1-sx),
ya1 [i] = (ya[i]*sy+ry*(1-sy)
c). using the function line, display the object before and after scaling.

CS2405 Computer Graphics Lab

Page 23

Step10. Shearing:
a).input the shearing value and reference point.
b). input the shear direction x or y
i).if direction x
xa1[i]=xa[i]+shx*(ya[i]-yref)
ii).otherwise
ya1[i]=ya[i]+shy*(xa[i]-xref)
iii). using the function line, display the object before and after shearing.
Step11. Reflection:
a).display the object before reflection using the function line
b). display the object after reflection using the function line
Step12. Stop.
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void translation(x,y,x1,y1,x2,y2)
{
int tx,ty,xx,yy;
printf("Enter transformational values:");
scanf("%d%d",&tx,&ty);
line(x+tx,y+ty,x1+tx,y1+ty);
line(x1+tx,y1+ty,x2+tx,y2+ty);
line(x2+tx,y2+ty,x+tx,y+ty);
}
void scaling(x,y,x1,y1,x2,y2)
{
float sx,sy;
printf("Enter the scaling vertices:");
scanf("%f%f",&sx,&sy);
line(x*sx,y*sy,x1*sx,y1*sy);
line(x1*sx,y1*sy,x2*sx,y2*sy);
line(x2*sx,y2*sy,x*sx,y*sy);
}
void scalingpivot(x,y,x1,y1,x2,y2)
{
float sx,sy,xf,yf;
int xp,yp,xp1,yp1,xp2,yp2;
printf("Enter the scaling vertices:");
scanf("%f%f",&sx,&sy);
printf("Enter the scaling pivot points:");
scanf("%f%f",&xf,&yf);
xp=(x*sx)+xf*(1-sx);
yp=(y*sy)+yf*(1-sy);
xp1=(x1*sx)+xf*(1-sx);
yp1=(y1*sy)+yf*(1-sy);
xp2=(x2*sx)+xf*(1-sx);

CS2405 Computer Graphics Lab

Page 24

yp2=(y2*sy)+yf*(1-sy);
line(x+xp,y+yp,x1+xp1,y1+yp1);
line(x1+xp1,y1+yp1,x2+xp2,y2+yp2);
line(x2+xp2,y2+yp2,x+xp,y+yp);
}
void rotation(x,y,x1,y1,x2,y2)
{
int the,xr,yr,xr1,yr1,xr2,yr2;
float rad;
printf("Enter the theta value:");
scanf("%d",&the);
rad=the*(3.14/180);
xr=x*cos(rad)-y*sin(rad);
yr=x*sin(rad)+y*cos(rad);
xr1=x1*cos(rad)-y1*sin(rad);
yr1=x1*sin(rad)+y1*cos(rad);
xr2=x2*cos(rad)-y2*sin(rad);
yr2=x2*sin(rad)+y2*cos(rad);
line(x+xr,y+yr,x1+xr1,y1+yr1);
line(x1+xr1,y1+yr1,x2+xr2,y2+yr2);
line(x2+xr2,y2+yr2,x+xr,y+yr);
}
void rotationpivot(x,y,x1,y1,x2,y2)
{
int the,xr,yr,xr1,yr1,xr2,yr2,xf,yf;
float rad;
printf("Enter the theta value:");
scanf("%d",&the);
printf("\n Enter the pivot points:");
scanf("%d%d",&xf,&yf);
rad=the*(3.14/180);
xr=xf+(x-xf)*cos(rad)-(y-yf)*sin(rad);
yr=yf+(x-xf)*sin(rad)-(y-yf)*cos(rad);
xr1=xf+(x1-xf)*cos(rad)-(y1-yf)*sin(rad);
yr1=yf+(x1-xf)*sin(rad)-(y1-yf)*cos(rad);
xr2=xf+(x2-xf)*cos(rad)-(y2-yf)*sin(rad);
yr2=yf+(x2-xf)*sin(rad)-(y2-yf)*cos(rad);
line(x+xr,y+yr,x1+xr1,y1+yr1);
line(x1+xr1,y1+yr1,x2+xr2,y2+yr2);
line(x2+xr2,y2+yr2,x+xr,y+yr);
}
void reflection(x,y,x1,y1,x2,y2)
{
line(y,x,y1,x1);
line(y1,x1,y2,x2);
line(y2,x2,y,x);
}
void shear(x,y,x1,y1,x2,y2)
{

CS2405 Computer Graphics Lab

Page 25

int s;
//x+=100; y+=100;
//x1+=100; y1+=100;
//x2+=100; y2+=100;
printf("Enter the shear value about x:");
scanf("%d",&s);
line(x,y,x1+s,y1);
line(x1+s,y1,x2,y2);
line(x2,y2,x,y);
}
void main()
{
int gd,gm,x,y,c,tx,ty,x1,y1,x2,y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("Enter the 6 values:");
scanf("%d%d%d%d%d%d",&x,&y,&x1,
&y1,&x2,&y2);
printf("Actual polygon");
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
do
{
printf("\nMenu\n 1.Translation\n
2.Scaling\n 3.Scaling with pivot\n");
printf(" 4.Rotation\n 5.Rotation
with pivot\n 6.Reflection\n");
printf(" 7.Shearing\n 8.Exit\n");
printf("Enter ur choice:");
scanf("%d",&c);
switch(c)
{
case 1:
translation(x,y,x1,y1,x2,y2);
break;
case 2:
scaling(x,y,x1,y1,x2,y2);
break;
case 3:
scalingpivot(x,y,x1,y1,x2,y2);
break;
case 4:
rotation(x,y,x1,y1,x2,y2);
break;
case 5:
rotationpivot(x,y,x1,y1,x2,y2);
break;
case 6:

CS2405 Computer Graphics Lab

Page 26

reflection(x,y,x1,y1,x2,y2);
break;
case 7:
shear(x,y,x1,y1,x2,y2);
break;
case 8:
exit(0);
break;
}
}while(c<8);
getch();
closegraph();
}
Output:

Result:
Thus the C Program for performing 2-Dimensional Transformation such as
Translation, Rotation, Scaling, Shearing and Reflection operation was implemented and output
verified using various samples.

QUESTIONS
1 What is reflection?
The reflection is actually the transformation that produces a mirror image of an object.
For this use some angles and lines of reflection.
2. What are the two classifications of shear transformation?
X shear, y shear.
3. Name any three font editing tools.
ResEdit, FONTographer
4. What is bitmap?
Some system has only one bit per pixel; the frame buffer is often referred to as bitmap.
5. What is point in the computer graphics system?
The point is a most basic graphical element & is completely defined by a pair of user
coordinates (x, y).

CS2405 Computer Graphics Lab

Page 27

Ex.No: 05

2D Composite Transformation

Aim:
To perform the 2D composite transformation such as translation, rotation, scaling,
shearing and reflection.
Global, Local and Composite Transformations
Transformation can be divided into two categories based on their scope: global and local.
In addition, there are composite transformations. A global transformation is applicable to all
items of a Graphics object. The Transform property of the Graphics class is used to set global
transformations.
A composite transformation is a sequence of transformations. For example, scaling
followed by translation and rotation is a composite translation. We can set up a matrix for any
sequence of transformation matrix by calculating the matrix product of individual
transformations forming these products is called composition. Multiply matrices in order from
right to left. Each successive transformation matrix premultiplies the product of the preceding
transformation matrices.
Procedure:
Step 1. Additivity of successive translations. We want to translate a point P to P by T(dx1,
dy1) and then to P by another T(dx2, dy2)
On the other hand, we can define T21= T(dx1, dy1) T(dx2, dy2) first, then apply T21 to P:
where
T21 T (d x 2 , d y 2 )T (d x1 , d y1 )
1 0 d x 2 1 0 d x1
0 1 d y 2 0 1 d y1
0 0 1 0 0 1

1 0 d x1 d x 2
0 1 d y1 d y 2
0 0

Step 2. Multiplicativity of successive scaling


P' ' S ( s x 2 , s y 2 )[ S ( s x1 , s y1 ) P]
[ S ( s x 2 , s y 2 ) S ( s x1 , s y1 )]P

where

S 21P
S 21 S ( s x 2 , s y 2 ) S ( s x1 , s y1 )

s x 2 0 0 s x1 0 0
0 s y 2 0 0 s y1 0
0
0 1 0
0 1
0
0
s x 2 * s x1

0
s y 2 * s y1 0
0
0
1
Step 3. Additivity of successive rotations
P' ' R( 2 )[ R(1 ) P]
[ R( 2 ) R(1 )]P
R21P

CS2405 Computer Graphics Lab

Page 28

where

R21 R( 2 ) R(1 )
cos 2 sin 2 0 cos 1 sin 1 0
sin 2 cos 2 0 sin 1 cos 1 0
0
0
1 0
0
1
cos( 2 1 ) sin( 2 1 ) 0
sin( 2 1 ) cos( 2 1 ) 0

0
0
1

Algorithm:
1. Input the object coordinates.
2. Translation
a) Enter the translation factors tx and ty.
b) Move the original coordinate position (x,y) to a new position
(x1,y1).ie. x=x+x1, y=y+y1.
3. Rotation
d) Enter the radian for rotation angle .
e) Rotate a point at position (x,y) through an angle about the origin
x1=xcos - ysin , y1=ycos + xsin .
4. Scaling
d) Input the scaled factors sx and sy.
e) The transformed coordinates (x1,y1) , x1=x.sx and y1=y.sy.
5.Reflection
Reflection can be performed about x axis and y axis.
f) Reflection about x axis : The transformed coordinates are x1=a and y1=-y.
g) Reflection about y axis : The transformed coordinates are x1=x and y1=y.
6. Shearing
h) Input the shearing factors shx and shy.
i) Shearing related to x axis : Transform coordinates x1=x+shx*y and y1=y.
j) Shearing related to y axis : Transform coordinates x1=x and y1=y+shy*x.
k) Input the xref and yref values.
l) X axis shear related to the reference line y-yref is x1=x+shx(y-yref) and y1=y.
m) Y axis shear related to the reference line x=xref is x1=x and y1=y+shy(x-xref)
7.Finally display the transformed object after the successive transformations.
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int
gd,gm,n,i,xa[10],ya[10],op,tx,ty,xa1[10],ya1[10],theta,xf,yf,rx,ry,sx,sy,shx,shy,xref,yref;
char d;
gd=DETECT;
initgraph(&gd,&gm,"");

CS2405 Computer Graphics Lab

Page 29

cout<<"enter the no of points";


cin>>n;
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
cout<<"enter the coordinates"<<i+1;< p=""> </i+1;<>
cin>>xa[i]>>ya[i];
}
do
{
cout<<"menu";
cout<<"\n1.translation\n2.rotation\n3.scaling\n4.shearing\n5.reflection\n6.exit";
cin>>op;
switch(op)
{
case 1:
cout<<"enter the translation vector";
cin>>tx>>ty;
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
xa1[i]=xa[i]+tx;
ya1[i]=ya[i]+ty;
}
cout<<"before translation";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
cout<<"after translation";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 2:
cout<<"enter the rotation angle";
cin>>theta;
theta=(theta*3.14)/180;
cout<<"enter the reference points";
cin>>xf>>yf;
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
xa1[i]=xf+(xa[i]-xf)*cos(theta)-(ya[i]-yf)*sin(theta);
ya1[i]=yf+(xa[i]-xf)*sin(theta)-(ya[i]-yf)*cos(theta);
}
cout<<"before rotation";
for(i=0;i<n;i++)< p=""> </n;i++)<>

CS2405 Computer Graphics Lab

Page 30

{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
cout<<"after rotation";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 3:
cout<<"enter the scaling factor";
cin>>sx>>sy;
cout<<"enter the reference point";
cin>>rx>>ry;
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
xa1[i]=xa[i]*sx+rx*(1-sx);
ya1[i]=ya[i]*sy+ry*(1-sy);
}
cout<<"before scaling";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
cout<<"after scaling";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 4:
cout<<"enter the shear value";
cin>>shx>>shy;
cout<<"enter the reference point";
cin>>xref>>yref;
cout<<"enter the shear direction x or y";
cin>>d;
if(d=='x')
{
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
xa1[i]=xa[i]+shx*(ya[i]-yref);
ya1[i]=ya[i];
}

CS2405 Computer Graphics Lab

Page 31

}
cout<<"before shearing";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
cout<<"after shearing";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 5:
cout<<"before reflection";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
cout<<"after reflection";
for(i=0;i<n;i++)< p=""> </n;i++)<>
{
line(ya[i],xa[i],ya[(i+1)%n],xa[(i+1)%n]);
}
getch();
cleardevice();
break;
case 6:
exit(0);
break;
}
}while(op!=6);
}
Output:
Result:
Thus the program for performing Composite 2D Transformation was implemented and
output verified successfully.
QUESTIONS
1. What is Transformation?
Transformation is the process of introducing changes in the shape size and orientation
of the object using scaling rotation reflection shearing & translation etc.
2. What is translation?
Translation is the process of changing the position of an object in a straight-line path
from one coordinate location to another. Every point (x , y) in the object must under go a
displacement to (x|,y|). the transformation is: x| = x + tx ; y| = y+ty

CS2405 Computer Graphics Lab

Page 32

3. What is rotation?
A 2-D rotation is done by repositioning the coordinates along a circular path, in the xy
plane by making an angle with the axes. The transformation is given by: X| = r cos (q + f) and
Y| = r sin (q + f).
4. What is scaling?
A 2-D rotation is done by repositioning the coordinates along a circular path, in the xy
plane by making an angle with the axes. The transformation is given by: X| = r cos (q + f) and
Y| = r sin (q + f).
5. What is shearing?
The shearing transformation actually slants the object along the X direction or the Y
direction as required. ie; this transformation slants the shape of an object along a required plane.
6. What is reflection?
The reflection is actually the transformation that produces a mirror image of an object.
For this use some angles and lines of reflection.

Ex.No: 06

Cohen Sutherland 2D line clipping and Windowing

Aim:
To implement Cohen-Sutherland 2D line clipping and windowing algorithm.
Functions used:
Line()
The function line() is used to draw a line from(x1,y1)to (x2,y2)
Syntax:
line (x1,y1,x2,y2)
initgraph()
This function takes thee arguments and they are
i).the video driver to be used (gd).
ii).the graphics mode (gm).
iii).the path name.
Syntax:
initgraph(gd,gm,path)
Setcolor()
This function changes the drawing colour.
Syntax:
Setcolor(value of the color)
settextstyle()
The function settextstyle() is used to change the style of the text.
Syntax:
settextstyle(font,direction,charsize)
Where font is the constant value or the font filename, direction is the number either 0 or 1,
which makes the output to display in horizontal, or in vertical direction, charsize is the
character size or magnification factor and it varies from 1 to 10.
Outtext().
This function display a text message on upper left of the screen
Syntax:

CS2405 Computer Graphics Lab

Page 33

Outtext(message);
Algorithm:
The method speeds up the processing of line segments by performing initial tests that
reduce the number of intersections that must be calculated.
a. Every line endpoint is assigned a four digit binary code, called region code, that
identifies the location of the point relative to the boundaries of the clipping rectangle.
b. Each bit position in the region code is used to indicate one of the four relative coordinate
positions of the point with respect to the clip window.
Bit 1: left
Bit 2: right
Bit 3: below
Bit 4: above
c. Bit values in the region code are determined by comparing endpoint coordinates values
(x, y) with respect to the clip boundaries. eg.Bit 1 is set to 1 if x<xwmin
d. Once we have established region codes for all line endpoints, we can quickly determine
which lines are completely outside or inside the clip window.
e. Lines that cannot be identified as completely inside or outside a clip window are checked
for intersection with boundaries.
f. Intersection points with a clipping boundary can be calculated using the slope-intercept
form of the line equation.
g. The y coordinate of the intersection point at vertical line

m ( y2 y1 ) ( x2 x1 )

y y1 m( x x1 )

h. The x coordinate of the intersection point at horizontal line

x x1
For each line segment

y y1
m

y yw

min

y yw

max

Step 1. compute clip codes


Step 2. if both are 0 0 0 0
accept line segment
else if c1 & c2 != 0
discard line segment
else /* c1 & c2 = 0 */
clip against left
clip against right
clip against bottom
clip against top
if anything remains accept clipped segment.
Step 3.Stop
Windowing:
1. Draw a world coordinate area selected for display called as window. This window
defines what is to be viewed.
2. Draw an area on a display device to which a window is mapped called as Viewport. The
viewport defines where it is to be displayed.

CS2405 Computer Graphics Lab

Page 34

3. Now perform the mapping of a part of a world-coordinate scene to device coordinates


referred as viewing transformation.
Algorithm:
Step 1. If C1||C2 = 0000, the line segment is inside the window; display.
Step 2.If C1jjC2 = 0000, the line segment is inside the window; display.
Step 3. If C1&&C2 != 0000, the line segment is outside the window; discard.
Step 4.If neither 1) nor 2), the line segment is subdivided into two shorter segments by one
(extended) boundary of the window which crosses the line, and for each of the resulting
segments, repeat 1) and 2)
Step 5.Stop.
Program:
COHEN-SUTHERLAND 2D LINE CLIPPING
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
float cxl,cxr,cyt,cyb;
code(float ,float);
void clip(float ,float,float,float);
void rect(float ,float,float,float);
main()
{
float x1,y1,x2,y2;
int g=0,d;
initgraph(&g,&d,"c:\\tc\\bin");
settextstyle(1,0,1);
outtextxy(40,15,"BEFORE CLIPPING");
printf("\n Please Enter Left,Bottom,Right,Top Of Clip Window");
scanf("%f%f%f%f",&cxl,&cyb,&cxr,&cyt);
rect(cxl,cyb,cxr,cyt);
getch();
printf("\n Enter The Line Coordinate");
scanf("%f%f%f%f",&x1,&y1,&x2,&y2);
line(x1,y1,x2,y2);
getch();
cleardevice();
settextstyle(1,0,1);
outtextxy(40,15,"AFTER CLIPPING");
clip(x1,y1,x2,y2);
getch();
closegraph();
}
void clip(float x1,float y1,float x2,float y2)
{
int c,c1,c2;
float x,y;
c1=code(x1,y1);
c2=code(x2,y2);

CS2405 Computer Graphics Lab

Page 35

getch();
while((c1!=0)||(c2!=0))
{
if((c1&c2)!=0)
goto out;
c=c1;
if(c==0)
c=c2;
if((c&1)==1)
{
y=y1+(y2-y1)*(cxl-x1);
x=cxl;
}
else
if((c&2)==2)
{
y=y1+(y2-y1)*(cxl-x1)/(x2-x1);
x=cxr;
}
else
if((c&8)==8)
{
x=x1+(x2-x1)*(cyb-y1)/(y2-y1);
y=cyb;
}
else
if((c&4)==4)
{
x=x1+(x2-x1)*(cyt-y1)/(y2-y1);
y=cyt;
}
if(c==c1)
{
x1=x;
y1=y;
c1=code(x,y);
}
else
{
x2=x;
y2=y;
c2=code(x,y);
}
}
out:
rect(cxl,cyb,cxr,cyt);
line(x1,y1,x2,y2);
}
code(float x ,float y)

CS2405 Computer Graphics Lab

Page 36

{
int c=0;
if(x<cxl) c=1;
else
if(x>cxr) c=2;
else
if(y<cyb) c=c|8;
else
if(y>cyt) c=c|4;
return c;
}
void rect(float xl,float yb,float xr,float yt)
{
line(xl,yb,xr,yb);
line(xr,yb,xr,yt);
line(xr,yt,xl,yt);
line(xl,yt,xl,yb);
}
OUTPUT
Windowing To Viewport Mapping
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
main()
{
float sx,sy;
int w1,w2,w3,w4,x1,x2,x3,x4,y1,y2,y3,y4,v1,v2,v3,v4;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("Enter The Coordinate x1,y1,x2,y2,x3,y3\n");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
cleardevice();
w1=5;
w2=5;
w3=635;
w4=465;
rectangle(w1,w2,w3,w4);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
v1=425;
v2=75;
v3=550;
v4=250;
sx=(float)(v3-v1)/(w3-w1);
sy=(float)(v4-v2)/(w4-w2);

CS2405 Computer Graphics Lab

Page 37

rectangle(v1,v2,v3,v4);
x1=v1+floor(((float)(x1-w1)*sx)+.5);
x2=v1+floor(((float)(x2-w1)*sx)+.5);
x3=v1+floor(((float)(x3-w1)*sx)+.5);
y1=v2+floor(((float)(y1-w2)*sy)+.5);
y2=v2+floor(((float)(y2-w2)*sy)+.5);
www.rejinpaul.com
25
y3=v2+floor(((float)(y3-w2)*sy)+.5);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
return 0;
}
Output:
Result:
Thus the program for performing Cohen Sutherland 2D line clipping and
Windowing algorithm was implemented successfully and output verified sample various
samples.
Questions
1. What is pixmap?
Some system has multiple bits per pixel, the frame buffer is often referred to as pixmap.
2. Write the types of clipping?
Point clipping, line clipping, area clipping, text clipping and curve clipping.
3. What is meant by scan code?
When a key is pressed on the keyboard, the keyboard controller places a code carry to
the key pressed into a part of the memory called as the keyboard buffer. This code is called as
the scan code.
4. List out the merits and demerits of Penetration techniques?
The merits and demerits of the Penetration techniques are as follows
It is an inexpensive technique
It has only four colors
The quality of the picture is not good when it is compared to other techniques
It can display color scans in monitors
Poor limitation etc.
5. List out the merits and demerits of DVST?
The merits and demerits of direct view storage tubes [DVST] are as follows
It has a flat screen
Refreshing of screen is not required
Selective or part erasing of screen is not possible
It has poor contrast and Performance is inferior to the refresh CRT.
Ex.No:07
Sutherland Hodgeman Polygon clipping Algorithm
Aim
To write a program for implementing Sutherland Hodgeman Polygon clipping
Algorithm

CS2405 Computer Graphics Lab

Page 38

Algorithm
The Sutherland - Hodgman algorithm performs a clipping of a polygon against each
window edge in turn. It accepts an ordered sequence of verices v1, v2, v3, ..., vn and
puts out a set of vertices defining the clipped polygon.

This figure represents a polygon (the large, solid, upward pointing arrow) before
clipping has occurred.
The following figures show how this algorithm works at each edge, clipping the
polygon.

a. Clipping against the left side of the clip window.


b. Clipping against the top side of the clip window.
c. Clipping against the right side of the clip window.
d. Clipping against the bottom side of the clip window.
Four Types of Edges
As the algorithm goes around the edges of the window, clipping the polygon, it
encounters four types of edges. All four edge types are illustrated by the polygon in
the following figure. For each edge type, zero, one, or two vertices are added to the
output list of vertices that define the clipped polygon.

The four types of edges are:


1. Edges that are totally inside the clip window. - add the second inside vertex point
2. Edges that are leaving the clip window. - add the intersection point as a vertex
3. Edges that are entirely outside the clip window. - add nothing to the vertex output list
4. Edges that are entering the clip window. - save the intersection and inside points as vertices
How To Calculate Intersections

CS2405 Computer Graphics Lab

Page 39

Assume that we're clipping a polgon's edge with vertices at (x1,y1) and (x2,y2) against a
clip window with vertices at (xmin, ymin) and (xmax,ymax).
The location (IX, IY) of the intersection of the edge with the left side of the window is:
i. IX = xmin
ii. IY = slope*(xmin-x1) + y1, where the slope = (y2-y1)/(x2-x1)
The location of the intersection of the edge with the right side of the window is:
i. IX = xmax
ii. IY = slope*(xmax-x1) + y1, where the slope = (y2-y1)/(x2-x1)
The intersection of the polygon's edge with the top side of the window is:
i. IX = x1 + (ymax - y1) / slope
ii. IY = ymax
Finally, the intersection of the edge with the bottom side of the window is:
i. IX = x1 + (ymin - y1) / slope
ii. IY = ymin
Algorithm:
Step 1. If first point inside add. If outside, dont add
Step 2.Move around polygon from vi to vn and back to v1
Step 3.Check vi,vi+1 wrt the clip edge
Step 4. Need vi,vi+1s inside/outside status
Step 5.Add vertex one at a time.
There are 4 cases:
foreach polygon P P = P foreach clipping edge (there are 4)
Clip polygon P to clipping edge foreach edge in polygon P
Check clipping cases (there are 4)
Case 1 : Output vi+1
Case 2 : Output intersection point
Case 3 : No output
Case 4 : Output intersection point
Step 6.Stop
Program
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
enum area{left,right,top,bottom};
typedef struct
{
double x,y;
} points;
points outvertex[10];
points vertex[10];
int max=0;
int n;
enum area id;
void sutherclip(int,int,int,int);
points intersect(int,points,points);

CS2405 Computer Graphics Lab

Page 40

int inside(int,points);
int inside(int clipbound,points s)
{
int pos=0;
switch(id)
{
case left:
if(s.x>clipbound)
pos=1;
break;
case right:
if(s.x<clipbound)
pos=1;
break;
case top:
if(s.y>clipbound)
pos=1;
break;
case bottom:
if(s.y<clipbound)
pos=1;
break;
}
return(pos);
}
points intersect(int clipbound,points s ,points p)
{
points temp; double calc;
switch(id)
{
case left:
case right:
temp.x=clipbound;
temp.y=s.y+(p.y-s.y)*(clipbound-s.x)/(p.xs.
x); break;
case bottom:
case top:
temp.y=clipbound;
temp.x=s.x+(p.x-s.x)*(clipbound-s.y)/(p.ys.
y); break;
}
return temp;
}
void clip(int xmin,enum area id1)
{
int i;
points temp;
points s,p;
int pt1,pt2;

CS2405 Computer Graphics Lab

Page 41

id=id1;
for(i=0;i<n;i++)
{
s=vertex[i];
if(i==n-1) p=vertex[0];
else
p=vertex[i+1];
pt1=inside(xmin,s);
pt2=inside(xmin,p);
if(pt1==1 && pt2==1)
outvertex[max++]=p;
if(pt1==0 && pt2==1)
{
temp=intersect(xmin,s,p);
outvertex[max++]=temp;
outvertex[max++]=p;
}
if(pt1==1 && pt2==0)
{
temp=intersect(xmin,s,p);
outvertex[max++]=temp;
}
}
n=max;
for(i=0;i<max;i++)
vertex[i]=outvertex[i];
max=0;
}
void sutherclip(int xmin,int xmax,int ymin,int ymax)
{
clip(xmin,left);
clip(xmax,right);
clip(ymin,top);
clip(ymax,bottom);
}
void main()
{
int xmin,xmax,ymin,ymax,i;
int gd=DETECT,gm;
sin(1);
clrscr();
printf("Enter the co ordinates of clipping window....\n");
scanf("%d %d %d %d",&xmin,&ymin,&xmax,&ymax);
printf("\nEnter the no of vertices of the polygon....\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the x & y coordinates of vertex %d \n",i+1);
scanf("%lf %lf",&vertex[i].x,&vertex[i].y);

CS2405 Computer Graphics Lab

Page 42

}
initgraph(&gd,&gm,"d:\\tc\\bgi");
setbkcolor(7);
printf("\n\nBefore Clipping");
rectangle(xmin,ymin,xmax,ymax);
for(i=0;i<n-1;i++)
{
line(vertex[i].x,vertex[i].y,vertex[i+1].x,vertex[i+1].y);
line(vertex[n-1].x,vertex[n-1].y,vertex[0].x,vertex[0].y);
}
getch();
sutherclip(xmin,xmax,ymin,ymax);
cleardevice();
printf("After clipping");
rectangle(xmin,ymin,xmax,ymax);
for(i=0;i<n-1;i++)
{
line(outvertex[i].x,outvertex[i].y,outvertex[i+1].x,outvertex[i+1].y);
line(outvertex[n-1].x,outvertex[n-1].y,outvertex[0].x,outvertex[0].y);
}
getch();
closegraph(); }
Output:
Result:
Thus the program for performing Sutherland Hodgeman Polygon clipping Algorithm
was implemented successfully.
QUESTIONS
1. What is run length encoding?
Run length encoding is a compression technique used to store the intensity values in the
frame buffer, which stores each scan line as a set of integer pairs. One number each pair
indicates an intensity value, and second number specifies the number of adjacent pixels on the
scan line that are to have that intensity value.
2. What is point in the computer graphics system?
The point is a most basic graphical element & is completely defined by a pair of user
coordinates (x, y).
3. Write short notes on lines?
A line is of infinite extent can be defined by an angle of slope q and one point on the line
P=P(x,y). This can also be defined as y=mx+C where C is the Yintercept.
4. Define Circle?
Circle is defined by its center xc, yc and its radius in user coordinate units. The equation
of the circle is (x-xc) + (y-yc) = r2.
5. What are the various attributes of a line?
The line type, width and color are the attributes of the line. The line type include solid
line, dashed lines, and dotted lines.
Ex.No:08 Three dimensional transformations - Translation, Rotation, Scaling
Aim:

CS2405 Computer Graphics Lab

Page 43

To write a C program to perform 3D transformations such as translation, rotation and


scaling.
Procedure:
1. Translation
a) A point is transferred from position (x,y,z) to position (x1,y1,z1) with
the matrix operation
X1 1 0 0 tx x
Y1 = 0 1 0 ty y
Z1 0 0 1 tz z
100011
b) The values are x1=x+tx ,y1=y+ty and z1=z+tz.
c) Display the translated object
2. Rotation
a) Coordinate axes rotation
X1=x-cos -ysin
Y1=xsin +ycos
Z1=z
b) Y axis rotation
Z1=zcos -xsin
X1=zsin +xcos
Y1=y
c) X axis rotation
Y1=ycos -zsin
Z1=ysin +zcos
X1=x
d) Display the rotated object
3. Scaling
a) Translate the fixed point to the origin
b) Scale the object
c) Translate the fixed point back to its original position.
d) Display the scaled object
Algorithm:
Step 1. Create a class cube with function draw cube.
Step 2. Use the function draw cube to draw a cube using eight points by means of
functions line.
Step 3. Declare the variables x1, y1, x2, y2, x3, y3, in array type which of data type int.
Step 4.Declare the variables the ta,op,ch,tx,ty,sx,sy,sz,lz+xy,zf,i,x,y,z.
Step 5.Initialise graphics functions.
Step 6.Input the first point in the cube.
Step 7.Input the size of the edge.
Step 8.Create an object to call the function.
Step 9.Using switch operation select the operation to perform translation, rotation,
scaling.
Step 10.Translation
a).input the translation vectortx,ty,tz.
b).calculate points using formula
x3[i]=x1[i]+tx.

CS2405 Computer Graphics Lab

Page 44

y3[i]=y1[i]+ty
z3[i]=z1[i]+tz.
x4[i]=x3[i]+z3[i]/2
y4[i]=y3[i]+z3[i]/2
c).using the function line, display the object before and after translation.
Step11. Rotation:
a). input the rotation angle
b). using formula theta=(theta*3.14)/180
c).input the direction in x,y,z axis
d). if the direction is along x axis,
x3[i]=x1[i].
y3[i]=y1[i]*cos(theta)-z1[i]*sin(theta),
y3[i]=y1[i]*sin(theta)-z1[i]*cos(theta),
if the direction is along yaxis,
y3[i]=y1[i].
z3[i]=z1[i]*cos(theta)-x1[i]*sin(theta),
x3[i]=z1[i]*sin(theta)-x1[i]*cos(theta),
if the direction is along z axis,
z3[i]=z1[i].
x3[i]=x1[i]*cos(theta)-y1[i]*sin(theta),
y3[i]=x1[i]*sin(theta)-y1[i]*cos(theta),
e).calculate the points using the formula
x4[i]=x3[i]+z3[i]/2
y4[i]=y3[i]+z3[i]/2
f). using the function line,display the object before and after rotation.
Step12. Scaling:
a).input the scaling factor and reference point
b).calculate coordinate point using formula
x3[i]=xf+(x1[i]*sx+xf*(1-sx),
y3 [i] =yf+ (y1[i]*sy+yf*(1-sy)
z3 [i] =zf+ (z1[i]*sz+zf*(1-sz)
c). calculate the points using the formula
x4[i]=x3[i]+z3[i]/2
y4[i]=y3[i]+z3[i]/2
d). using the function line, display the object before and after scaling.
Step13. Stop.
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void draw(float x1,float y1,float x2,float y2,float z)
{
bar3d(x1,y1,x2,y2,z,1);
}
void z_rotate(float x1,float y1,float x2,float y2,float z,float r)
{
float a,b,c,d;

CS2405 Computer Graphics Lab

Page 45

a=(x1*cos(r))-(y1*sin(r));
b=(x2*cos(r))-(y2*sin(r));
c=(x1*sin(r))+(y1*cos(r));
d=(x2*sin(r))+(y2*cos(r));
draw(a,c,b,d,z); }
void main() {
int gd,gm,s,ch;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"E:\\TC\\BGI");
do {
float
x1=200,x2=300,y1=200,y2=300,z=100,tx,ty,sx,sy,sz,o,r;
clrscr();
printf("\n\n\n\t\t 3D Transformations");
printf("\n\n1.3D Translation\n2.3D Scaling\n3.3D Rotation \n4.Exit");
printf("\n\nEnter Ur Option:");
scanf("%d",&ch);
clrscr();
switch(ch) {
case 1:
printf("\n\nEnter Translation Values(tx,ty):");
scanf("%f %f",&tx,&ty);
printf("\nBefore Translation");
setcolor(10);
draw(x1,y1,x2,y2,z);
sleep(3);
printf("\nAfter Translation");
setcolor(12);
draw(x1+tx,y1+ty,x2+tx,y2+ty,z);
break;
case 2:
printf("\n\nEnter the scaling Values(sx,sy,sz):");
scanf("%f %f %f",&sx,&sy,&sz);
printf("\nBefore Scaling");
setcolor(4);
draw(x1,y1,x2,y2,z);
sleep(3);
printf("\nAfter Scaling");
x1*=sx;
y1*=sy;
x2*=sx;
y2*=sy;
z*=sz;
setcolor(6);
draw(x1,y1,x2,y2,z);
break;
case 3:
printf("\n\nEnter the rotation angle:");
scanf("%f",&o);

CS2405 Computer Graphics Lab

Page 46

printf("\nBefore Rotation");
draw(x1,y1,x2,y2,z);
sleep(3);
printf("\nAfter Rotation");
r=(o*3.14)/180;
z_rotate(x1,y1,x2,y2,z,r);
break;
case 4:
exit(0);
default:
printf("\n\nEnter a valid choice"); }
printf("\n\nPress 1 to continue:");
scanf("%d",&s); }
while(s==1);
getch();
closegraph();}
Output:
Result:
Thus the program for performing 3-Dimensional Transformation was implemented
successfully and output verified sample various samples.
QUESTIONS
1. What is fixed point scaling?
The location of a scaled object can be controlled by a position called the fixed point that
is to remain unchanged after the scaling transformation.
2. What is Bezier Basis Function?
Bezier Basis functions are a set of polynomials, which can be used instead of the
primitive polynomial basis, and have some useful properties for interactive curve design.
3. What is surface patch?
A single surface element can be defined as the surface traced out as two parameters (u,
v) take all possible values between 0 and 1 in a two-parameter representation. Such a single
surface element is known as a surface patch.
4. Define B-Spline curve?
A B-Spline curve is a set of piecewise(usually cubic) polynomial segments that pass
close to a set of control points. However the curve does not pass through these control points, it
only passes close to them.
5. What is a spline?
To produce a smooth curve through a designed set of points, a flexible strip called spline
is used. Such a spline curve can be mathematically described with a piecewise cubic polynomial
function whose first and second derivatives are continuous across
various curve section.
6. What are the different ways of specifying spline?
Using a set of boundary conditions that are imposed on the spline.
Using the state matrix that characteristics the spline
Using a set of blending functions that calculate the positions along the curve path by
specifying combination of geometric constraints on the curve
Ex.No: 09
Composite 3D transformations
Aim:
To perform 3D composite transformations such as translation, rotation and scaling.

CS2405 Computer Graphics Lab

Page 47

Procedure:
A rotation matrix for any axis that does not coincide with a coordinate axis can be set up
as a composite transformation involving combination of translations and the coordinate-axes
rotations.
1. Translate the object so that the rotation axis passes through the coordinate origin
2. Rotate the object so that the axis rotation coincides with one of the coordinate axes
3. Perform the specified rotation about that coordinate axis
4. Apply inverse rotation axis back to its original orientation
5. Apply the inverse translation to bring the rotation axis back to its original position
Algorithm:
Step 1.Translate P1 to the origin.
Step 2. Rotate about the y axis such that P1P2 lies in the (y, z) plane.
Step 3. Rotate about the x axis such that P1P2 lies on the z axis.
Step 4. Rotate about the z axis such that P1P3 lies in the (y, z) plane.
Step 5. Stop
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
struct pt
{
float x;float y;
};
float thematrix[3][3];
void print(float t[][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%f\t",t[i][j]);
printf("\n");
}
}
void matrixsetidentity(float m[][3])
{
int i,j;
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{
if(i==j)
m[i][j]=1;
else
m[i][j]=0;
}}}
void premul(float a[][3],float b[][3])
{

CS2405 Computer Graphics Lab

Page 48

int r,c,z=20;
float tmp[3][3];
for(r=0;r<3;r++)
{ for(c=0;c<3;c++)
{
tmp[r][c]=a[r][0]*b[0][c]+a[r][1]*b
[1][c]+a[r][2]*b[2][c];
}}
for(r=0;r<3;r++)
for(c=0;c<3;c++)
b[r][c]=tmp[r][c];
z=z*a[2][2];
}
void triangle(struct pt *p1)
{
line(p1[0].x,p1[0].y,p1[1].x,p1[1].y);
line(p1[1].x,p1[1].y,p1[2].x,p1[2].y);
line(p1[2].x,p1[2].y,p1[0].x,p1[0].y);
}
void translate(int tx,int ty)
{
float m[3][3];
matrixsetidentity(m);
m[0][2]=tx;
m[1][2]=ty;
premul(m,thematrix);
}
void scaling()
{
float m[3][3],sx,sy,sz;
matrixsetidentity(m);
printf("\nEnter the scaling with respect to
x-axis:");
scanf("%f%f%f",&sx,&sy,&sz);
m[0][0]=sx;
m[1][1]=sy;
m[2][2]=sz;
premul(m,thematrix);
}
void rotation()
{
float m[3][3];
float rad;
int a;
printf("\nEnter rotation angle");
scanf("%d",&a);
rad=a*(3.14/180);
matrixsetidentity(m);
m[0][0]=cos(rad);

CS2405 Computer Graphics Lab

Page 49

m[0][1]=-sin(rad);
m[1][0]=sin(rad);
m[1][1]=cos(rad);
premul(m,thematrix);
}
void transformpts(int npts,struct pt *p1)
{
int k;
float tmp;
for(k=0;k<npts;k++)
{
tmp=thematrix[0][0]*p1[k].x+thematrix[0]
[1]*p1[k].y+thematrix[0][2];
p1[k].y=thematrix[1][0]*p1[k].x+thematri
x[1][1]*p1[k].y+thematrix[1][2];
p1[k].x=tmp;
}}
void d3d(struct pt* p1,int z)
{
bar3d(p1[0].x,p1[0].y,p1[1].x,p1[1].y,z,1);
}
void main()
{
int gd,gm;
int tx,ty,tx1,ty1,z;
int xf,yf,ch;
struct pt p1[3];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"e:\\tc\\bgi");
matrixsetidentity(thematrix);
p1[0].x=150.0;p1[0].y=100.0;
p1[1].x=250.0;p1[1].y=150.0;
z=20;
do
{
printf("\n1.Translation\n2.Scaling\n3.Rotation\n4.exit\n");
printf("Enter ur option");
scanf("%d",&ch);
switch(ch) {
case 1:
cleardevice();
d3d(p1,z);
printf("Enter translation first coordinates\n");
scanf("%d %d",&tx,&ty);
translate(tx,ty);
transformpts(3,p1);
d3d(p1,z);
printf("Enter translation second coordinates\n");
scanf("%d %d",&tx1,&ty1);

CS2405 Computer Graphics Lab

Page 50

translate(tx1,ty1);
transformpts(3,p1);
d3d(p1,z);
break;
case 2:
cleardevice();
d3d(p1,z);
scaling();
transformpts(3,p1);
d3d(p1,z);
scaling();
transformpts(3,p1);
d3d(p1,z);
break;
case 3:
cleardevice();
d3d(p1,z);
rotation();
transformpts(3,p1);
d3d(p1,z);
rotation();
transformpts(3,p1);
d3d(p1,z);
break;
case 4:
break;
} }while(ch<4);
getch();
closegraph(); }
Output:
Result:
Thus the program for performing Composite 3D Transformation was implemented
successfully and output verified using various samples.
QUESTIONS
1.Define Projection?
The process of displaying 3D into a 2D display unit is known as projection. The
projection transforms 3D objects into a 2D projection plane
2. What are the steps involved in 3D transformation?
Modeling Transformation, Viewing Transformation, Projection Transformation, Workstation
Transformation
3. What do you mean by view plane?
A view plane is nothing but the film plane in camera which is positioned and oriented for
a particular shot of the scene.
4. Define projection?
The process of converting the description of objects from world coordinates to viewing
coordinates is known as projection
Ex.No:10
Drawing three dimensional objects and Scenes
Aim
To draw 3D objects and scenes

CS2405 Computer Graphics Lab

Page 51

Algorithm:
1. Parallel Projection
a) Enter the boundary coordinates of the object.
b) Define the direction of the projection line.
c) Align the projection plane so that it intersects each coordinate axis in which
the object is defined at the same distance from the origin.
d) The projection is perpendicular to the view plane
e) If the view plane is placed at position Z1 along the z axis , then any point
(x,y,z) in viewing coordinates is transformed to projection coordinates xp=x and
yp=y.
2.Perspective Projection
a) Enter the boundary coordinates of the object.
b) Define the projection reference point and thus the direction of the projection
lines.
c) The projected view is obtained by transforming points along projection lines
that meet at the projection reference point.
d) Calculate the intersection of the projection lines with the view plane.
e) Parallel lines in the object that are not parallel to the plane are projected into
converging lines.
f) Parallel lines that are parallel to the view plane will be projected as parallel
lines.
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd,gm;
int tlx,tly,brx,bry,d;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"e:\\tc\\bgi");
printf("Enter the input for 3D object");
scanf("%d %d %d %d %d",&tlx,&tly,&brx,&bry,&d);
bar3d(tlx,tly,brx,bry,d,1);
sleep(3);
//getch();
cleardevice();
printf("Front View");
bar3d(tlx,tly,brx,bry,0,0);
sleep(3);
//getch();
cleardevice();
printf("Top view");
bar3d(tlx,tly-d,brx,tly,0,0);
sleep(3);
//getch();
cleardevice();
printf("Side View");

CS2405 Computer Graphics Lab

Page 52

bar3d(brx,tly,brx+d,bry,0,0);
getch();
closegraph();
}
PROJECTION FOR 3D SCENE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x1=200,y1=200,x2=400,y2=200,x3=400,y3=400,x4=200,y4=400;
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
cleardevice();
printf("\n 3D object \n");
rectangle(x1,y1,x3,y3);
rectangle(x1+50,y1-50,x3+50,y3-50);
line(x1,y1,x1+50,y1-50);
line(x2,y2,x2+50,y2-50);
line(x3,y3,x3+50,y3-50);
line(x4,y4,x4+50,y4-50);
printf("\n press any key to see top view");
getch();
cleardevice();
printf("\n top view\n");
rectangle(x1,y1,x2+50,y2-50);
printf("\n press any key to see side view");
getch();
cleardevice();
printf("\n side view\n");
rectangle(x2,y2,x3+50,y3-50);
printf("\n press any key to see front view");
getch();
cleardevice();
printf("\n front view \n");
rectangle(x1,y1,x3,y3);
getch();
}
Output:
Result:
Thus the program for drawing three dimensional objects and Scenes was implemented
successfully and output verified using various samples.
QUESTIONS
1. What do you mean by Perspective projection?

CS2405 Computer Graphics Lab

Page 53

Perspective projection is one in which the lines of projection are not parallel. Instead,
they all converge at a single point called the center of projection.
2. What is Projection reference point?
In Perspective projection, the lines of projection are not parallel. Instead, they all
converge at a single point called Projection reference point.
3. What you mean by parallel projection?
Parallel projection is one in which z coordinates is discarded and parallel lines from each
vertex on the object are extended until they intersect the view plane.
4. What is tweening?
It is the process, which is applicable to animation objects defined by a sequence of
points, and that change shape from frame to frame.
5.Define frame?
One of the shape photographs that a film or video is made of is known as frame.
6. What is key frame?
One of the shape photographs that a film or video is made of the shape of an object is
known initially and for a small no of other frames called keyframe
Study of OpenGL
Graphics programming using OPENGL
OpenGL is a software interface that allows you to access the graphics hardware without
taking care of the hardware details or which graphics adapter is in the system. OpenGL is a lowlevel graphics library specification. It makes available to the programmer a small set of
geomteric primitives - points, lines, polygons, images, and bitmaps. OpenGL provides a set of
commands that allow the specification of geometric objects in two or three dimensions, using
the provided primitives, together with commands that control how these objects are rendered
(drawn).
Libraries
OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL
commands to perform such tasks as setting up matrices for specific viewing orientations and
projections and rendering surfaces.
OpenGL Utility Toolkit (GLUT) is a window-system-independent toolkit, written by
Mark Kilgard, to hide the complexities of differing window APIs.
Opening a window for Drawing The First task in making pictures is to open a screen
window for drawing. The following five functions initialize and display the screen window in
our program.
1. glutInit(&argc, argv)
The first thing we need to do is call the glutInit() procedure. It should be called before any other
GLUT routine because it initializes the GLUT library.
The parameters to glutInit() should be the same as those to main(), specifically main(int argc,
char** argv) and glutInit(&argc, argv).
2. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
The next thing we need to do is call the glutInitDisplayMode() procedure to specify the display
mode for a window. We must first decide whether we want to use an RGBA (GLUT_RGB) or
color-index (GLUT_INDEX) color model. The RGBA mode stores its color buffers as red,

CS2405 Computer Graphics Lab

Page 54

green, blue, and alpha color components. Color-index mode, in contrast, stores color buffers in
indicies. And for special effects, such as shading, lighting, and fog, RGBA mode provides more
flexibility. In general, use RGBA mode whenever possible. RGBA mode is the default. Another
decision we need to make when setting up the display mode is whether we want to use single
buffering (GLUT_SINGLE) or double buffering (GLUT_DOUBLE). If we aren't using
annimation, stick with single buffering, which is the default.
3. glutInitWindowSize(640,480)
We need to create the characteristics of our window. A call to glutInitWindowSize() will be
used to specify the size, in pixels, of our inital window. The arguments indicate the height and
width (in pixels) of the requested window.
4. glutInitWindowPosition(100,15)
Similarly, glutInitWindowPosition() is used to specify the screen location for the upper-left
corner of our initial window. The arguments, x and y, indicate the location of the window
relative to the entire display. This function positioned the screen 100 pixels over from the left
edge and 150 pixels down from the top.
5. glutCreateWindow(Example)
To create a window, the with the previously set characteristics (display mode, size, location,
etc), the programmer uses the glutCreateWindow() command. The command takes a string as a
parameter which may appear in the title bar.
6. glutMainLoop()
The window is not actually displayed until the glutMainLoop() is entered. The very last
thing is we have to call this function
Example 1: Skeleton for OpenGL Code
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(465, 250);
glutInitWindowPosition(100, 150);
glutCreateWindow("My First Example");
glutDisplayFunc(mydisplay);
glutReshapeFunc(myreshape);
glutMouseFunc(mymouse);
glutKeyboardFunc(mykeyboard);
myinit();
glutMainLoop();
return 0;
}
Example 2:
#include <glut.h> /* glut.h includes gl.h and glu.h*/
void display()
{
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);

CS2405 Computer Graphics Lab

Page 55

glVertex2f(100, 100);//line start point


glVertex2f(200, 200);// line end point
glEnd();
/* flush GL buffers */
glFlush();
}
void init()
{
glClearColor(1.0,1.0,1.0,0);
glColor3f(0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0 , 640 , 0 , 480);
}

void main(int argc, char** argv)


{
/* Initialize mode and open a window in upper left corner of
/* screen */
/* Window title is name of program (arg[0]) */
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(0, 0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}
Example 3
#include <iostream.h>
#include <math.h>
#include <glut.h>
GLdouble X1, Y1, X2, Y2;
void LineDDA(void)
{
GLdouble dx=X2-X1 , dy=Y2-Y1,steps;
float xInc,yInc,x=X1,y=Y1;
steps=(abs(dx)>abs(dy))?abs(dx):abs(dy);
xInc=dx/(float)steps;
yInc=dy/(float)steps;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2d(x,y);
for(int k=0;k<steps;k++)
{
x+=xInc;

CS2405 Computer Graphics Lab

Page 56

y+=yInc;
glVertex2d(x,y);
}
glEnd();
glFlush();
}
void Init()
{
glClearColor(1.0,1.0,1.0,0);
glColor3f(0.0,0.0,0.0);
glViewport(0 , 0 , 640 , 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0 , 640 , 0 , 480);
}
void main(int argc, char **argv)
{
cout<<"Enter Two Points for Draw LineDDA:\n";
cout<<"\nEnter Point1( X1 , Y1):";
cin>>X1>>Y1;
cout<<"\nEnter Point2( X2 , Y2):";
cin>>X2>>Y2;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("LineDDA");
Init();
glutDisplayFunc(LineDDA);
glutMainLoop();
}
Example 4:
//chessboard
#include<GL/glut.h>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,480.0,0.0,480.0);
}
void board(int size)
{
int i=0,k=0;
for(i=0;i<8;++i)
{
for(k=0;k<8;++k)

CS2405 Computer Graphics Lab

Page 57

{
if((i+k)%2==0)
glColor3f(1.0,1.0,1.0);
else
glColor3f(0.0,0.0,0.0);
glRecti(i*size,k*size,(i+1)*size,(k+1)*
size);}
}
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE);
board(60);
glEnd();
glFlush();
}
void main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|
GLUT_RGB);
glutInitWindowSize(480,480);
glutInitWindowPosition(100,150);
glutCreateWindow("Checker board");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
Example 5:
//chain of diamonds
#include <gl/Glut.h>
typedef struct diamond
{
GLint x,y;
}center;
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}v
oid myDisplay(void)
{
int size=50,n=5,i;
glClear(GL_COLOR_BUFFER_BIT);

CS2405 Computer Graphics Lab

Page 58

Ex.No: 11

center cen;
cen.x=26,cen.y=30;
for(i=0;i<5;i++)
{
glBegin(GL_LINE_LOOP);
glVertex2i(cen.x-size/2,cen.y);
glVertex2i(cen.x,cen.y+size/2);
glVertex2i(cen.x+size/2,cen.y);
glVertex2i(cen.x,cen.y-size/2);
glEnd();
cen.x=cen.x+size;
}g
lFlush();
}v
oid main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,150);
glutCreateWindow("MY First");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
Generating Fractal images

Aim:
To generate fractal images.
Procedure:
The fractals of interest in this chapter can all be generated by the following classes of
algorithms:
Step 1.Linear replacement mapping - Fractal curves such as the Koch and Sierpinski curves are
generated by successive refinement of a given line by some generator function.
Step 2.Iterated function systems - Many natural objects such as ferns and trees can be generated
by the successive application of a series of contractive affine transformations.
Step 3.Complex plane mapping - Mathematical objects such as the Julia and Mandelbrot sets are
generated by successive mapping on the complex plane.
Step 4.Stochastic processes - Mountain landscapes and other irregular objects are generated by
applying random processes within a recursive algorithm.
Algorithm
The sierpinski triangle-A fractal image

CS2405 Computer Graphics Lab

Page 59

1.The sierpinski Triangle is created by infinite removals


2.Each triangle is divided into 4 smaller upside down triangles
3.The center of the 4 triangles is removed
4. As the process is iterated infinite number of times, the total area of the
set goes to infinity as the size of the each new triangle goes to zero
5.After closer examination magnification factor is 2.
6.With each magnification there are 3 divisions of a triangle
Dimension D=ln(3)/ln(2)
D=1.5850
Program:
#include<stdlib.h>
#include<GL/glut.h>
struct GLintPoint
{
public:
GLint x,y;
}tri;
void myInit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}
int random(int m)
{
return (rand() %m);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
int r=random(6);
for(int j=0; j<=r; j++)
{
int pt1=random(200);
int pt2=random(250);
GLintPoint
T[3]={{150+pt1,50+pt2},{300+pt1,350+pt2},{400+pt1,50+pt2}};
int index =random(3);
tri.x=T[index].x;
tri.y=T[index].y;
glBegin(GL_POINTS);
{

CS2405 Computer Graphics Lab

Page 60

for(int i=0;i<1000;i++)
{
index=random(3);
tri.x=(tri.x+T[index].x)/2;
tri.y=(tri.y+T[index].y)/2;
glVertex2i(tri.x,tri.y);
}}}
glEnd();
glFlush();
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("Sierpinski gasket");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop(); }
Natural Scenes:
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<process.h>
#include<alloc.h>
#include<dos.h>
void draw()
{
arc(500,100,0,90,20);
arc(540,100,90,180,20);
arc(250,80,0,90,20);
arc(290,80,90,180,20);
arc(450,90,0,90,20);
arc(490,90,90,180,20);
rectangle(80,300,200,460);
rectangle(120,360,160,460);
circle(155,410,3);
line(80,300,140,230);
line(140,230,200,300);
}
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int left, top, right, bottom;
unsigned size;
unsigned size1;
void far *buf;
void far *buf1;

CS2405 Computer Graphics Lab

Page 61

initgraph(&gdriver, &gmode,"../bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
cout<<"Graphics error: %s\n"<< grapherrormsg(errorcode);
cout<<"Press any key to halt:";
getch();
exit(1);
}
circle(40,400,10);
line(40,410,40,450);
line(40,420,50,430);
line(40,420,30,430);
line(40,450,35,460);
line(40,450,45,460);
draw();
size = imagesize(30,400,45,460);
buf=farmalloc(size);
getimage(30,380,50,460,buf);
for(int x=30,y=400;x<=140;x=x+10)
{
putimage(x,y,buf,COPY_PUT);
draw();
delay(1000);
cleardevice();
}
getch();
closegraph();
return 0;
}
Result:
Thus the program for generating fractal images was implemented successfully using
OpenGL and C Programming and output verified using various samples.
QUESTIONS
1.What is a fractal image
Fractal is "a rough or fragmented geometric shape that can be split into parts, each of
which is (at least approximately) a reduced-size copy of the whole,"[1] a property called selfsimilarity.
2. Define the following:
(i) X-height (ii) Set (iii) Kerning
X-height: The X-height is the measurement of the height of the character
X, in other words of the middle bit without any ascender or descender.
(ii) Set: The width of the letters is called the set and is fixed relative to the
point-size.
(iii) Kerning: The spaces between letters in one world (tracking) can be
adjusted in a process called kerning.
3. Define the following respective to sound:
(i) Waveform (ii) Frequency (iii) Amplitude
i) Waveform

CS2405 Computer Graphics Lab

Page 62

Sound is produced by the vibration of matter. During the vibration pressure variation
are created in the air surrounding it. The pattern of the oscillation is called a
waveform.
(ii) Frequency
The frequency of the sound is the reciprocal value of the period. It represents the
number of period s in a second and it is measured in Hertz
(Hz) or cycles per second.
(iii) Amplitude
A sound also has amplitude. The amplitude of a sound is a measure
of the displacement of the air pressure wave from its, or quiescent state.
4. Define quantization (or) resolution?
The resolution (or) quantization of a sample value depends on the number of bits used in
measuring the height of the waveform. An 8-bit quantization yields 256 possible values, 16-bit
CD-qudra quantization results in over 65536 values.
5. What are the types of sound objects that can be used in multimedia production?
There are four types of sound objects that can be used in multimedia production:
Waveform audio
MIDI sound tracks
Compact disc (CD) audio
MP3 files
6.What are the applications of fractal image?
Produces visual effect. Hence used in film industry

Gap Analysis Innovative Experiments

CS2405 Computer Graphics Lab

Page 63

HSV to RGB Color Model:


#include<stdio.h>
#include<conio.h>
#include<math.h>
void hsvtorgb(float h,float s,float v);
void main()
{
float h,s,v;
clrscr();
printf("\n HSV to RGB colr model\n");
printf("enter the H,S&V value in range(0-1)\n");
scanf("%f%f%f",&h,&s,&v);
hsvtorgb(h,s,v);
getch();
}
void hsvtorgb(float h,float s,float v)
{
float *r,*g,*b;
int i;
float aa,bb,cc,f;
if(s==0.0)
*r=*g=*b=v;
else
if(h==1.0)
h=0.0;
i=floor(h);
f=h-i;
aa=v*(1-s);
bb=v*(1-(s*f));
cc=v*(1-(s*(1-f)));
switch(i)
{
case 0:
*r=v;
*g=cc;
*b=aa;
break;
case 1:
*r=bb;
*g=v;
*b=aa;
break;
case 2:
*r=aa;
*g=v;
*b=cc;
break;
case 3:
*r=aa;

CS2405 Computer Graphics Lab

Page 64

*g=bb;
*b=v;
break;
case 4:
*r=cc;
*g=aa;
*b=v;
break;
case 5:
*r=v;
*g=aa;
*b=bb;
break;
}
printf("the equivalent RGB valued are:\n R:%f\n G:%f \nB:%f",*r,*g,*b);
}
Conversion Between RGB to CMY and CMY to RGB
#include<stdio.h>
#include<conio.h>
void main()
{
int ch;
float r,g,b,c,m,y;
clrscr();
printf("\n MENU 1.RGB TO CMY \n2. CMY TO RGB \n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Enter the red,green&blue values (0 to 255):");
scanf("%f%f%f",&r,&g,&b);
c=(1-(r/255))*255;
m=(1-(g/255))*255;
y=(1-(b/255))*255;
printf("red:%f \t green:%f \t blue:%f\n",r,g,b);
printf("\n the equivalent CMY value 0:\n\n cyan:%f \t meganta:%f\t yellow:%f",c,m,y);
break;
case 2:
printf("\n enter the cyan,meganta,yellow value(0 to 255):");
scanf("%f%f%f",&c,&m,&y);
r=(1-(c/255))*255;
g=(1-(m/255))*255;
b=(1-(y/255))*255;
printf("cyan:%f\t meganta:%f\t yellow:%f\n",c,m,y);
printf("\n euivalent RGB value is:\n\n red:%f\tgreen:%f\t blue:%f",r,g,b);
break;
}
getch();

CS2405 Computer Graphics Lab

Page 65

}
Adobe Photoshop.
Definition:
Welcome to Adobe Photoshop CS2, breaking new ground as the benchmark of digital
imaging excellence. This latest version of the digital imaging standard introduces new levels of
power, precision and control, with an exciting combination of revolutionary new features and
next-generation enhancements. Photoshop CS2 software pushes the boundaries of digital
photography, helps you turn your dreams into designs faster and more easily than ever before,
and helps you organize and process images in a fraction of the time
The Power to Create the Extraordinary
Adobe Bridge
Vanishing Point

The next-generation File Browser for Photoshop CS2.


Groundbreaking ability to clone, paint and transform in the perspective of
your images.
Image Warp
Warp any object, with customizable presets and adjustable control points.
Noise Reduction Advanced correction of noise created in high-ISO shooting, plus JPEG
artifact reduction. 32-bit HDR Create and edit 32-bit, High Dynamic Range
.
images, for the widest range and richest detail
Spot Healing Brush Fast, efficient one-click retouching of dust, scratches and other image\
One- Click Red Eye CorrectionInstantly eradicate this common photo flaw.
Optical Lens Correction Correct common lens issues like barrel and pincushion distortion.
Animation
Easily create animated Web graphics directly in Photoshop CS2.
Smart Sharpen
Intelligently counteract common photo blurring with advanced control.
Shadow/Highlight Simple discrete adjustment of shadows and highlights, now also for
CMYK images.
Enhanced 16-bit Editing Additional filters, such as Liquify, are now available for use in 16-bit
images.
Creation Acceleration:
Smart Objects

Non-destructive editing and transformations, including Illustrator CS2


integration.
Multiple Layer Control with Smart Guides Faster, more intuitive editing without using the
Layers palette.
Multi-Image Camera Raw Process multiple raw images while you continue to work in Video
Photoshop CS2.
Powerful Design Process Management Easier versioning & collaboration with the new Adobe
Version Cue.
Integrated Adobe Online Services
Access and download professional Adobe Stock Photos
and share and print online with Adobe Photoshop
Adaptability
Making Photoshop CS2 Your Own
Menu Customization Workflow-based presets and custom-defined menu sets, with colorkeyed commands.
Enhanced Automation New actions and scripts facilitating batch image processing and film &
video production.

CS2405 Computer Graphics Lab

Page 66

Variables
Streamline creation of repetitive graphics using imported spreadsheet data.
Event-Based Scripting Expand your efficiency with commands triggered at specific points in
your workflow.
Adobe Help Center
New task-based help topics and search features in a separate floating
window
Procedure:
Step 1: Open Adobe Photoshop application from programs in start menu
Step 2: Click file menu then choose New menu. A New window appears.
Step 3: In new window give the work space and change picture resolution
Step 4: Some tools are,
Tools:
Rectangle Marquee Tool(M):
The rectangle marquee tool is used to select rectangle areas by dragging over the
areas of the image. It can also select elliptical, single row & column.
Move Tool(V) :
The Move tool lets you drag a selection or layer to anew location in the image. With
the info palette open, you can track the exact distance of the move.
Lasso Tool (L):
The Lasso and polygonal lasso is used to draw the both straight edge and freehand
select the segments.
Magic Wand Tool(W):
This tool is used to select the portions of an image based similarities of adjacent
pixels.
Crop Tool(C):
This tool is used to process of removing the portions of an image to create a focus or
strengthen the composition.
Healing Brush Tool(J):
This tool is used to drag the same image.
Patch Tool(P);
This tool is used to repair the selected area with the pixels from another area or a
pattern, like healing brush toll, patch tool matches the texture, lighting, shading the
sampled pixels.
Brush Tool(B):
This tool is used to soft strokes of color and pencil tool creates hard-edged, freehand
lines.
Clone Stamp tool(S):
This tool is used to a sample of image, which you can then apply over image edit at a
part of time.
Eraser Tool(E):
This tool is used to cut or erase the images.
Paint Bucket Tool(G):
This tool is used to allocate the pixels to object or image.
Dodge Tool(Q):
This tool is used to lighten an area of the image. The Burning tool is used to the
direction of image.
Eyedropper Tool(I):
This tool is used to create a sample piece of image to create foreground or
background image.

CS2405 Computer Graphics Lab

Page 67

Text Tool(I):
This tool is used to create text to given image or picture.
Line Tool (L):
This tool is used to draw a line to given image or picture.
Smudge Tool(R):
This tool is used to action or events to handle at that time. It is also used to create a
finger print of the image.
Blur Tool(B):
This tool is used to softens hard edges in an image to reduce details. The sharpen
tool focuses soft edges to increase clarity or focus.
Step 4: After Editing image save the picture document
Step 5: Close the application.
Macromedia Flash
Tween:
To move an object from one place to another place in straight line.
Motion Guide:
To move an object from one place to another place in specified path.
Insert the guide layer and draw the path by using pencil tool.
Change the property of tween to motion.
Shape Tween:
To move an object from one character to another character shape.
Select a character by using text tool.
Change the property of tween to motion.
Insert required blank frames with motion tween.
Select and execute.
Symbol:
To move an object from one shape to another shape.
Select a character by using oval tool and break the object.
In that window select the graphics type and break the object.
Change the property of tween to motion.
Insert required blank frames with motion tween.
Draw another object convert it to symbol as the same break tool.
Select and execute.
Mask:
To mask some letter to object by using in a circle or oval shape.
In layer 1, write some text to be masked and draw, execute the shape.
3D Max:
What is 3D Studio Max Highly customizable and scalable 3D animation, modeling and
rendering solution for creative professionals and largescale pipelines.
What is it used for? Game Development e.g. EA, Rockstar Games
Film and TV Effects, Design Visualization
Layer Manager: Allows you to organize and manage objects as layers
Curve Editor Allows you to work with motion expressed as function curves on a graph
Schematic View node-based scene graph that gives you access to object properties
Material Editor The Material Editor provides functions to create and edit materials and maps
Render Scene Dialog Allows you to set rendering parameters
Consists of:
1) Create Panel

CS2405 Computer Graphics Lab

Page 68

2) Modify Panel
3) Hierarchy Panel
4) Motion Panel
5) Display Panel
6) Utilities Panel
Command Panel: Creating Objects
Can create a wide range of objects
Geometry
Shapes
Lights
Cameras
Helpers
Space Warps
Systems
Modeling a Human: Demo
No point in modeling something you already have E.g., could use an existing model
to make a model of yourself
Modifying Objects
Wide range of modifiers that can be applied to objects
Modifiers provide a way for you to sculpt and edit objects. They can change the geometry of an
object, and its properties.
The modifiers you apply to an object are stored in a stack. By navigating up and down the
stack, you can change the effect of the modifier, or remove it from the object. Or you can choose
to collapse the stack and make your changes permanent.
Example of Mesh Modifiers UVW Map, Unwrap UVW, MultiRes
UVW Map Modifier
Select Faces you want to map
Select the type of Mapping you want
Select the alignment type
Since your head mesh is based on an existing models head, vertices already have texture
coordinates
Character Studio
Advanced character motion toolset
Contains
Behavioral crowd system
1-Click parametric skeletons
Kinematic blending
Visual clipboard
And much, much more!
Physique Modifier
Used to skin the models mesh with the underlying skeleton
Vertices are affected by specific bones by a certain amount or weight
Maxscript
MAXScript is the built-in scripting language for 3ds max and related products, such as
Autodesk VIZ, character studio,
plasma and gmax.
MAXScript provides users of these products with the ability to: Script most aspects of the
program's use, such as modeling, animation, materials, rendering, and so on. Extend or replace
the user interface for objects, modifiers, materials, textures, render effects, and atmospheric
effects. Build scripted plug-ins for custom mesh objects, modifiers, render effects
and more. Build custom import/export tools using ASCII and binary file I/O.

CS2405 Computer Graphics Lab

Page 69

Вам также может понравиться