CGM Record
CGM Record
CGM Record
Name :
Register No. :
Year and Semester : IV / VII
Branch and Section : CSE / A
Course Code and Title : 18PD14 / Computer Graphics and Multimedia
Academic Year : 2023 – 2024
BONAFIDE CERTIFICATE
Computer Science and Engineering (Branch) during the academic year 2021-2022
VISION
To create computer professionals with a strong academic and technical background to achieve
special distinction at the national and international arena and also to serve and lead the society.
MISSION
Providing excellent learning opportunities for students in Computer Science and
Engineering to meet the needs of Nation as a whole
Establishing centers of research in areas of the immediate needs to the society
PROGRAM OUTCOMES
PSO-1 Analyze, design, implement, test and evaluate computer programs in the areas related to
algorithms, networking, web design, cloud computing, IoT and data analytics of varying
complexity.
PSO-2 Develop innovative ideas to provide solutions for complex problems and apply advanced
knowledge of computer science domain to identify research challenges in Computer Science and
Engineering.
INDEX
Signature
Sl. Page
Date Name of Experiment Marks of the
No No.
faculty
1(a) BRESENHAM’S ALGORITHM FOR LINE 2
1(b) BRESENHAM’S ALGORITHM FOR ELLIPSE 5
1(c) BRESENHAM’S ALGORITHM FOR CIRCLE 8
1(d) MID – POINT CIRCLE ALGORITHM 11
2(a) PERFORMING 2D TRANSFORMATIONS 14
2(b) PERFORMING 2D TRANSFORMATIONS 18
3(a) IMPLEMENTING OF COHEN – SUTHERLAND 2D 23
CLIPPING
3(b) IMPLEMENTING OF WINDOW – TO – VIEWPORT 27
MAPPING
4 PERFORMING 3D TRANSFORMATIONS 30
5 VISUALIZING PROJECTIONS OF 3D IMAGES 34
6(a) CONVERSION BETWEEN RGB TO HSV COLOR 36
MODEL
6(b) CONVERSION BETWEEN HSV TO RGB COLOR 39
MODEL
6(c) IMPLEMENTING OF TEXT COMPRESSION 42
ALGORITHM
7(a) SIMPLE PRESENTATION USING MOTION TWEEN 46
7(b) IMAGE EDITING AND MANIPULATION USING 49
ADOBE PHOTOSHOP
7(c) MASKING, PENDULUM USING MACROMEDIA 59
FLASH
8 2D ANIMATION 61
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
LIST OF EXPERIMENTS
5. Composite 3D transformation.
7. Image editing and manipulation – basic operations on image using any image editing
software, creating gif animated images, and image optimization.
1
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Step 2: Input the two line endpoints and the left endpoint in (x0, y0).
Step 3: Load (x0, y0) into the frame buffer that is plot the first point.
Step 4: Calculate constants ∆x, ∆y, 2∆y and 2∆y-2∆x, and obtain the starting value for the decision
parameter as P0=2∆y-∆x.
Step 5: At each xk along the line, Starting at k=0, perform the following test:
Program:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gdriver = DETECT, gmode;
int x1,y1,x2,y2,dx,dy,x,y,xend,p;
initgraph(&gdriver, &gmode, "");
printf("\n\n\n\tBresanham line drawing algorithm");
printf("\n\t-----------------------------");
printf("\n\nEnter the value of x1,y1,x2,y2:::");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=abs(x1-x2), dy=abs(y1-y2),p=2*dy-dx;
if(x1>x2)
{
2
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
x=x2;
y=y2;
xend=x1;
}
else
{
x=x1;
y=y1;
xend=x2;
}
putpixel(x,y,WHITE);
while(x<xend)
{
x++;
if(p<0)
p+=2*dy;
else
{
y++;
p+=2*(dy-dx);
}
putpixel(x,y,WHITE);
}
getch();
closegraph();
}
3
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to implement the Bresenham's algorithm for Line is executed and the output is
verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
4
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Step 2: Input rx, ry and ellipse center (xc, yc) and obtain the first point on an ellipse centered on the
origin as (x0, y0)= (0, ry).
Step 3: Calculate the initial value of the decision parameter in region 1 as P10=ry2-rx2ry+1/4 rx2.
Step 4: At each xk position in Region 1, starting at k=0, perform the following test,
If p1k<0, the next point along the ellipse centered on (0, 0) is (xk+1, yk) and
p1k+1=p1k+2ry2xk+1+ry2
Otherwise, the next point along the circle is (xk+1, yk-1) and p1k+1=p1k+2ry2xk+1-2rx2yk+1+ry2 with
2ry2xk+1=2ry2xk+2ry2 2rx2yk+1=2rx2yk-2rx2, and continue the Initial value of the decision parameter
in region 2 using the last point (x0,y0) calculated in region 1 as p20=ry2(x0+1/2)2+rx2(y0-1)2 -rx2ry2.
Step 5: At each yk position in region 2, starting at k=0, perform the following test,
If p2k>0, the next point along the ellipse centered on (0, 0) is (xk ,yk-1) and p2k+1=p2k-2rx2yk+1+rx2.
Otherwise, the next point along the circle is (xk+1,yk-1) and p2k+1=p2k+2ry2xk+1-2ry2yk+1+rx2 using
the same incremental calculations for x and y as in region 1.
Step 7: Move each calculated pixel position (x, y) on to the elliptical path centered on (xc, yc) and plot
the co-ordinate values:
x=c+xc
y=y+yc
5
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Program:
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#define round(a) ((int)(a+0.5))
void ellip(int xcen, int ycen, int x, int y)
{
putpixel(xcen + x, ycen + y, 2);
putpixel(xcen - x, ycen + y, 2);
putpixel(xcen + x, ycen - y, 2);
putpixel(xcen - x, ycen - y, 2);
}
int main()
{
int gd = DETECT, gm;
int xcen, ycen, rx, ry;
int rx1, ry1, rx2, ry2;
int p, x, y, px, py;
void ellip(int, int, int, int);
initgraph(&gd, &gm, "");
printf("\n\n\t\t Ellipse DRAWING ALGORITHM");
printf("\n\n\nEnter the coordinates degree(Rx,Ry)::");
scanf("%d%d", &rx, &ry);
printf("Enter coordinates center(x,y)::");
scanf("%d%d", &xcen, &ycen);
rx1 = rx * rx, ry1 = ry * ry, rx2 = 2 * rx1, ry2 = 2 * ry1;
x = 0, y = ry, px = 0, py = rx2;
ellip(xcen, ycen, x, y);
p = round(ry1 - (rx1 * ry) + (0.25 * rx1));
while (px < py)
{
x++;
px += ry2;
if (p < 0)
p += ry1 + px;
else
{
y--;
py -= rx2;
p += ry1 + px - py;
}
ellip(xcen, ycen, x, y);
}
p = round(ry1 * (x + 0.5) * (x + 0.5) + rx1 * (y - 1) * (y - 1) - rx1 * ry1);
while (y > 0)
{
y--;
py -= rx2;
6
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
if (p > 0)
p += rx1 - py;
else
{
x++;
px += ry2;
p += rx1 - py + px;
}
ellip(xcen, ycen, x, y);
}
getch();
closegraph();
return 0;
}
Output:
Result:
Thus the program to implement the Bresenham's Algorithm for Ellipse is executed and the
output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
7
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Step 2: Input the radius r and circle center(xc, yc) and obtain the first point on the circumference of a
circle centered on the origin as, (x0,y0)=(o, r).
Step 3: Calculate the Initial value of the decision parameter as, P0=5/4-r.
If pk<0, the next point along the circle centered on (0, 0) is (xk+1, yk) and pk+1=pk+2xk+1+1.
Otherwise the next point along the circle is (xk+1, yk- 1) and pk+1=pk+2xk+1-2yk+1. Where,
2xk+1=2xk+2 2yk+1=2yk-2.
Step 6: Move each calculated pixel position (x, y) onto the circular path centered on (xc, yc) and plot
the co-ordinate values:
x=x+xc
y=y+yc
Program:
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void circlepoints(int xcenter,int ycenter,int x,int y)
{
putpixel(xcenter+x,ycenter+y,WHITE);
putpixel(xcenter-x,ycenter+y,WHITE);
putpixel(xcenter+x,ycenter-y,WHITE);
putpixel(xcenter-x,ycenter-y,WHITE);
8
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
putpixel(xcenter+y,ycenter+x,WHITE);
putpixel(xcenter-y,ycenter+x,WHITE);
putpixel(xcenter+y,ycenter-x,WHITE);
putpixel(xcenter-y,ycenter-x,WHITE);
}
void circle1(int xcenter,int ycenter,int radius)
{
int x=0,y=radius,p=1-radius;
circlepoints(xcenter, ycenter,x,y);
while( x < y)
{
if(p<0)
x++;
else
{
x++;
y--;
}
if(p<0)
p+=2 * x+1;
else
p+= 2 * (x-y) +1;
circlepoints(xcenter,ycenter,x,y);
}
}
void main()
{
int gdriver = DETECT, gmode;
int x1,y1,r;
initgraph(&gdriver, &gmode, "");
printf("\n\n\n\tBresanham mid-point circle generating algorithm");
printf("\n\t ------------------------------------------------- ");
printf("\n\n\nEnter the values of x-y coordinates and radius::");
scanf("%d%d%d",&x1,&y1,&r);
circle1(x1,y1,r);
getch();
closegraph();
}
9
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to implement the Bresenham’s Algorithm for Circle is executed and the
output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
10
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
To write a C program to implement the mid-point circle algorithm for moving wheel.
Algorithm:
Step 1: Get the input of two end points (X0,Y0) and (X1,Y1).
dx = X1 - X0
dy = Y1 - Y0
Step 3: Based on the calculated difference in step-2, you need to identify the number of steps to put
pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and complete the
drawing of the line.
Step 6: Input radius r and circle center (xc,yc) and obtain the first point on the circumference of
the circle centered on the origin as (x0, y0) = (0, r)
If PK< 0 then next point on circle (0,0) is (XK+1,YK) and PK+1 = PK + 2XK+1 + 1
Step 10: Move each calculate pixel position (X, Y) onto the circular path centered on (XC,YC)
and plot the coordinate values.
X = X + XC, Y = Y + YC
Program:
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int x,y,x_mid,y_mid,radius,dp;
int g_mode,g_driver=DETECT;
clrscr();
initgraph(&g_driver,&g_mode,"C:\\TURBOC3\\BGI");
printf("*********** MID POINT Circle drawing algorithm ********\n\n");
printf("\nenter the coordinates= ");
scanf("%d %d",&x_mid,&y_mid);
printf("\n now enter the radius =");
scanf("%d",&radius);
x=0;
y=radius;
dp=1-radius;
do
{
putpixel(x_mid+x,y_mid+y,YELLOW);
putpixel(x_mid+y,y_mid+x,YELLOW);
putpixel(x_mid-y,y_mid+x,YELLOW);
putpixel(x_mid-x,y_mid+y,YELLOW);
putpixel(x_mid-x,y_mid-y,YELLOW);
putpixel(x_mid-y,y_mid-x,YELLOW);
putpixel(x_mid+y,y_mid-x,YELLOW);
putpixel(x_mid+x,y_mid-y,YELLOW);
if(dp<0)
dp+=(2*x)+1;
else
{
y=y-1;
dp+=(2*x)-(2*y)+1;
}
12
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
x=x+1;
}while(y>x);
getch();
}
Output:
Result:
Thus the program to implement the mid-point circle algorithm for moving wheel is executed and
the output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
13
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Step 4: Draw the polygon using the vertices and input type of transformation on the Polygon.
x1=x1+tx
y1=y1+ty
x2=x2+tx
y2=y2+ty
• Input the scaling factors sx,sy and the reference co-ordinates xf,yf.
• Call scale() which calculates
x'=x. sx+x’(1-sx)
y’=y. sy+y’(1-sy)
14
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
x'=xr+(x-xr)cosθ-(y-yr)sinθ
y’=yr+(x-xr)sinθ-(y-yr)cosθ
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void translate(int,int);
void scale(int,int);
void rotate(float);
void main()
{
intch;
intgd=DETECT,gm;
inttx,ty,sx,sy;
float theta;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setbkcolor(WHITE);
setcolor(6);
outtextxy (100,88,"Object.");
rectangle(100,250,150,200);
printf("---MENU---");
printf("\n 1)Translate\n 2)Scale\n 3)Rotate");
printf("\nEnter your choice: ");
scanf("%d",&ch);
cleardevice();
switch(ch)
{
case 1:
outtextxy(10,45,"Enter value of tx and ty:");
scanf("%d %d",&tx,&ty);
translate(tx,ty);
break;
case 2:
outtextxy(10,45,"Enter the value of sx and sy:");
scanf("%d%d",&sx,&sy);
scale(sx,sy);
break;
case 3:
outtextxy(10,50,"Enter the angle for rotation: ");
15
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
scanf("%f",&theta);
rotate(theta);
break;
default: printf("you have enterd wrong choice");
break;
}
getch();
closegraph();
}
void translate(inttx,intty)
{
setcolor(2);
outtextxy(240,10,"TRANSLATION");
outtextxy(238,20,"------------");
rectangle(100,250,150,200);
rectangle(100+tx,250+ty,150+tx,200+ty);
}
void scale(intsx,intsy)
{
setcolor(2);
outtextxy(240,10,"SCALING");
outtextxy(238,20,"--------");
rectangle(100,250,150,200);
rectangle(100*sx,250*sy,150*sx,200*sy);
}
void rotate(float theta)
{
int x1,x2,x3,x4;
int y1,y2,y3,y4;
int ax1,ax2,ax3,ax4,ay1,ay2,ay3,ay4;
intrefx,refy;
theta=theta*(3.14/180);
setcolor(2);
outtextxy(240,10,"ROTATE");
outtextxy(238,20,"-------");
refx=100;
refy=100;
x1=100;
y1=100;
x2=150;
y2=100;
x3=150;
y3=150;
x4=100;
y4=150;
ax1=refy+(x1-refx)*cos(theta)-(y1-refy)*sin(theta);
ay1=refy+(x1-refx)*sin(theta)+(y1-refy)*cos(theta);
ax2=refy+(x2-refx)*cos(theta)-(y2-refy)*sin(theta);
ay2=refy+(x2-refx)*sin(theta)+(y2-refy)*cos(theta);
16
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
ax3=refy+(x3-refx)*cos(theta)-(y3-refy)*sin(theta);
ay3=refy+(x3-refx)*sin(theta)+(y3-refy)*cos(theta);
ax4=refy+(x4-refx)*cos(theta)-(y4-refy)*sin(theta);
ay4=refy+(x4-refx)*sin(theta)+(y4-refy)*cos(theta);
rectangle(100,150,150,100);
line(ax1,ay1,ax2,ay2);
line(ax2,ay2,ax3,ay3);
line(ax3,ay3,ax4,ay4);
line(ax4,ay4,ax1,ay1);
}
Output:
Result:
Thus the program to perform 2D Transformations such as translation, scaling and rotation is
executed and the output is verified
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
17
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
To write a C program for implementing the two dimensional transformation such as Shearing &
Reflection.
Algorithm:
Step 4: For shearing read the shearing factor and apply the shearing factor formula with respect to x
& y.
i) x’ = x + shx*y y’ = y
ii) y’=y + shy*x x’= x
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<alloc.h>
#include<stdlib.h>
intn,i,p[20],q[20];
intconvertx(int x);
intconverty(int y);
void axis(void);
voidinit(void);
void shear(void);
void reflect(void);
void main()
{
intch,gd=DETECT,gm;
initgraph(&gd,&gm,"e:\\tc\\bgi");
axis();
printf("\b");
cleardevice();
printf("Enter the number of vertices:");
18
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
scanf("%d",&n);
printf("Enter the co-ordinate center the first vertex at the end");
for(i=0;i<2*n+2;i++)
scanf("%d",&p[i]);
clrscr();
init();
getch();
do
{
clrscr();
cleardevice();
printf("\n \t\t2D-Transformation \n1.reflection\n2.shearing\n");
printf("\n\nEnteryuor choice:\n");
scanf("%d",&ch);
clrscr();
cleardevice();
switch(ch)
{
case 1:
reflect();
break;
case 2:
shear();
break;
}
}while(ch!=3);
closegraph();
}
void axis(void)
{
cleardevice();
setlinestyle(SOLID_LINE,1,1);
line(320,0,320,getmaxy());
line(0,240,getmaxx(),240);
outtextxy(325,245,"0");
line(316,40,324,40);
outtextxy(325,41,"400");
line(316,440,324,440);
outtextxy(325,441,"-400");
line(20,236,20,244);
outtextxy(19,250,"-600");
line(620,236,620,244);
outtextxy(608,250,"600");
}
voidinit()
{
cleardevice();
axis();
setcolor(YELLOW);
19
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
setlinestyle(SOLID_LINE,1,1);
for(i=0;i<2*n+2;i+=2)
q[i]=convertx(p[i]);
for(i=1;i<2*n+2;i+=2)
q[i]=converty(p[i]);
drawpoly(n+1,q);
setcolor(WHITE);
}
intconvertx(int x)
{
x=x/2;
return(x+=320);
}
intconverty(int y)
{
y=y/2;
return(y+=240-y);
}
void shear()
{
intsh[20],sho[20];
floatshx,shy,c;
printf("(1)share relate to x-axis\n");
printf("(2)share relate to y-axis\n");
printf("\n Enter your choice:");
scanf("%f",&c);
if(c==1)
{
init();
printf("\ Enter the shear factor(shx):");
scanf("%f",&shx);
for(i=1;i<2*n+2;i+=2)
sh[i]=p[i]+(shx*(p[i+1]));
for(i=0;i<2*n+2;i+=2)
sh[i]=p[i];
}
else
{
init();
printf("\enter the shear factor(shy):");
scanf("%f",);
for(i=1;i<2*n+2;i+=2)
sh[i]=(shy*p[i-1])+p[i];
for(i=0;i<2*n+2;i+=2)
sh[i]=p[i];
}
setlinestyle(DOTTED_LINE,1,1);
for(i=0;i<2*n+2;i+=2)
sho[i]=convertx(sh[i]);
20
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
for(i=1;i<2*n+2;i+=2)
sho[i]=converty(sh[i]);
drawpoly(n+1,sho);
getch();
}
void reflect()
{
inti,c,rf[20],rft[20];
printf("\n 1.x-axis reflection\n 2.y-axis reflection");
printf("\n Enter the choice:");
scanf("%d",&c);
clrscr();
cleardevice();
if(c==1)
{
for(i=1;i<2*n+2;i+=2)
rf[i]=p[i]*(-1);
for(i=0;i<2*n+2;i+=2)
rf[i]=p[i];
}
else
{
for(i=0;i<2*n+2;i+=2)
rf[i]=p[i]*(-1);
for(i=1;i<2*n+2;i+=2)
rf[i]=p[i];
}
init();
setlinestyle(DOTTED_LINE,1,1);
for(i=0;i<2*n+2;i+=2)
rft[i]=convertx(rf[i]);
for(i=1;i<2*n+2;i+=2)
rft[i]=converty(rf[i]);
drawpoly(n+1,rft);
getch();
}
21
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to program for implementing the two dimensional transformation such as
Shearing & Reflection is executed and the output is verified
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
22
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Input the window co-ordinates and draw the rectangular window on the screen.
Step 3: Check the bottom endpoint of the line p1 against the left, right and bottom boundaries of the
window and find whether it is below the clip window.
Step 4: If p1 is below the clip window, find the point of intersection of the line with the bottom
boundary of the window as p1’.
Step 6: Check whether the point p2 is above the clip window, (ie) outside the clip window.
Step 7: If p2 is above the clip window and to the left/right of the window, find the point of
intersection of the line with the left/right boundary of the window as p2’.
Step 8: Find the final point of intersection of the line with the top boundary of the clip window as
p2’’.
Step 9: Discard the line sections from p2 to p2’ and p2’ to p2’’.
Program:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
int xa,xb,ya,yb;
int encode(float x,float y)
{
return(8*(x<xa)+4*(x>xb)+2*(y<ya)+(y>yb));
}
void swap(int *a,int *b)
23
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
{
int *t=a;
a=b;
b=t;
}
void lineclip(int x1,int y1,int x2,int y2)
{
float dx,dy;
int c1,c2;
c1=encode(x1,y1);
c2=encode(x2,y2);
while(c1|c2)
{
if(c1&c2)
return;
dx=x2-x1;
dy=y2-y1;
if(c1)
{
if(c1&8)
{
y1+=dy*(xa-x1)/dx;
x1=xa;
}
else if(c1&4)
{
y1+=dx*(xb-x1)/dx;
x1=xb;
}
else if(c1&2)
{
x1+=dx*(ya-y1)/dy;
y1=ya;
}
else if(c1&1)
{
x1+=dx*(yb-y1)/dy;
y1=yb;
}
c1=encode(x1,y1);
}
else
{
if(c2&8)
{
y2+=dy*(xa-x2)/dx;
x2=xa;
}
else if(c2&4)
24
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
{
y2+=dy*(xb-xa)/dx;
x2=xb;
}
else if(c2&2)
{
x2+=dx*(yb-y2)/dy;
y2=ya;
}
else if(c2&1)
{
x2+=dx*(yb-y2)/dy;
y2=yb;
}
c2=encode(x2,y2);
}
}
line(x1,y1,x2,y2);
}
void main()
{
int gd=DETECT,gm,x1,y1,x2,y2;
initgraph(&gd,&gm,"");
textbackground(0);
setbkcolor(1);
cout<<"\n\nCohen sutherland line clipping algorithm\n-------------------------------";
cout<<"\n\n\nEnter 4 values of clipping area::";
cin>>xa>>ya>>xb>>yb;
cout<<"\n\nEnter the first co-ordinate value::";
cin>>x1>>y1;
cout<<"\n\nEnter the second co-ordinate value::";
cin>>x2>>y2;
if(x1>x2)
swap(&x1,&x2);
if(y1>y2)
swap(&y1,&y2);
cleardevice();
setcolor(13);
outtextxy(50,50,"Before clipping");
rectangle(xa,ya,xb,yb);
line(x1,y1,x2,y2);
getch();
cleardevice();
outtextxy(50,50,"After clipping");
rectangle(xa,ya,xb,yb);
lineclip(x1,y1,x2,y2);
getch();
closegraph();
}
25
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to implement Cohen-Sutherland 2D Clipping is executed and the output is
verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
26
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Step 6: Choose the co-ordinates of a rectangle to be drawn inside the window and to be mapped onto
the viewport.
Step 7: Draw the rectangle inside the drawn window using its co-ordinates.
Sx= (xvmax-xvmin)/(xwmax-xwmin)
Sy=(yvmax-yvmin)/(ywmax-ywmin)
Step 9: To map a point at position (xw,yw) in the window into position (xv,yv) in the associated
viewport, maintain the same relative placement in the viewport as in the window using the
expressions
Step 10: Obtain the co-ordinates of the rectangle which is to be mapped in the window using the
above two expressions. Draw the relative rectangle in the viewport using the mapped co-ordinates.
Program:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
27
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
void main()
{
float xwmin,xwmax,ywmin,ywmax;
float xvmin,xvmax,yvmin,yvmax;
float x[10],y[10],yv,xv,sx,sy;
int gd=DETECT,gm,i;
clrscr();
printf("\n\n\t\tWindow to Viewport ");
printf("\n\nEnter window-port coordinates (xwmin,ywmin,xwmax,ywmax)::");
scanf("%f%f%f%f",&xwmin,&ywmin,&xwmax,&ywmax);
printf("\nEnter view-port coordinates(xvmin,yvmin,xvmax,yvmax)::");
scanf("%f%f%f%f",&xvmin,&yvmin,&xvmax,&yvmax);
printf("\nEnter the vertices for triangle:");
for(i=0;i<3;i++)
{
printf("\nEnter coordiante(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,"");
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]-xwmin)*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();
}
28
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to implement Window to View port Mapping is executed and the output is
verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
29
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date:
Aim:
Algorithm:
Step 3: Draw the polygon ie the 3D object and get the type of transformation to be performed.
y’= ycosθ-zsinθ
z’= ysinθ+zcosθ and x’=x.
z’= zcosθ-xsinθ
x’= zsinθ+xcosθ and y’=y.
30
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Program:
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
int i,j;
void tcube()
{
for(i=1;i<=10;i++)
{
cleardevice();
rectangle(50,100,400,300);
rectangle(200-(i*12),200,250-(i*12),250);
rectangle(225-(i*12),175,275-(i*12),225);
line(200-(i*12),200,225-(i*12),175);
line(250-(i*12),200,275-(i*12),175);
line(200-(i*12),250,225-(i*12),225);
line(250-(i*12),250,275-(i*12),225);
delay(400);
}
outtextxy(200,50,"*AFTER TRANSLATION*");
getch();
cleardevice();
}
void rcube()
{
for(i=1;i<=5;i++)
{
cleardevice();
rectangle(100,100,500,300);
rectangle(200+(i*5),200-(i*2),250-(i*5),250-(i*2));
rectangle(225+(i*5),175+(i*2),275-(i*5),225-(i*2));
line(200+(i*5),200-(i*2),225+(i*5),175+(i*2));
line(250-(i*5),200-(i*2),275-(i*5),175+(i*2));
line(200+(i*5),250-(i*2),225+(i*5),225+(i*2));
line(250-(i*5),250-(i*2),275-(i*5),225+(i*2));
}
j=2;
delay(200);
for(;i<=10;i++)
{
cleardevice();
rectangle(100,100,400,300);
rectangle(200+(i*5),200-(i*2),250-(i*5),250-(i*2));
rectangle(225+(i*5),175+(i*2),275-(i*5),225+(i*2));
line(200+((i-j)*5),200-(i*2),225+((i-j)*5),175+(i*2));
line(250-((i-j)*5),200-(i*2),275-((i-j)*5),175+(i*2));
line(200+((i-j)*5),250-(i*2),225+((i-j)*5),225+(i*2));
31
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
line(250-((i-j)*5),250-(i*2),275-((i-j)*5),225+(i*2));
delay(200);
j=j+2;
}
outtextxy(250,50,"*After Rotation*");
getch();
cleardevice();
}
void scube()
{
for(i=1;i<=10;i++)
{
cleardevice();
rectangle(100,80,500,300);
rectangle(200,200-(i*8),250+(i*8),250);
rectangle(225,175-(i*8),275+(i*8),225);
line(200,200-(i*8),225,175-(i*8));
line(250+(i*8),200-(i*8),275+(i*8),175-(i*8));
line(200,250,225,225);
line(250+(i*8),250,275+(i*8),225);
delay(200);
}
outtextxy(250,50,"*After scaling*");
getch();
cleardevice();
}
void main()
{
int gd=DETECT,gm,ch;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n\n\t\t 3D TRANSFORMATIONS\n\t\t*******************\n");
printf("\n\n\tMenu:");
printf("\n\n\t1.Translation\n\t2.Rotation\n\t3.Scaling\n\t4.Exit\n");
while(ch!=0)
{
printf("Enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
tcube();
break;
case 2:
rcube();
break;
case 3:
scube();
break;
case 4:
exit(0);
}
}
}
32
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to perform 3D Transformations such as translation, scaling, and rotation is
executed and the output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
33
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date:
Aim:
Algorithm:
Step 6: Enter the reference value about which the perspective projection is to be viewed.
Step 7: Calculate the projection points using the co-ordinates and the reference value.
Step 8: Display the perspective projection of the 3D image along the axis.
Program:
#include<conio.h>
#include<graphics.h>
#include<math.h>
int midx,midy,maxx,maxy;
void main()
{
int gd,gm,x,y,z;
clrscr();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\tc\\bgi");
setfillstyle(3,2);
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
34
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
bar3d(midx-250,midy+150,midx-150,midy+225,20,4);
printf("\n Enter the projection vector:\t");
scanf("%d%d%d",&x,&y,&z);
bar3d(midx-(x*5),midy-(y*9),midx-(x*3),midy-(y*5),10*z,4);
getch();
Closegraph ();
}
Output:
Result:
Thus the program to visualize the projections of 3D images is executed and the output is
verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
35
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
To write a C program to convert RGB Color model into HSV Color model.
Algorithm:
Program:
#include <stdio.h>
#include <conio.h>
float MIN(float a, float b)
{
return (a < b ? a : b);
}
36
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
37
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to convert RGB Color model into HSV Color model is executed and the output
is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
38
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
To write a C program to convert RGB Color model into HSV Color model.
Algorithm:
aa =v (1-s)
bb =v (1-sf)
cc =v (1-s (1-f))
• Based on the value of I, assign the values of R, G and B with aa, bb, and cc values.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void hsvtorgb(float h,float s,float v)
{
float *r,*g,*b;
int i;
float aa,bb,cc,f;
if(s==0)
{
*r=*g=*b=v;
printf("R=%f\tG=%f\tB=%f\n",*r,*g,*b);
}
else
{
if(h==1.0)
39
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
h=0;
h*=6.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;
printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
break;
case 1:
*r=bb;*g=v;*b=aa;
printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
break;
case 2:
*r=aa;*g=cc;*b=v;
printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
break;
case 3:
*r=aa;*g=bb;*b=v;
printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
break;
case 4:
*r=cc;*g=aa;*b=v;
printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
break;
case 5:
*r=v;*g=aa;*b=bb;
printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
break;
}
}
}
void main()
{
float a,b,c;
clrscr();
printf("\n Enter the HSV values:\n");
scanf("%f%f%f",&a,&b,&c);
printf("\nThe RGB values:\n");
hsvtorgb(a,b,c);
getch();
}
40
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to convert RGB Color model into HSV Color model is executed and the
output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
41
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
Algorithm:
Step 2: Open the source Text file to be compressed and the Destination file to store the compressed
version of the source.
Step 3: Read the characters from the source file one by one.
Step 4: Check for the redundancy of the same read character in the consecutive character stream till
different character is read.
Step 5: Write the character and the number of its consecutive occurrence in the destination file.
Step 6: Continue the process until the source reaches the end-of-File character.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],b[50],dl;
int i,j,flag=0,countindex=0,index=-1,count=0,size;
FILE *ip,*op;
clrscr();
printf("\n\n Enter the text for input:");
scanf("%s",a);
size=strlen(a);
ip=fopen("source","w");
fprintf(ip,"%s",a);
printf("\n Input file length:");
printf("%d",ftell(ip));
fclose(ip);
42
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
printf("\n");
ip=fopen("compress.dat","w");
for(i=0;i<size;i++)
{
j=i+1;
if(a[j]==a[i])
count=count+1;
else
{
if(count>0)
{
b[++index]=a[i];
fprintf(ip,"%c",b[index]);
b[++index]='#';
fprintf(ip,"%c",b[index]);
b[++index]=count+1;
fprintf(ip,"%c",b[index]);
count=0;
}
else
{
b[++index]=a[i];
fprintf(ip,"%c",b[index]);
}
countindex=index;
}
}
fclose(ip);
op=fopen("compress.dat","r+");
printf("\n\n Compressed output\n ");
for(i=0;i<size;i++)
{
fscanf(op,"%c",b[i]);
if(b[i]=='#')
{
flag=1;
printf("%c",b[i]);
continue;
}
else if(flag==1)
{
printf("%d",b[i]);
flag=0;
}
else
printf("%c",b[i]);
}
printf("\n Compressed file length:");
printf("%d",ftell(op));
43
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
fclose(op);
flag=0;
op=fopen("compress.dat","r+");
ip=fopen("decompress.dat","w");
printf("\n\n\n Decompressed output:\n ");
for(i=0;i<=countindex;i++)
{
fscanf(op,"%c",b[i]);
if(b[i]=='#')
{
flag=1;
continue;
}
else if(flag==1)
{
for(j=0;j<b[i]-1;j++)
{
fprintf(ip,"%c",dl);
printf("%c",dl);
}
flag=0;
}
else if(b[i]!='\0')
{
fprintf(ip,"%c",b[i]);
printf("%c",b[i]);
dl=b[i];
}
}
printf("\n Decompressed Length:");
printf("%d",ftell(ip));
fcloseall();
getch();
}
44
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
Result:
Thus the program to compress a Text file using Text Compression Algorithm is executed and
the output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
45
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date:
Aim:
Procedure:
• Draw any object in the workspace and fix its critical place.
• The frames on the timeline are copied from the initial frame up to the frame by the right
clicking of mouse and choosing copy frames.
• The object is moved to its target position from its initial position as soon as the final frame
are being copied in the timeline.
• The object is provided with a motion or any movements anywhere the motion tween is
created for that object, so right click the mouse and choose create motion tween in the last
but one frame.
• This creates the arrow head that notifies the duration of animation frame. The first frame
position to the last frames position.
• Then press cntrl+Enter keys or select text scene from control menu to view the animation.
46
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
47
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Result:
Thus the procedure to represent motion tween using Macromedia Flash is executed and the
output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
48
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Ex. No: 7(b) IMAGE EDITING AND MANIPULATION USING ADOBE PHOTOSHOP
Date :
Aim:
Procedure:
1. Start ->Photoshop and open the image from the drive and try out the different tools.
1. Rotate
Image – Image Rotation – try out the different options.
2. 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.
3. 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.
4. 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).
5. 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.
7. 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 color
a. Select in the menu Image – Adjustments – Replace Color.
b. Mark the button Image under the motif.
49
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
c. With the pipette (Eyedropper Tool) collect the most dominant color of the image.
d. Under the headline Replace, select a substitute color, by dragging the sliding bar in Hue,
Saturation and Lightness.
e. Then select (pipette with a +) and select the additional color shades and click OK.
Text on Images
Procedure:
1. Open Adobe Photoshop
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, download, speed, 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.
Output:
51
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
52
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
53
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
54
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
55
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
56
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
57
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Result:
Thus the program to implement and create 3D object and scene using OpenGL is executed and
the output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
58
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date:
Aim:
Procedure:
Masking:
• Select the oval tool from the tool bar and draw a ball of any color.
• Select the destination frame in the frame in the layer and right click on it and give insert key
frame. Then right click and select Create motion Tween in order to enable the motion of the ball.
• In the same destination frame, move the ball to the desired location.
• Right click on Timeline and insert a new layer.
• Add some text in the new layer and select Mask by right clicking it.
• Check that layer 2 has text and layer 1 has the ball.
• Select layer1 and then press Enter or select play from Control.
Output:
59
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Pendulum:
• Select the oval tool from the tool bar to draw a circle.
• Draw a straight line using the line tool from the tool bar.
• Select both circle and line and then set the center point at the top of the line.
• Using transformation set the motion of the
• Select insert key frame at the destination frame and then select Create Motion tween.
pendulum.
• Press Enter or Select play from control.
Output:
Result:
Thus the Masking, Pendulum operations using macromedia flash is executed and the output is
verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
60
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Date :
Aim:
To develop programs for making simple animations using transformations like rotation, sealing and
translation. The simple animations are given below:
Steps:
i. For moving any object, we incrementally calculate the object coordinates and redraw the i. picture
to give a feel of animation by using for loop.
ii. Suppose if we want to move a circle from left to right means, we have to shift the position of
circle along x- direction continuously in regular intervals.
iii. The below programs illustrate the movement of objects by using for loop and also using
transformations like rotation, translation etc.
iv. For windmill rotation, we use 2D rotation concept and formulas.
#include <graphics.h
#include <dos.h>
#include <conio.h>
main()
int i,j 0, gd DETECT, gm;
initgraph(&gd&gm, "C:\TURBOC3 BGI");
settextstyle(DEFAULT FONT HORIZ DIR,2);
outtextxy(25,240,"Press any key to view the moving car");
getch();
setviewport(0,0,639,440,1);
for(i=0;i< 420;i=i+10, j++)
rectangle(50+1,275,150+1,400);
rectangle(150+1,350,200+ 1.400);
circle(75 +1,410,10); circle(175+1,410,10);
setcolor(j);
delay(100);
if(i 420)
break;
clearviewport();
getch();
cleardevice();
outtextxy(100,200,"Project by http://www.turboc.codeplex.com"):
delay(5000);
closegraph():
return 0;
61
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Output:
62
Department of Computer Science and Engineering 18PD14 Computer Graphics and Multimedia Laboratory
Result:
Thus the program to develop programs for making simple animations using transformations
like rotation, sealing and translation is executed and the output is verified.
PREPARATION 30
LAB PERFORMANCE 30
REPORT 40
TOTAL 100
63