0% found this document useful (0 votes)
79 views

Computer Graphics Lab Manual

The document describes a graphics programming course curriculum with the following key points: - The objectives are to understand graphics programming, create 3D scenes using OpenGL, perform image manipulation, and create 2D animations. - The list of experiments includes algorithms for 2D/3D transformations, projections, image editing, animation creation, and developing a graphics project using OpenGL. - The outcomes are that students will be able to create 3D scenes with OpenGL, perform image manipulation, and develop 2D animations.

Uploaded by

Flora Wairimu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Computer Graphics Lab Manual

The document describes a graphics programming course curriculum with the following key points: - The objectives are to understand graphics programming, create 3D scenes using OpenGL, perform image manipulation, and create 2D animations. - The list of experiments includes algorithms for 2D/3D transformations, projections, image editing, animation creation, and developing a graphics project using OpenGL. - The outcomes are that students will be able to create 3D scenes with OpenGL, perform image manipulation, and develop 2D animations.

Uploaded by

Flora Wairimu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

lOMoARcPSD|2383750

lOMoARcPSD|2383750

OBJECTIVES:
The student should be made to:
Understand graphics programming•
Be exposed to creation of 3D graphical scenes using open graphics library
suits• Be familiar with image manipulation, enhancement•
Learn to create animations•
To create a multimedia presentation/Game/Project. •

LIST OF EXPERIMENTS:
IMPLEMENT THE EXERCISES USING C / OPENGL / JAVA
1. Implementation of Algorithms for drawing 2D Primitives – Line (DDA, Bresenham) –
all slopes Circle (Midpoint) – we have completed these already
2. 2D Geometric transformations –
• Translation
• Rotation Scaling
• Reflection Shear
• Window-Viewport
3. Composite 2D Transformations
4. Line Clipping
5. 3D Transformations – Translation, Rotation, Scaling.
6. 3D Projections – Parallel, Perspective.
7. Creating 3D Scenes.
8. Image Editing and Manipulation – Basic Operations on image using any
image editing software, Creating gif animated images, Image optimization.
9. 2D Animation – To create Interactive animation using any authoring tool.
TOTAL: 45
PERIODS
OUTCOMES:
At the end of the course, the student should be able to:
Create 3D graphical scenes using open graphics library
suits• Implement image manipulation and enhancement•
Create 2D animations using tools•

LIST OF EQUIPMENT FOR A BATCH OF 30 STUDENTS:


SOFTWARE
C, C++, Java, OpenGL
HARDWARE:
Standalone desktops –
lOMoARcPSD|2383750

LIST OF EXPERIMENTS

EX.NO NAME OF EXPERIMENT

1 DDA LINE DRAWING ALGORITHM - Done

2 BRESENHAM LINE DRAWING ALGORITHM-Done

3 BRESENHAM CIRCLE DRAWING ALGORITHM- Done

4 IMPLEMENTATION OF 2D TRANSFORMATION

5 LINE CLIPING USING COHEN-SUTHERLAND ALGORITHM

6 POLYGON CLIPPING USING COHEN-SUTHERLAND ALGORITHM

7 IMPLEMENTATION OF 3D TRANSFORMATION

8 IMPLEMENTATION OF COMPOSITE 2D TRANSFORMATION

9 IMPLEMENTATION OF 3D PROJECTIONS

10 WINDOW TO VIEWPORT MAPPING

11 IMAGE EDITING AND MANIPULATION USING ADOBE


PHOTOSHOP

12 CREATION OF GIF ANIMATED IMAGES

13 IMAGE OPTIMIZATION USING ADOBE PHOTOSHOP

14 CREATING 3D SCENE USING OPENGL


lOMoARcPSD|2383750

Ex .No - 1 DDA LINE DRAWING

ALGORITHM AIM:

To write a C program to implement DDA line drawing algorithm.

ALGORITHM:

Step 1:Start the program.

Step 2:Initialize the graphics mode using init graph function.

Step 3:Accept the end points of the line to be drawn x1,,y1,x2,y2.

Step 4:To determine the slope along find dy=y2-y1 ,dx=x2-x1 and slope

=dy/dx. Step 5:calculate the step value.

Step 6:Find the new intermediate points using xᵢ=dx/step and yᵢ=dy/step.

Step 7:Plot pixel using (xᵢ,yᵢ) and repeat this process by incrementing the points (xᵢ,yᵢ) at equal
slope intervals until the end points of the line to be drawn is encountered.

Step 8:Stop the program.

PROGRAM
#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
int main( )
{
float x,y,x1,y1,x2,y2,dx,dy,pixel;
int i,gd,gm;
printf("Enter the value of x1 : ");
scanf("%f",&x1);
printf("Enter the value of y1 : ");
scanf("%f",&y1);
printf("Enter the value of x2 : ");
scanf("%f",&x2);
printf("Enter the value of y1 : ");
scanf("%f",&y2);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
pixel=dx;
else
pixel=dy;
dx=dx/pixel;
lOMoARcPSD|2383750

dy=dy/pixel;
x=x1;
y=y1;
i=1;
while(i<=pixel)
{
putpixel(x,y,4);
x=x+dx;
y=y+dy;
i=i+1;

}
getch();
closegraph();
}
lOMoARcPSD|2383750

Ex No.2 BRESENHAM LINE DRAWING ALGORITHM

AIM:

To write a c program to create Bresenham line drawing algorithm.

ALGORITHM:

Step 1:Start the program.

Step 2:Initialize the graphics mode using init graph function.

Step 3:Accept the input at starting and endpoint of the line to be drawn.

Step 4: Load (xᵢ,yᵢ) into the frame buffer to be plotted as a first point.

Step 5:Calculate the constants ∆x,∆y,2∆y, 2∆y -2∆x and obtain the first decision parameter
P˳=2∆y -2∆x.

Step 6:At each xk along the line starting at k=0 perform the following test

If pk<0,the next point is (xk+1,yK) and pk+1=pk+2∆y,otherwise next point to the


plotted is(xk+1,yk+1),

Otherwise the next point to be plotted is (xk+1,yk+1), and pk+1=pk+2∆y-2∆x.

Step 7 :Repeat the process until the end point of the line to be drawn is encountered.

Step 8: Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd = DETECT,
gm; int dx, dy, p, end;
float x1, x2, y1, y2, x, y;
initgraph(&gd, &gm, "c:\tc\bgi");
printf("Enter Value of X1: ");
scanf("%f", &x1);
printf("Enter Value of Y1:
"); scanf("%f", &y1);
printf("Enter Value of X2:
"); scanf("%f", &x2);
printf("Enter Value of Y2:
"); scanf("%f", &y2);
lOMoARcPSD|2383750

dx = abs(x1 - x2);
dy = abs(y1 - y2);
p = 2 * dy - dx;
if(x1 > x2)
{
x = x2;
y = y2;
end = x1;
}
else
{
x = x1;
y = y1;
end = x2;
}
putpixel(x, y,
1); while(x <
end)
{
if(p < 0)
{x=x+1;
y=y;
p = p + 2 * dy;
}
else
{ x=x+1;
y = y + 1;
p = p + 2 * (dy - dx);
}
putpixel(x, y, 1);
}
getch();
closegraph();
}
lOMoARcPSD|2383750

Ex No.3 BRESENHAM CIRCLE DRAWING ALGORITHM

AIM:

To write a c program to create bresenham circle drawing algorithm.

ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the graphics mode using init graph function.

Step 3: Accept the input at radius and center of the circle.

Step 4: Obtain the first point to be plotted on th circumference of the circle centered on the
origin(o,r).

Step 5: Calculate the initial value of decision parameter P˳=5/4-r.

Step 6: At each xk along the line starting at k=0 perform the following test

If pk<0,the next point is (xk+1,yK) and pk+1=pk+2xk+1+1,otherwise next point to the plotted

is (xk+1,yk-1) and pk+1=pk+2xk+1+1-2yk-1.

Step 7 : Repeat the above steps until x>=y for this circle drawing one octant is generated and
copied for remaining octants.

PROGRAM

# include<stdio.h>
# include<conio.h>
# include<graphics.h>
# include<math.h>
void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();
printf("Enter the radius ");
scanf("%d",&r);
x=0;
y=r;
putpixel(xc+x,yc-y,1);

p=3-(2*r);

for(x=0;x<=y;x++)
lOMoARcPSD|2383750

{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;

p=p+((4*(x-y)+10));
}

putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);

}
getch();
closegraph();
}
lOMoARcPSD|2383750

Ex No.4 IMPLEMENTATION OF 2D

TRANSFORMATION AIM:

To create a C program to implement 2D transformations such as translation, rotation, scaling,


reflection and shearing.

ALGORITHM:

Step 1: Start the program.

Step 2: Initialization the graphics mode using init graph().

Step 3: Declare all variables and draw the 2D .

Step 4: Translation

a) Accept the translation vector(tx,ty).

b) Add the translation vector to corresponding co-ordinates of the 2D object to obtain


the transaltion co-ordinates.

c) Draw the 2D object using translated co-ordinates x’=x+tx, y’=y+ty.

Step 5: Scaling

a) Accept the scaling factor(sx,sy).

b) Multiply the scaling factor to the corresponding co-ordinates of the 2D object to


obtain the scaling co ordinates.

c) Draw the 2D object using scaling co-ordinates x’=x*sx, y’=y*sy.

Step 6: Rotation to rotate the object using the formula

a) Θ=(float)(3.14xra)/180.
b) X1=x2+abs(x1-x2)cosθ-abs(y1-y2)sinθ
c) Y1=y2+abs(x1-x2)sinθ+abs(y1-y2)cosθ
d) X3=x2+abs(x3-x1)cosθ-abs(y3-y1)sinθ
e) Y3=y2+abs(x3-x1)sinθ+abs(y3-y1)cosθ

Step 7 : Shearing

To shear the object using the formula


lOMoARcPSD|2383750

a) Along x-direction

x=x1+sx*y1, y=y1

b) Along y-direction

x=x1, y=y1+sy*x1

Step 8: Reflection

To reflect a object using formula

a) Along x-axis

theta=(90*ra)/180

b) Along y-axis

theta=(270*ra)/180

c) Along z-axis

theta=(180*ra)/180

Step 9: Generate the output.

Step 10: Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int ch,x,y,az,i,w,ch1,p,q,ch2,xa,ya,ra,a[10],b[10],da,db;
float x1,y1,az1,aw1,w1,dx,dy,theta,xls,yls,sx,sy,p1,q1,a1[10],b1[10];
void main()
{
int gm,gr;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
printf("Enter the values 1:\n");
scanf("%d%d",&x,&y);
printf("Enter the values 2:\n");
scanf("%d%d",&az,&w);
printf("Enter the value 3:\n");
scanf("%d%d",&p,&q);
cleardevice();
line(x,y,az,w);
lOMoARcPSD|2383750

line(x,y,p,q);
line(az,w,p,q);
printf("*****2D COMPOSITE TRANSFORMATION *****\n"); printf("1.Translation\
n2.scaling\n3.shearing\n4.Rotation\n5.Reflection\n6.exit\n"); printf("Enter your choice:\
n");
scanf("%d",&ch);
switch(ch)
{
case 1:
cleardevice();
printf("*** Translation ***\n");
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("Enter the translation coordinates:\n"); scanf("%f
%f",&dx,&dy);
x1=x+dx;y1=y+dy;az1=az+dx;w1=w+dy;p1=p+dx;q1=q+dy;
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
break;
case 2:
cleardevice();
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("Enter the scaling value\n"); scanf("%f
%f",&sx,&sy);
x1=x*sx;y1=y*sy;az1=az*sx;w1=w*sy;p1=p*sx;q1=q*sy;
line(x1,y1,az1,w1);
line(x1,y1,p1,q1);
line(az1,w1,p1,q1);
break;
case 3:
cleardevice();
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("**** shearing****\n");
printf("1. X-direction shearing\n 2. Y-direction shearing\n");
printf("Enter your choice:\n");
scanf("%d",&ch2);
switch(ch2)
{
case 1:
cleardevice();
printf("Enter the value of shearing x:\n");
scanf("%f",&xls);
x1=x+(xls*y);
y1=y;
lOMoARcPSD|2383750

az1=az+(xls*w);
w1=w; p1=p+
(xls*q); q=q;
line(x1,y1,az1,w1);
line(x1,y1,p1,q1);
line(az1,w1,p1,q1);
break;
case 2:
cleardevice();
printf("Enter the value of shearing y:\n");
scanf("%f",&yls);
x1=x; y1=y+
(yls*x); az1=az;
w1=w+(yls*az);
p1=p; q1=q+
(yls*p);
line(x1,y1,az1,w1);
line(x1,y1,p1,q1);
line(az1,w1,p1,q1);
break;
}
case 4:
cleardevice();
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
printf("***** Rotation *****\n");
printf("Enter the ra value:\n");
scanf("%d",&ra); theta=(float)
(ra*3.14/180);
x1=az+abs(x-az)*cos(theta)-abs(y-w)*sin(theta);
y1=w+abs(x-az)*sin(theta)+abs(y-w)*cos(theta);
p1=az+abs(p-az)*cos(theta)-abs(q-w)*sin(theta);
q1=w+abs(p-az)*sin(theta)+abs(q-w)*cos(theta);
line(x1,y1,az1,w1);
line(az1,w1,p1,q1);
line(x1,y1,p1,q1);
break;
case 5:
cleardevice();
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
printf("***** Reflection *****\n");
printf("1.ABOUT X-AXES\n2.ABOUT Y-AXES\n3.BOTH AXES\n");
printf("Enter your choice:\n");
scanf("%d",&ch1);
switch(ch1)
lOMoARcPSD|2383750

{
case 1:
cleardevice(); theta=(float)
(90*(3.14/180));
x1=az+abs(x-az)*cos(theta)-abs(-y-w)*sin(theta);
y1=w+abs(x-az)*sin(theta)+abs(-y-w)*cos(theta);
p1=az+abs(p-az)*cos(theta)-abs(-q-w)*sin(theta);
q1=w+abs(p-az)*sin(theta)+abs(-q-w)*cos(theta);
line(x1,y1,az1,w1);
line(az1,w1,p1,q1);
line(x1,y1,p1,q1);
break;
case 2:
cleardevice(); theta=(float)
(270*(3.14/180));
x1=az+abs(-x-az)*cos(theta)-abs(y-w)*sin(theta);
y1=w+abs(-x-az)*sin(theta)+abs(y-w)*cos(theta);
p1=az+abs(-p-az)*cos(theta)-abs(q-w)*sin(theta);
q1=w+abs(-p-az)*sin(theta)+abs(q-w)*cos(theta);
line(x1,y1,az1,w1);
line(az1,w1,p1,q1);
line(x1,y1,p1,q1);
break;
case 3:
cleardevice(); theta=(float)
(180*(3.14/180));
x1=az+abs(-x-az)*cos(theta)-abs(-y-w)*sin(theta);
y1=w+abs(-x-az)*sin(theta)+abs(-y-w)*cos(theta);
p1=az+abs(-p-az)*cos(theta)-abs(-q-w)*sin(theta);
q1=w+abs(-p-az)*sin(theta)+abs(-q-w)*cos(theta);
line(x1,y1,az1,w1);
line(az1,w1,p1,q1);
line(x1,y1,p1,q1);
break;
}
}
}
getch();
closegraph();}
lOMoARcPSD|2383750

Ex No.5 LINE CLIPING USING COHEN-SUTHERLAND

ALGORITHM AIM:

To write a c program to clip a line using the line clipping algorithm.

ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the graphic mode using initgraph.

Step 3: Declare the variables and draw a window and a line using rectangle an line function.

Step 4: Using the values of x1,y1,x2,y2.Check whether the line is within the rectangle
coordinates xmin,ymin,xmax,ymax and clip it.

Step 5: Draw the clipped line in the

window. Step 6: Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
float m,xmin,ymin,xmax,ymax,x1,y1,x2,y2;
void main()
{
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\BGI");
printf(“Enter the xmin ,ymin:\n”);
scanf(“%f%f”,&xmax,&ymax);
printf(“Enter x1,y1:\n”); scanf(%f
%f,&x1,y1); printf(“Enter x2,y2:\
n”); scanf(%f%f,&x2,y2);
cleardevice();
printf(“Before clipping”);
rectangle(xmin,ymin,xmax,ymax);
lOMoARcPSD|2383750

line(x1,y1,x2,y2);
getch();
m=(y2-y1)/(x2-x1);
if(x1<xmin)
{
y1=y1+m*(xmin-x1);
x1=xmin;
}
if(y1<ymin)
{
x1=x1+(ymin-y1)/m;
y1=ymin;
}
if(x1>xmax){
y1=y1-m*(x1-xmax);
x1=xmax;
}
if(y1>ymax)
{
x1=x1-(y1-ymax)/m;
y1=ymax;
}
if(x2<xmin)
{
y2=y2+m*(xmin-x2);
x2=xmin;
}
if(y2<ymin)
{
x2=x2+(ymin-y2)/m;
y2=ymin;
}
If(x2>xmax)
{
y2=y2-m*(x2-xmax);
x2=xmax;
}
if(y2>ymax)
{
x2=x2-(y2-ymax)/m;
y2=ymax;
}
printf(“After clipping:\n);
rectangle(xmin,ymin,xmax,ymax);
printf(“%f%f%f%f”,x1,y1,x2,y2);
line(x1,y1,x2,y2);
getch();
}
lOMoARcPSD|2383750

Ex No. 6 POLYGON CLIPPING USING COHEN-SUTHERLAND ALGORITHM

AIM:

To write a c program to clip a polygon using the line clipping algorithm.

ALGORITHM:

Step 1: Start the program

Step 2: Initialize the graphic mode using initgraph.

Step 3: Declare the variables and draw a window and a polygon shape of based on five lines
using window and line function.

Step 4: Using the clipping function,the values of the lines are checked whether the line is within
the rectangle coordinates xmin,ymin,xmax,ymax and clip it.

Step 5: Draw the clipped line in the

window. Step 6: Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
float m,xmin,ymin,xmax,ymax,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5;
void polc(float x1,float y1,float x2,float y2);
void main()
{
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\BGI");
printf(“Enter the xmin ,ymin:\n”);
scanf(“%f%f”,&xmax,&ymax);
printf(“Enter x1,y1:\n”); scanf(%f
%f,&x1,y1);
lOMoARcPSD|2383750

printf(“Enter x2,y2:\n”);
scanf(%f%f,&x2,y2);
printf(“Enter x3,y3:\n”);
scanf(%f%f,&x3,y3);
printf(“Enter x4,y4:\n”);
scanf(%f%f,&x4,y4);
printf(“Enter x5,y5:\n”);
scanf(%f%f,&x5,y5);

cleardevice();
printf(“Before clipping”);
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x4,y4,x5,y5);
line(x5,y5,x1,y1);
getch();
cleardevice();
printf(“after clipping”);
rectangle(xmin,ymin,xmax,ymax);
polc(x1,y1,x2,y2);
polc(x2,y2,x3,y3);
polc(x3,y3,x4,y4);
polc(x4,y4,x5,y5);
polc(x5,y5,x1,y1);
getch();
}
void polc(float x1,float y1,float x2,float y2)
{
m=(y2-y1)/(x2-x1);
if(x1<xmin)
{
y1=y1+m*(xmin-x1);
x1=xmin;
}
if(y1<ymin)
{
x1=x1+(ymin-y1)/m;
y1=ymin;
}
if(x1>xmax){
y1=y1-m*(x1-xmax);
x1=xmax;
}
if(y1>ymax)
{
x1=x1-(y1-ymax)/m;
y1=ymax;
}
lOMoARcPSD|2383750

if(x2<xmin)
{
y2=y2+m*(xmin-x2);
x2=xmin;
}
if(y2<ymin)
{
x2=x2+(ymin-y2)/m;
y2=ymin;
}
If(x2>xmax)
{
y2=y2-m*(x2-xmax);
x2=xmax;
}
if(y2>ymax)
{
x2=x2-(y2-ymax)/m;
y2=ymax;
}
line(x1,y1,x2,y2);
getch();
}
lOMoARcPSD|2383750

Ex No. 7 3D

TRANSFORMATION AIM:

To write a c program for the implementation of 3D transformation such as translation, scaling,


rotation.

ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the graphic mode and declare the variables.

Step 3: Translation

a) Accept the translation vector(x,y).


b) Add the translation vector to the corresponding coordinates of the 3d object to obtain
the translation coordinates
c) Draw the 3d object.

Step 4: Scaling

a) Accept the scaling factor (x,y,z).


b) Multiply the scaling factor with the corresponding coordinates of the 3d object to
obtain scaling coordinates.
c) Draw the 3d objects.

Step 5: Rotation

a) Accept the rotation angle()


b) Using the angle calculate x1,y1,x2,y2,
c) Using that to draw 3d object x,y,z axis rotation.
lOMoARcPSD|2383750

Step 6: Stop the program

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int maxx,maxy,midx,midy;
void axis()
{
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
}
void main()
{
int x,y,z,x1,x2,t,y1,ch,y2,choice;
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
printf("3D Transformation\n");
printf(" 1.Translation\n 2.Scaling\n 3.Rotation\n 4.exit\n");
printf("Enter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
cleardevice();
axis();
bar3d(midx+50,midy-100,midx+60,midy-90,10,1);
printf("Enter the translation factor:\n"); scanf("%d
%d",&x,&y);
cleardevice();
axis();
bar3d(midx+50,midy-100,midx+60,midy-90,10,1);
printf("After translation\n");
bar3d(midx+x+50,midy-(y+100),midx+x+60,midy-(y+90),10,1);
break;
}
case 2:
{
axis();
bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
printf("Enter the scaling factor:\n"); scanf("%d%d
%d",&x,&y,&z);
lOMoARcPSD|2383750

cleardevice();
axis();
bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
printf("After scaling\n");
bar3d(midx+(x*50),midy-(y*100),midx+(x*60),midy-(y*90),5*z,1);
break;
}
case 3:
{
printf("Enter the rotation angle:\n");
scanf("%d",&t);
x1=50*cos(t*(3.14/180))-100*sin(t*(3.14/180));
y1=50*sin(t*(3.14/180))+100*cos(t*(3.14/180));
x2=60*cos(t*(3.14/180))-90*sin(t*(3.14/180));
y2=60*sin(t*(3.14/180))+90*cos(t*(3.14/180));
printf(" 1.z-axis\n 2.x-axis\n 3.y-axis\n");
printf("Enter your choice:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
cleardevice();
axis();
printf("After rotation about z-axis\n");
bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1);
break;
}
case 2:
{
cleardevice();
axis();
printf("After rotation about x-axis\n");
bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1);
break;
}
case 3:
{
cleardevice();
axis();
printf("After rotation about y-axis\n");
bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1);
break;
}
}
}
}
getch();
closegraph();
}
lOMoARcPSD|2383750

Ex No. 8 COMPOSITE 2D

TRANSFORMATION AIM:

To write a c program to implement composite 2D transformation

ALGORITHM:

Step 1: Start the program.

Step 2: Input the object coordinates.

Step 3: Translation

a) Enter the translation factors tx and ty


b) Move the original coordinate position (x,y,az,w) ,(x,y,p,q) and (az,w,p,q).

Step 6: Rotation

a) Enter the radian value ra.


b) Using the ra calculate theta value Θ=(float)(3.14xra)/180.
c) From the theta value calculate the x,y,p,q values.
d) Rotate the original coordinate position (x,y,az,w),( x,y,p,q) and (az,w,p,q).

Step 5: Scaling

a) Input the scaled factors sx and sy.

b) Transform the coordinates by x’=x*sx, y’=y*sy,az=az*sx, w=w*sy,p=p*sx,q=q*sy.

Step 6: Reflection

a) Along x-axis theta=(float)

(90*(3.14/180));

b) Along y-axis theta=(float)

(270*(3.14/180));
lOMoARcPSD|2383750

c) Along both-axis theta=(float)

(180*(3.14/180));

Using the theta value accordingly find the x,y,p,q

values Step 7 : Shearing

To shear the object using the formula

a)Along x-direction

y=y, x=x+(xls*y),

w=w; az=az+(xls*w),

q=q,p=p+(xls*q).

b) Along y-direction

x=x, y=y+(yls*x),

az=az,w=w+(yls*az),

p=p,q=q+(yls*p)

Step 8: Generate the output.

Step 9: Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int ch,x,y,az,i,w,ch1,p,q,ch2,xa,ya,ra,a[10],b[10],da,db;
float x1,y1,az1,aw1,w1,dx,dy,theta,xls,yls,sx,sy,p1,q1,a1[10],b1[10];
void main()
{
int gm,gr;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
printf("Enter the values 1:\n");
scanf("%d%d",&x,&y);
printf("Enter the values 2:\n");
scanf("%d%d",&az,&w);
lOMoARcPSD|2383750

printf("Enter the value 3:\n");


scanf("%d%d",&p,&q);
cleardevice();
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("*****2D COMPOSITE TRANSFORMATION *****\n");
do
{
printf("1.Translation\n2.scaling\n3.shearing\n4.Rotation\n5.Reflection\n6.exit\n");
printf("Enter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
cleardevice();
printf("*** Translation ***\n");
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("Enter the translation coordinates:\n"); scanf("%f
%f",&dx,&dy);
x=x+dx;y=y+dy;az=az+dx;w=w+dy;p=p+dx;q=q+dy;
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
break;
case 2:
cleardevice();
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("Enter the scaling value\n"); scanf("%f
%f",&sx,&sy);
x=x*sx;y=y*sy;az=az*sx;w=w*sy;p=p*sx;q=q*sy;
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
break;
case 3:
cleardevice();
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
printf("**** shearing****\n");
printf("1. X-direction shearing\n 2. Y-direction shearing\n");
printf("Enter your choice:\n");
scanf("%d",&ch2);
switch(ch2)
{
lOMoARcPSD|2383750

case 1:
cleardevice();
printf("Enter the value of shearing x:\n");
scanf("%f",&xls);
x=x+(xls*y);
y=y; az=az+
(xls*w); w=w;
p=p+(xls*q);
q=q;
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
break;
case 2:
cleardevice();
printf("Enter the value of shearing y:\n");
scanf("%f",&yls);
x=x; y=y+
(yls*x); az=az;
w=w+(yls*az);
p=p; q=q+
(yls*p);
line(x,y,az,w);
line(x,y,p,q);
line(az,w,p,q);
break;
}
case 4:
cleardevice();
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
printf("***** Rotation *****\n");
printf("Enter the ra value:\n");
scanf("%d",&ra); theta=(float)
(ra*3.14/180);
x=az+abs(x-az)*cos(theta)-abs(y-w)*sin(theta);
y=w+abs(x-az)*sin(theta)+abs(y-w)*cos(theta);
p=az+abs(p-az)*cos(theta)-abs(q-w)*sin(theta);
q=w+abs(p-az)*sin(theta)+abs(q-w)*cos(theta);
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
break;
case 5:
cleardevice();
line(x,y,az,w);
line(az,w,p,q);
lOMoARcPSD|2383750

line(x,y,p,q);
printf("***** Reflection *****\n");
printf("1.ABOUT X-AXES\n2.ABOUT Y-AXES\n3.BOTH AXES\n");
printf("Enter your choice:\n");
scanf("%d",&ch1);
switch(ch1)
{
case 1:
cleardevice(); theta=(float)
(90*(3.14/180));
x=az+abs(x-az)*cos(theta)-abs(-y-w)*sin(theta);
y=w+abs(x-az)*sin(theta)+abs(-y-w)*cos(theta);
p=az+abs(p-az)*cos(theta)-abs(-q-w)*sin(theta);
q=w+abs(p-az)*sin(theta)+abs(-q-w)*cos(theta);
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
break;
case 2:
cleardevice(); theta=(float)
(270*(3.14/180));
x=az+abs(-x-az)*cos(theta)-abs(y-w)*sin(theta);
y=w+abs(-x-az)*sin(theta)+abs(y-w)*cos(theta);
p=az+abs(-p-az)*cos(theta)-abs(q-w)*sin(theta);
q=w+abs(-p-az)*sin(theta)+abs(q-w)*cos(theta);
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
break;
case 3:
cleardevice(); theta=(float)
(180*(3.14/180));
x=az+abs(-x-az)*cos(theta)-abs(-y-w)*sin(theta);
y=w+abs(-x-az)*sin(theta)+abs(-y-w)*cos(theta);
p=az+abs(-p-az)*cos(theta)-abs(-q-w)*sin(theta);
q=w+abs(-p-az)*sin(theta)+abs(-q-w)*cos(theta);
line(x,y,az,w);
line(az,w,p,q);
line(x,y,p,q);
break;
}
}
}while(ch!=6);
getch();
closegraph();
}
lOMoARcPSD|2383750

Ex No.9 3D PROJECTIONS

AIM:

To write a program to implement 3D projection

ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the

variables.

Step 3: Get the number of sides ‘s’ using the calculate the coordinate points.

Step 4: Get the depth value ‘d’ uing the print the 3d object by draw3d function.

Step 5: Print the top view,side view and bottom view of the 3d object.

Step 6: Stop the program

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void draw3d(int s,int x[20],int y[20],int d);
void main()
{
int gd=DETECT,gm;
int x[20],y[20],i,s,d;
initgraph(&gd,&gm,"");
printf("enter the no of sides");
scanf("%d",&s);
for(i=0;i<s;i++)
{
printf("x%d,y%d:",i,i);
scanf("%d %d",&x[i],&y[i]);
}
printf("depth:");
scanf("%d",&d);
draw3d(s,x,y,d);
getch();
lOMoARcPSD|2383750

setcolor(14);
for(i=0;i<s-1;i++)
{
line(x[i]+200,y[i],x[i+1]+200,y[i+1]);
} line(x[i]
+200,y[i],x[0]+200,y[0]);
getch();
for(i=0;i<s-1;i++)
{
line(x[i],300,x[i+1],300);
line(x[i],300+d*2,x[i+1],300+d*2);
line(x[i],300,x[i],300+d*2);
line(x[i+1],300,x[i+1],300+d*2);
}getch();
for(i=0;i<s-1;i++)
{
line(10,y[i],10,y[i+1]);
line(10+d*2,y[i],10+d*2,y[i+1]);
line(10,y[i],10+d*2,y[i]);
line(10,y[i+1],10+d*2,y[i+1]);
}
getch();
closegraph();
}
void draw3d(int s,int x[20],int y[20],int d)
{
int i,j,k=0;
for(j=0;j<2;j++)
{
for(i=0;i<s-1;i++)
line(x[i]+k,y[i]-k,x[i+1]+k,y[i+1]-k);
line(x[i]+k,y[i]-k,x[0]+k,y[0]-k);
k=d;
}
for(i=0;i<s;i++)
line(x[i],y[i],x[i]+d,y[i]-d);
}
lOMoARcPSD|2383750

Ex No.10 WINDOW TO VIEWPORT

MAPPING AIM:

To write a c program to clip a window to viewport mapping.

ALGORITHM:

Step 1: Start the program

Step 2: Get the maximum and minimum coordinates of the window.

Step 3: Get the maximum and minimum coordinates of the viewport.

Step 4: Get the vertices of the triangles.

Step 5: Display the output by fiiting window in viewport.

Step 6: Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
float xwmin,xwmax,ywmax,ywmin;
float xvmin,xvmax,yvmax,yvmin;
float x[10],y[10],yv,xv,sx,sy;
int gd=DETECT,gm; int i;
clrscr();
printf("\n ENTER THE WINDOW PORT COORDINATES:\nxwmin,ywmin,xwmax,ywmax);");
scanf("%f%f%f%f",&xwmin,&ywmin,&xwmax,&ywmax);
printf("\n ENTER THE VIEW PORT COORDINATES:\
n(xvmin,yvmin,xvmax,yvmax);"); scanf("%f%f%f
%f",&xvmin,&yvmin,&xvmax,&yvmax);
printf("\n enter vertices for triangle:");
for(i=0;i<3;i++)
lOMoARcPSD|2383750

{
printf("enter (x%d,y%d);",i,i);
scanf("%f%f",&x[i],&y[i]);
}
sx=((xvmax-xvmin)/(xwmax-xwmin));
sy=((yvmax-yvmin)/(ywmax-ywmin));
initgraph(&gd,&gm,"c:\\tc\\BGI");
outtextxy(80,30,"WINDOW PORT");
rectangle(xwmin,ywmin,xwmax,ywmax);
for(i=0;i<2;i++)
{
line(x[i],y[i],x[i+1],y[i+1]);
}
line(x[2],y[2],x[0],y[0]);
getch();
cleardevice();
for(i=0;i<3;i++)
{
x[i]=xvmin+((x[i]-ywmin)*sx);
y[i]=yvmin+((y[i]-ywmin)*sy);
}
outtextxy(150,10,"view port");
rectangle(xvmin,yvmin,xvmax,yvmax);
for(i=0;i<2;i++)
{
line(x[i],y[i],x[i+1],y[i+1]);
}
line(x[2],y[2],x[0],y[0]);
getch();
}
lOMoARcPSD|2383750

ex . No 11 - IMAGE EDITING AND MANIPULATION USING ADOBE PHOTOSHOP

PROCEDURE:

Simple image editing

1. Start ->Photoshop and open the image from the drive and try out the different tools.
i. Rotate
Image – Image Rotation – try out the different options.
ii. Resize
Choose in the menu Image – Image Size – e.g. under Pixel Dimensions (e.g.
percentage-wise alteration) or Document Size (cm). You can change the resolution of
the image in the Resolution field.
iii. Crop
Select the Crop Tool from the Tool-palette.
Click and drag diagonally with the mouse over the image, and double-click in the marked area,
when you have the segment you wish to keep.
iv. Zoom
Select the Zoom Tool from the Tool-palette. Zoom doesn’t change the actual size.
Hold down the ALT-key to zoom out again (- in the magnifying glass).
v. Brightness/Contrast
If the image is a little too dark, you can adjust the brightness and contrast under, Adjustments in
the menu Image, Brightness and Contrast or Shadow/Highlight.
vi. Right the scene
If a scene is oblique you can right it by selecting the entire image Select - All. Next
choose Edit – Free Transform and right the scene by moving the mouse out of the
selection square, till the mouse changes it’s appearance to a bended arrow:
vii. Filter
There are many different ways to transform pictures into artworks in Photoshop.
Try one of the many filters on the image such as Liquify, Noise, Texture, Render
Difference clouds etc.

Colour change, image extraction and merging of images

i. Change colour
a. Select in the menu Image – Adjustments – Replace Colour.
b. Mark the button Image under the motif.
c. With the pipette (Eyedropper Tool) collect the most dominant colour of the image.
d. Under the headline Replace, select a substitute colour, by dragging the sliding bar in
Hue, Saturation and Lightness.
lOMoARcPSD|2383750

e. Then select (pipette with a +) and select the additional colour shades and click OK.

ii. Extracting image from background


a. Select the Magic Wand Tool from the Tool-palette and set the Tolerance to 30 – a
higher value, will select a larger colour area.
b. lick in the white area. Adjoining areas can be included in the marking by holding down
the SHIFT-key and simultaneously clicking with the Magic Wand in the area. If a too
large area has been marked, you can exclude an area by holding down the ALT-key.
c. Select the Background Eraser Tool and adjust the thickness and shape of the eraser.
Erase the background – pay attention to missed spots in the check pattern that appears.
(An alternative could be to select the Quick Selection Tool or the Magic Eraser Tool)

iii. Reduce the size of the image


Image – Image Size – use the adjustments of the width in % of the original. If the size
is not as wanted, select Undo from the Edit menu and try again.

iv. Copy one image to another image


a. Select the Rectangular Marquee Tool from the Tool-palette.
b. Draw a square around the motif.
c. Select in the menu Edit – Copy.
d. Click the other image and select Edit – Paste. The first image is now placed in a
new layer.
e. Select the Move Tool in the Tool-palette and move the image to a required position.

Text on images
1. Open the desired image.
2. Select the Horizontal Type Tool from the Tool-palette and try the different text
attributes on the Properties-palette.
3. Click (or drag to create a textbox) where you want the text to be placed, and type
the desired text.

Save all the images as when the images are edited and manipulated.
lOMoARcPSD|2383750

ORIGINAL IMAGE:

ROTATION

1.180 DEGREE
lOMoARcPSD|2383750

RESIZE IMAGE:

CROP:
lOMoARcPSD|2383750

ZOOM:

BRIGHTNESS AND CONTRAST:


lOMoARcPSD|2383750

RIGHT THE SCENE:

FILTER- LIQUIFY
lOMoARcPSD|2383750

FILTER-CLOUD

COLOUR CHANGE,IMAGE EXTRACTION AND MERGING OF IMAGES:


lOMoARcPSD|2383750

CHANGE COLOUR:

EXTRACTING IMAGE FROM BACKGROUND:


lOMoARcPSD|2383750

TEXT ON IMAGES:
lOMoARcPSD|2383750

Ex.No - 12 CREATION OF GIF ANIMATED

IMAGES PROCEDURE:

1. Import images into Photoshop. (Open the image with Adobe Photoshop)
2. Create new layer and copy each images to the layer.
3. Adjustments can be made if necessary.
4. Save the file.
5. File->Jump To ->Adobe Image Ready 7.0 or by clicking the icon from Tools.
6. Open Animation pane from Window option.
7. Choose Make Frames from Layers option by clicking on the double right arrow on the
top right corner of the animation pane.
8. The layers created in Photoshop are converted to frames in ImageReady.
9. Next go to File->Save optimized As and save the file in gif format.
10. Open the file in browser.
lOMoARcPSD|2383750

Ex.No – 13 IMAGE OPTIMIZATION USING ADOBE PHOTOSHOP

1. Open Adobe Photoshop7.0 .


2. Go to File->Open and select any image from your computer.
3. Now go to File->Save for web option
4. Click the original tab to view the size,downloadspeed,quality of the original image
5. Click optimized tab to enter custom values for width and height on the right pane of
the window
6. Go to 4-up and pick any optimized image ,its download option and click save button.
7. A save optimized dialog box will open, enter a new name and click save.
lOMoARcPSD|2383750

Ex .No -14 CREATING 3D SCENE USING

OPENGL AIM:

To implement and create 3D scene using opengl.

STEPS TO RUN OPENGL FILE

1. C:\OPEN-GL\GL Files\include\GL
Copy all the files to C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl
2. C:\OPEN-GL\GL Files\lib
Copy all files to C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
3. C:\OPEN-GL\GL Files\dll
Copy all to C:\WINDOWS\system32
4. Start-visual studio-file-new-project-visual c++-win32-console application –enter
name- save
lOMoARcPSD|2383750

5. Remove all content except header file and start typing the coding
6. Solution explorer-filename-right click-
properties c/c++-preprocessor-change to all
configurations
enter the path C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include
7. Solution explorer-filename-right click-
properties Linker-input- change to all
configurations
Type the path-opengl32.lib glut32.lib glu32.lib
8. Build-project name
9. Debug-start without debugging

PROGRAM

#include <glut.h>
GLfloat light_diffuse[] = {7.0, 1.0, 2.0, 6.0};
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
GLfloat n[6][3] = {
{-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} };
GLint faces[6][4] = {
{0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4},
{4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} };
GLfloat v[8][3];
void
drawBox(void)
{
int i;
for (i = 0; i < 6; i++) {
glBegin(GL_QUADS);
glNormal3fv(&n[i][0]);
glVertex3fv(&v[faces[i][0]][0]);
glVertex3fv(&v[faces[i][1]][0]);
glVertex3fv(&v[faces[i][2]][0]);
glVertex3fv(&v[faces[i][3]][0]);
glEnd();
}
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawBox();
lOMoARcPSD|2383750

glutSwapBuffers();
}

void init(void)
{
v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1;
v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1;
v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1;
v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1;
v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;
v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
gluPerspective(40.0,1.0,1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.);
glTranslatef(0.0, 0.0, -1.0);
glRotatef(60, 1.0, 0.0, 0.0);
glRotatef(-20, 0.0, 0.0, 1.0);
}

int main(int argc, char **argv)


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("red 3D lighted cube");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
lOMoARcPSD|2383750

You might also like