Computer Graphics & Multimedia lab
Computer Graphics & Multimedia lab
Computer Graphics & Multimedia lab
PREPARED BY
Dr.S.Chakaravarthi
SCHOOL OF COMPUTING
1|Page
LAB MANUAL
SUBJECT NAME:
COMPUTER GRAPHICS AND MULTIMEDIA
LABORATORY
Regualtion 2015
(2015-2016)
2|Page
BCS4L3 COMPUTER GRAPHICS AND MULTIMEDIA L T P C
LABORATORY
Total Contact Hours - 30 0 0 3 2
Prerequisite –Multimedia Systems.
Lab Manual Designed by – Dept. of Computer Science and Engineering
OBJECTIVES The main objective is students gain knowledge about multimedia concepts, 2D and
3D Transformations.
COURSE OUTCOMES (COs)
CO1 Explain line drawing using programming language.
CO2 Explain 2D and 3D transformations
CO3 Demonstrate simple 2D animations using animation software.
CO4 Prepare simple scenes using image editing software.
CO5 Explain the linking between web and multimedia.
CO6 Model a simple multimedia application.
MAPPING BETWEEN COURSE OUTCOMES & PROGRAM OUTCOMES
(3/2/1 INDICATES STRENGTH OF CORRELATION) 3- High, 2- Medium, 1-Low
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 3 3 3 3 3 3
CO2 3 2 3 3 3
CO3 3 2 2 3 3
CO4 2 3 3 3 3 3
CO5 3 2 2 3 3
CO6 3 2 3 3 3 3
Category Professional Core (PC)
Approval 37th Meeting of Academic Council, May 2015
3|Page
BCS6L3- COMPUTER GRAPHICS AND MULTIMEDIA LABORATORY
LIST OF EXPERIMENTS
4|Page
CONTENT
3(c) Operators 27
Motion Tweening 41
7(a)
7(d) Masking 45
5|Page
1 (A)- BRESENHAM’S LINE DRAWING ALGORITHM
AIM:
To draw a line using Bresenham’s algorithm
ALGORITHM:
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x1,x2,y1,y2,gd=DETECT,gm,dx,dy,step;
int x,y,const1,const2,k,p,x_end;
initgraph(&gd,&gm,"");
printf("\nEnter the end point co-ordinates of the line.......\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
p=2*dy-dx;
const1=2*dy;
const2=2*(dy-dx);
if(x1>x2)
{
x=x2;
y=y2;
x_end=x1;
}
else
{
x=x1;
y=y1;
x_end=x2;
}
putpixel(x,y,15);
6|Page
while(x<x_end)
{
x++;
if(p<0)
p+=const1;
else
{
y++;
p+=const2;
}
putpixel(x,y,15);
}
getch();
closegraph();
}
INPUT:
OUTPUT:
RESULT:
Thus the program to draw a line using Bresenham’s algorithm was executed.
7|Page
1(B)- BRESENHAM’S CIRCLE ALGORITHMS
AIM:
To draw a circle using Bresenham’s circle algorithm
ALGORITHM:
1. Read the center and radius of the circle.
2. Shift the centre to origin ,consider the points on y-axis at a distance of radius
3. Plot the pixel at the centre of circle
4. While x – coordinates is less than the radius ,do the following
a. Increment x by one and calculate y- co ordinate
b. Shift the coordinate to original position
c. Plot the pixel
5. Display the circle.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
void plotpoint(int,int,int,int);
int xc,yc,r,x,y,p;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm," ");
printf("Enter the center co-ordinates of the circle:\n");
scanf("%d%d",&xc,&yc);
printf("Enter the radius of the circle:\n");
scanf("%d",&r);
x=0; y=r;
plotpoint(xc,yc,x,y);
p=1-r;
while(x<y)
{
if(p<0)
x=x+1;
else
{
x=x+1;
y=y-1;
}
if(p<0)
8|Page
p=p+2*x+1;
else
p=p+2*(x-y)+1;
plotpoint(xc,yc,x,y);
}
getch();
}
void plotpoint(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
}
INPUT:
Enter the center co-ordinates of the circle:
200
200
Enter the radius of the circle:
50
OUTPUT:
RESULT :
Thus the program to draw a circle using Bresenham’s algorithm was executed.
9|Page
1 (C)- BRESENHAM’S ELLIPSE ALGORITHMS
AIM:
To draw an ellipse using Bresenham’s algorithm
ALGORITHM:
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define ROUND(a) ((int)(a+0.5))
void plotpoint(long int,long int,long int,long int);
void main()
{
long int xc,yc,rx,ry,rx2,ry2,x,y,px,p,tworx2,twory2,py;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("Enter the center co-ordinates of the ellipse:\n");
scanf("%ld %ld ",&xc,&yc);
printf("Enter the radius along x-axis and y-axis:\n");
scanf("%ld %ld",&rx,&ry);
x=0;
y=ry;
px=0;
rx2=rx*rx;
ry2=ry*ry;
tworx2=2*rx2;
twory2=2*ry2;
py=tworx2*y;
plotpoint(xc,yc,x,y);
p=ROUND(ry2-(rx2*ry)+(.25*rx2));
10 | P a g e
while(px<py)
{
x++;
px+=twory2;
if(p<0)
{
p+=ry2+px;
}
else
{
y--;
py-=tworx2;
p+=ry2+px-py;
}
plotpoint(xc,yc,x,y);
}
p=ROUND(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2);
while(y>0)
{
y--;
py-=tworx2;
if(p>0)
p+=rx2-py;
else
{
x++;
px+=twory2;
p+=rx2-py+px;
}
plotpoint(xc,yc,x,y);
}
getch();
}
INPUT:
OUTPUT:
RESULT:
Thus the program to draw an ellipse using Bresenham’s algorithm was executed.
12 | P a g e
TWO DIMENSIONAL TRANSFORMATION
AIM :
To implement the various 2D transformations like translation, scaling, rotation, shearing and
reflection.
ALGORITHM:
To draw polygon
1. Read the number of vertices.
2. Read the x & y coordinates of the vertices and store it in an array.
3. Draw the polygon using drawpoly().
Translation
It is applied to an object by repositioning it along a straight line path from
one coordinate to another.
1. Read the translation distance tx & ty
2. Add tx & ty to the coordinates to move to the new position
3. Display the polygon
Scaling
It alters the size of an object, by multiplying the coordinate values of
each vertex by scaling factors.
1. Read the scaling factor sx
2. Multiply the scaling sx with each coordinate vertex to alter the size.
3. Display the polygon.
Rotation
It is applied to an object by repositioning it along a circular path in the xy plane
1. Read the rotation factor or pivot point (a) and distance (xr, yr) from origin.
2. Polygon is rotated by displacing each vertex through the specified rotation angle (a)
3. Display the polygon.
Reflection
A reflection is a transformation that produces a mirror image of an object.
1. Reflection of an object is produced by displacing the object along x axis & y axis being the
same.
2. Display the polygon.
Shearing
A transformation that distorts the shape of an object
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int i,poly4[10],poly1[10],poly2[10],poly3[10],tx,ty,sx,n,xr,yr,a;
int poly[10],poly5[10],sy;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("\nEnter the number of vertices of the polygon:\n");
scanf("%d",&n);
printf("Enter the(x,y) co-ordinates of the vertices:\n");
for(i=0;i<2*n;i++)
{
scanf("%d",&poly[i]);
}
poly[2*n]=poly[0];
poly[2*n+1]=poly[1];
outtextxy(70,70,"Original image");
drawpoly(n+1,poly);
//TRANSLATION
getch();
cleardevice();
outtextxy(30,30,"OriginalImage");
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the Translation Factor");
gotoxy(30,3);
scanf("%d %d",&tx,&ty);
for(i=0;i<2*n;i+=2)
{
poly1[i]=poly[i]+tx;
poly1[i+1]=poly[i+1]+ty;
}
poly1[2*n]=poly1[0];
poly1[2*n+1]=poly1[1];
drawpoly(n+1,poly1);
getch();
cleardevice();
//SCALING
outtextxy(30,30,"Original Image");
14 | P a g e
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the Scaling Factor");
gotoxy(30,3);
scanf("%d",&sx);
for(i=0;i<2*n;i+=2)
{
poly2[i]=poly[i]*sx;
poly2[i+1]=poly[i+1]*sx;
}
poly2[2*n]=poly2[0];
poly2[2*n+1]=poly2[1];
drawpoly(n+1,poly2);
getch();
cleardevice();
//ROTATION
outtextxy(30,30,"Original Image");
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the Rotation Factor");
gotoxy(30,3);
scanf("%d%d%d",&xr,&yr,&a);
for(i=0;i<2*n;i+=2)
{
poly3[i]=xr+((poly[i]-xr)*cos(a))-((poly[i+1]-yr)*sin(a));
poly3[i+1]=yr+((poly[i+1]-yr)*cos(a))+((poly[i]-xr)*sin(a));
}
poly3[2*n]=poly3[0];
poly3[2*n+1]=poly3[1];
drawpoly(n+1,poly3);
getch();
cleardevice();
//REFLECTION
outtextxy(30,30,"Original Image");
drawpoly(n+1,poly);
outtextxy(10,10,"Reflected Image");
for(i=0;i<2*n;i+=2)
{
poly4[i]=640-poly[i];
poly4[i+1]=poly[i+1];
}
poly4[2*n]=poly4[0];
poly4[2*n+1]=poly4[1];
drawpoly(n+1,poly4);
getch();
cleardevice();
//SHEARING
outtextxy(30,30,"Original Image");
15 | P a g e
drawpoly(n+1,poly);
outtextxy(10,10,"Enter the shear factor");
gotoxy(30,3);
scanf("%d",&sh);
for(i=0;i<2*n;i+=2)
{
poly5[i]=poly[i]+sh*poly[i+1];
poly5[i+1]=poly[i+1];
}
poly5[2*n]=poly5[0];
poly5[2*n+1]=poly5[1];
drawpoly(n+1,poly5);
getch();
cleardevice();
}
Input:
Output
Original image
Translation
Input:
Output
Original image
16 | P a g e
Scaling
Input:
Output
Original image
17 | P a g e
Rotation
Input:
Output
Original image
Reflection
Output
Original image
Shearing
Input:
Output
Original image
RESULT:
Thus the program to implement various 2D transformations like translation, scaling, rotation,
reflection & shearing was executed.
18 | P a g e
3 (A)- LINE CLIPPING
AIM:
To write a program to clip the line using Cohen Sutherland algorithm.
ALGORITHM:
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
/* Defining structure for end point of line */
typedef struct coordinate
{
int x,y;
char code[4];
}pt;
void drawwindow();
void drawline(pt p1,pt p2,int c1);
pt setcode(pt p);
int visibility(pt p1,pt p2);
pt resetendpt(pt p1,pt p2);
main()
{
int gd=DETECT,gm,v;
pt p1,p2,ptemp;
initgraph(&gd,&gm,"");
cleardevice();
printf("\n\n\tEnter End point 1 (x,y): ");
scanf("%d %d",&p1.x,&p1.y);
printf("\n\n\tEnter End point 2 (x,y):");
scanf("%d %d",&p2.x,&p2.y);
19 | P a g e
cleardevice();
drawwindow();
getch();
drawline(p1,p2,15);
getch();
p1=setcode(p1);
p2=setcode(p2);
v=visibility(p1,p2);
switch(v)
{
case 0:cleardevice();
drawwindow();
drawline(p1,p2,15);
break;
case 1: cleardevice();
drawwindow();
break;
case 2: cleardevice();
p1=resetendpt(p1,p2);
p2=resetendpt(p2,p1);
drawwindow();
drawline(p1,p2,15);
break;
}
getch();
closegraph();
return(0);
}
20 | P a g e
pt ptemp;
if(p.y<100)
ptemp.code[0]='1'; //top
else
ptemp.code[0]='0';
if(p.y>350)
ptemp.code[1]='1'; //bottom
else
ptemp.code[1]='0';
if(p.x>450)
ptemp.code[2]='1'; //right
else
ptemp.code[2]='0';
if(p.x<150)
ptemp.code[3]='1'; //left
else
ptemp.code[3]='0';
ptemp.x = p.x;
ptemp.y=p.y;
return(ptemp);
}
if(flag==0)
return(1);
return(2);
}
21 | P a g e
/*function to find new end points*/
pt resetendpt(pt p1,pt p2)
{
pt temp;
int x,y,i;
float m,k;
if(p1.code[3]=='1')
x=150;
if(p1.code[2]=='1')
x=450;
if((p1.code[3]=='1')||(p1.code[2]=='1'))
{
m=(float)((p2.y-p1.y)/(p2.x-p1.x));
k=(p1.y+(m*(x-p1.x)));
temp.y=k;
temp.x=x;
for(i=0;i<4;i++)
temp.code[i]=p1.code[i];
if(temp.y<=350 && temp.y >=100)
return(temp);
}
22 | P a g e
OUTPUT
RESULT:
Thus the program to clip the line using Cohen Sutherland algorithm was executed.
23 | P a g e
3(B)- POLYGON CLIPPING
AIM:
To write a program to clip the polygon using Cohen Sutherland algorithm.
ALGORITHM:
1. Read the coordinates of clipping window.
2. Draw the clipping window.
3. Read the number of polygon vertices & draw the polygon
4. Check the polygon vertices against clipping boundaries in the order left, right, bottom & top.
5. Find the intersection point of the polygon with the boundary of clipping rectangle.
6. Discard the polygon vertices which are outside the window after saving the intersection points.
7. Display the polygon inside the clipping window.
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
enum area{left,right,top,bottom};
typedef struct
{
double x,y;
} points;
points outvertex[10];
points vertex[10];
int max=0;
int n;
enum area id;
void sutherclip(int,int,int,int);
points intersect(int,points,points);
int inside(int,points);
switch(id)
{
case left:
case right:
temp.x=clipbound;
temp.y=s.y+(p.y-s.y)*(clipbound-s.x)/(p.x-s.x);
break;
case bottom:
case top:
temp.y=clipbound;
temp.x=s.x+(p.x-s.x)*(clipbound-s.y)/(p.y-s.y);
break;
}
return temp;
}
25 | P a g e
p=vertex[i+1];
pt1=inside(xmin,s);
pt2=inside(xmin,p);
for(i=0;i<max;i++)
vertex[i]=outvertex[i];
max=0;
}
26 | P a g e
{
line(outvertex[i].x,outvertex[i].y,outvertex[i+1].x,outvertex[i+1].y);
line(outvertex[n-1].x,outvertex[n-1].y,outvertex[0].x,outvertex[0].y);
}
getch();
closegraph();
INPUT:
Enter the co ordinates of clipping window
100 100 300 300
Enter the no of vertices of the polygon…..
3
Enter the x & y co ordinates of vertex 1
75 150
Enter the x & y co ordinates of vertex 2
150 150
Enter the x & y co ordinates of vertex 3
100 200
Output:
Before Clipping
After Clipping
RESULT:
Thus the program to clip the polygon using Cohen Sutherland algorithm was executed.
27 | P a g e
3 (C)- WINDOW-VIEWPORT MAPPINGAIM:
AIM:
To write a program to perform window – view port mapping.
ALGORITHM:
1. Read the window & view port co-ordinates.
2. Read the number of polygon vertices
3. Draw the filled polygon inside the window.
4. Draw the view port
5. Map the polygon which is in the window to the view port.
6. Display the polygon inside the view port.
SOURCE CODE :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int x[10],y[10],pol[25],ny,xymin,xymax,ywmax,ywmin,yymax,yymin,xwmax,xwmin;
void viewport()
{
float sx,sy;
int i,j,k;
sx=(float)((float)(xymax-xymin)/(float)(xwmax-xwmin));
sy=(float)((float)(yymax-yymin)/(float)(ywmax-ywmin));
for(i=0;i<3;i++)
{
x[i]=sx*(x[i]-xwmin)+xymin;
y[i]=sy*(y[i]-ywmin)+yymin;
}
k=0;
for(i=0;i<ny;i++)
{
pol[k]=x[i];
pol[k+1]=y[i];
k+=2;
}
}
void main()
{
int i,j,d=DETECT,m=DETECT;
clrscr();
printf("Enter the window co ordinates:");
28 | P a g e
scanf("%d%d%d%d",&xwmin,&ywmin,&xwmax,&ywmax);
printf("Enter the view port co ordinates:");
scanf("%d%d%d%d",&xymin,&yymin,&xymax,&yymax);
printf("Enter the number of vertices");
scanf("%d",&ny);
printf("Enter the %d values",ny*2);
for(i=0;i<ny;i++)
scanf("%d%d",&x[i],&y[i]);
j=0;
for(i=0;i<ny;i++)
{
pol[j]=x[i];
pol[j+1]=y[i];
j+=2;
}
initgraph(&d,&m,"");
settextstyle(3,0,3);
outtextxy(xwmin,ywmin-35,"Window");
rectangle(xwmin,ywmin,xwmax,ywmax);
setfillstyle(8,getmaxcolor());
fillpoly(ny,pol);
moveto(x[0],y[0]);
lineto(x[0],y[0]);
getch();
viewport();
outtextxy(xymin,yymin-35,"Viewport");
rectangle(xymin,yymin,xymax,yymax);
setfillstyle(8,getmaxcolor());
fillpoly(ny,pol);
moveto(x[0],y[0]);
lineto(x[0],y[0]);
getch();
closegraph();
}
Input:
Enter the window co ordinates:
120 50 350 140
Enter the view port co ordinates:
400 150 500 170
Enter the number of vertices
3
Enter the 6 values: 250 80 200 100 300 100
29 | P a g e
Output:
WINDOW
VIEWPORT
RESULT:
30 | P a g e
4. THREE DIMENSIONAL TRANSFORMATION
AIM:
To implement the various 3D transformations like translation, scaling and
rotation.
.
ALGORITHM:
To draw polygon
1. Read the number of vertices.
2. Read the x & y coordinates of the vertices and store it in an array.
3. Draw the polygon using drawpoly().
Translation
It is applied to an object by repositioning it along a straight line path from
one coordinate to another.
1. Read the translation distance tx & ty
2. Add tx & ty to the coordinates to move to the new position
3. Display the polygon
Scaling
It alters the size of an object, by multiplying the coordinate values of
each vertex by scaling factors.
1. Read the scaling factor sx
2. Multiply the scaling sx with each coordinate vertex to alter the size.
3. Display the polygon.
Rotation
It is applied to an object by repositioning it along a circular path in the xy
plane.
1. Read the rotation factor or pivot point (a) and distance (xr, yr) from origin.
2. Polygon is rotated by displacing each vertex through the specified rotation angle (a).
3. Display the polygon.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
31 | P a g e
int n,poly[20],poly1[20],poly2[10],sx,poly3[10];
int tx,ty,xr,yr,a,sy,poly4[10],poly5[10],poly6[10],poly7[10];
int i;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
//TRANSLATION
outtextxy(30,30,"ORIGINAL IMAGE");
drawpoly(n+1,poly);
drawpoly(n+1,poly1);
for(i=0;i<2*n;i+=2)
line(poly[i],poly[i+1],poly1[i],poly1[i+1]);
getch();
outtextxy(10,10,"Enter the Translation factor:");
gotoxy(30,3);
scanf("%d%d",&tx,&ty);
for(i=0;i<2*n;i+=2)
{
poly2[i]=poly[i]+tx;
poly2[i+1]=poly[i+1]+ty;
poly3[i]=poly1[i]+tx;
poly3[i+1]=poly1[i+1]+ty;
}
32 | P a g e
poly2[2*n]=poly2[0];
poly2[2*n+1]=poly2[1];
poly3[2*n]=poly3[0];
poly3[2*n+1]=poly3[1];
drawpoly(n+1,poly2);
drawpoly(n+1,poly3);
for(i=0;i<2*n;i+=2)
line(poly2[i],poly2[i+1],poly3[i],poly3[i+1]);
getch();
cleardevice();
//SCALING
//ROTATION
printf("\n\n\t original image!");
drawpoly(n+1,poly);
drawpoly(n+1,poly1);
for(i=0;i<2*n;i+=2)
line(poly[i],poly[i+1],poly1[i],poly1[i+1]);
getch();
outtextxy(10,10,"Enter the rotation factor");
33 | P a g e
gotoxy(30,3);
scanf("%d%d%d",&xr,&yr,&a);
for(i=0;i<2*n;i+=2)
{
poly6[i]=xr+((poly[i]-xr)*cos(a))-((poly[i+1]-yr)*sin(a))+70;
poly6[i+1]=yr+((poly[i+1]-yr)*cos(a))+((poly[i]-xr)*sin(a))+70;
poly7[i]=xr+((poly[i]-xr)*cos(a))-((poly1[i+1]-yr)*sin(a))+70;
poly7[i+1]=yr+((poly[i+1]-yr)*cos(a))+((poly1[i]-xr)*sin(a))+70;
}
poly6[2*n]=poly6[0];
poly6[2*n+1]=poly6[1];
poly7[2*n]=poly7[0];
poly7[2*n+1]=poly7[1];
drawpoly(n+1,poly6);
drawpoly(n+1,poly7);
for(i=0;i<2*n;i+=2)
line(poly6[i],poly6[i+1],poly7[i],poly7[i+1]);
getch();
cleardevice();
}
Input:
Output
Original image
Translation
Input:
34 | P a g e
Output
Original image
Scaling
Input:
Output
Original image
Rotation
Input:
Output
Original image
35 | P a g e
RESULT:
Thus the program to implement various 3D transformations like translation, scaling & rotation was
executed.
36 | P a g e
5. VISUALIZE THE PROJECTION OF 3D IMAGES.
AIM:
To write a program to visualize the projection of 3D images.
ALGORITHM:
SOURCE CODE:
#include<graphics.h>
void top()
{
moveto(100,200);
outtext("TOP VIEW");
line(400,200,440,150);
line(400,200,300,150);
line(300,150,340,100);
line(340,100,440,150);
}
void side()
{
moveto(100,200);
outtext("SIDE VIEW");
rectangle(500,100,600,200);
}
void main()
{
int x =DETECT,y,i,mx,my,wid=40;
initgraph(&x,&y,"");
mx=100;
my=100;
setfillstyle(USER_FILL,3);
moveto(100,250);
outtext("3D IMAGE");
37 | P a g e
bar3d(mx,my,mx+100,my+100,wid,1);
getch();
cleardevice();
top();
getch();
cleardevice();
side();
getch();
cleardevice();
front(wid);
getch();
cleardevice();
bar3d(mx,my,mx+100,my+100,wid,1);
line(400,200,440,150);
line(400,200,300,150);
line(300,150,340,100);
line(340,100,440,150);
rectangle(500,100,600,200);
rectangle(400,250,400+wid,350);
rectangle(300,250,400,350);
getch();
closegraph();
}
Output:
RESULT:
Thus the program to visualize the projection of 3D images was executed.
38 | P a g e
6. CONVERSIONS BETWEEN COLOR MODELS
AIM:
To write the program to convert HSV color to RGB color model and vice versa.
ALGORITHM:
HSV to RGB
1. Read the H, S, V values in the range 0 to 1.
2. If the value of s is 0 then it is gray scale and the R, G, B becomes the value of V.
3. If the value of h is 1.0 then assign h=0 else h=h*6.0 and perform the following
i= floor(h); f=h-i;
aa=v*(1-s); bb=v*(1-s*f); cc=v*(1-s*(1f)));
4. Based on the i value assign v,aa,bb,cc to RGB and display the RGB values.
RGB to HSV
1. Read the R, G, B values.
2. Find the min,max value among the RGB values
3. Assign the maximum value to V.
4. S value is calculated by (max-min)/max.
5. H value is calculated by comparing R, G, and B values to max value.
6. Display the H, S and V values.
SOURCE CODE:
Output:
The R, G, B values:
#include<math.h>
#include<stdio.h>
#include<conio.h>
#define MAX(a,b)(a>b?a:b)
#define MIN(a,b)(a<b?a:b)
void rgbtohsv(float r,float g,float b,float *h,float *s,float *v)
{
float max = MAX(r,MAX(g,b));
float min = MIN(r,MIN(g,b));
float delta=max-min;
*v=max;
if(max!=0.0)
{
*s=delta/max;
if(r==max)
*h=(g-b)/delta;
else if(g==max)
*h=2+(b-r)/delta;
else if(b==max)
*h=4+(b-r)/delta;
*h*=60.0;
if(*h<0)
40 | P a g e
*h+=360.0;
*h/=360.0;
}
}
void main()
{
float r,g,b,h=0,s=0,v=0;
clrscr();
printf("Enter the value of R,G,B\n:");
scanf("%f%f%f",&r,&g,&b);
rgbtohsv(r,g,b,&h,&s,&v);
printf("H=%f , S=%f ,V=%f",h,s,v);
getch();
}
Input:
The H, S, V values:
RESULT:
Thus the program to convert HSV color to RGB color models and vice versa was executed.
41 | P a g e
7(A)-MOTION TWEENING
AIM:
To create motion tweening of an object.
ALGORITHM:
1. Select the layer and place the ball by drawing with the help of tools.
2. Select the frames by pressing F6 or right click and select insert frame.
3. Click the layer and right click & create motion tween.
4. Move the ball in the screen to the required destination point.
5. Press ctrl + Enter
6. Enter to show it in full screen
RESULT:
Thus the motion tweening of an object has been implemented and the output was verified.
42 | P a g e
7(B)-SHAPE TWEENING – OBJECT AND TEXT
AIM:
To create shape tweening of an object and text.
ALGORITHM:
Object:
1. Select the layer and place a ball.
2. Select the frame by pressing F6 (or) right click the mouse and select insert frame.
3. In the same layer, create another object say rectangle.
4. click the layer and in properties change the tween to shape.
5. Press ctrl+Enter to show it in full screen.
Text:
1. Select the text from the tool box and place it
2. Press ctrl twice a time.
3. Select the frame by pressing F6 or right click the mouse and select insert frame.
4. Select the layer and in properties change the tween as shape.
5. Press ctrl+enter to show it in full screen.
43 | P a g e
Shape tweening of text :
RESULT:
Thus the shape tweening-text and object has been implemented and the output was verified.
44 | P a g e
7(C)-GUIDE LAYER
AIM:
To create an animation using guide Layer.
ALGORITHM:
OUTPUT:
RESULT:
Thus the guide layer has been implemented and the output was verified.
45 | P a g e
7(D )-MASKING
AIM:
To implement masking concept
ALGORITHM:
OUTPUT:
RESULT:
Thus the masking has been implemented and the output was verified.
46 | P a g e
8. WORKING WITH TOOL
AIM:
To use various image painting tools in photoshop
ALGORITHM:
47 | P a g e