Computer Graphics Lab Manual
Computer Graphics Lab Manual
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 EXPERIMENTS
4 IMPLEMENTATION OF 2D TRANSFORMATION
7 IMPLEMENTATION OF 3D TRANSFORMATION
9 IMPLEMENTATION OF 3D PROJECTIONS
ALGORITHM AIM:
ALGORITHM:
Step 4:To determine the slope along find dy=y2-y1 ,dx=x2-x1 and slope
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.
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
AIM:
ALGORITHM:
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
Step 7 :Repeat the process until the end point of the line to be drawn is encountered.
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
AIM:
ALGORITHM:
Step 4: Obtain the first point to be plotted on th circumference of the circle centered on the
origin(o,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
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:
ALGORITHM:
Step 4: Translation
Step 5: Scaling
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
a) Along x-direction
x=x1+sx*y1, y=y1
b) Along y-direction
x=x1, y=y1+sy*x1
Step 8: Reflection
a) Along x-axis
theta=(90*ra)/180
b) Along y-axis
theta=(270*ra)/180
c) Along z-axis
theta=(180*ra)/180
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
ALGORITHM AIM:
ALGORITHM:
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.
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
AIM:
ALGORITHM:
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.
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:
ALGORITHM:
Step 3: Translation
Step 4: Scaling
Step 5: Rotation
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:
ALGORITHM:
Step 3: Translation
Step 6: Rotation
Step 5: Scaling
Step 6: Reflection
(90*(3.14/180));
(270*(3.14/180));
lOMoARcPSD|2383750
(180*(3.14/180));
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)
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
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:
ALGORITHM:
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.
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
MAPPING AIM:
ALGORITHM:
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
PROCEDURE:
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.
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.
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:
FILTER- LIQUIFY
lOMoARcPSD|2383750
FILTER-CLOUD
CHANGE COLOUR:
TEXT ON IMAGES:
lOMoARcPSD|2383750
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
OPENGL AIM:
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);
}