Professional Documents
Culture Documents
January-May 2012
CS1360-GRAPHICS AND MULTIMEDIA
LABORATORY
VI Semester
BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE AND ENGINEERING
Ex.No
Date
Name Of Experiment
1
(a)
1
(b)
1
(c)
.
Two Dimensional
Transformation Using C programming
Two Dimensional
Reflection Using C programming
.
7
10
Frame By Frame
Animation Using Flash
11
Motion Tweening
Using Flash
.
12
Shape Tweening
Using Flash
13
Study Of Tools
x+=1;
if(p<0)
p=p+2*dy;
else
y+=1,p=p+2*(dy-dx);
putpixel(x,y,7);
}
getch();
closegraph();
int p,x1,y1,r;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode," ");
clearviewport();
printf("\n\n\tCIRCLE ALGORITHM");
printf("\n\t\t*****************\n");
printf("\n\tEnter x co-ordinates:");
scanf("%d",&x1);
printf("\n\tEnter y co-ordinates:");
scanf("%d",&y1);
printf("\n\tEnter R-radius:");
scanf("%d",&r);
x=0;
y=r;
plotpoints(x1,y1);
p=1-r;
while(x<y)
{ if(p<0)
x++;
else
{
x++;
y--;
}
if(p<0)
p+=2*x+1;
else
p+=2*(x-y)+1;
plotpoints(x1,y1);
} getch();
}
void plotpoints(int x1,int y1)
{
putpixel(x1+x,y1+y,2);
putpixel(x1-x,y1+y,2);
putpixel(x1+x,y1-y,2);
putpixel(x1-x,y1-y,2);
putpixel(x1+y,y1+x,2);
putpixel(x1-y,y1+x,2);
putpixel(x1+y,y1-x,2);
putpixel(x1-y,y1-x,2);
delay(30);
}
t=3.141/180;
d=i*t;
x=x1+ceil(r1*sin(d));
y=y1+ceil(r2*cos(d));
delay(20);
putpixel(x,y,15);
} getch();
closegraph();
}
box(x1,y1,x2,y2);
printf("Enter the rotating angle");
scanf("%d",&theta);
m=(pi/180)*theta;
n=0.01;
do
cleardevice();
setcolor(5);
box(x1,y1,x2,y2);
x=x1,y=y2,a=x2,b=y2,c=x2,d=y1,e=x1,f=y1;
a=x+floor(x2-x1)*cos(n);
b=y+floor(y2-y1)*sin(n);
c=x+floor(x2-x1)*sqrt(2)*cos(n-(pi/4));
d=y+floor(y2-y1)*sqrt(2)*sin(n-(pi/4));
e=x+floor(x2-x1)*cos(n-(pi/2));
f=y+floor(y2-y1)*sin(n-(pi/2));
setcolor(35);
line(x1,y2,a,b);
line(a,b,c,d);
line(c,d,e,f);
line(e,f,x1,y2);
n+=0.01;
delay(50);
while(n<m);
getch();
goto p;
break;
case 3:
cleardevice();
setcolor(5);
box(x1,y1,x2,y2);
printf("Enter the scaling factor");
scanf("%f%f",&sx,&sy);
cleardevice();
setcolor(5);
box(x1,y1,x2,y2);
x3=(x2-x1)*(sx)+x1;
y3=(y2-y1)*(sy)+y1;
setcolor(35);
box(x1,y1,x3,y3);
getch();
goto p;
break;
default:
break; }
printf("Do u want to continue");
scanf("%s",&cho);
while(cho=='y' || cho=='y');
}
closegraph();
OUTPUT OF 2D TRANSFORMATION
Enter the value of x1,y1: 120 200
Enter the value of x2,y2: 300 250
1.Translation
2.Rotation
3.Scaling
4.Exit
Enter your choice:1
Enter the hori. and veri translation
1.Translation
2.Rotation
3.Scaling
4.Exit
Enter your choice:2
Enter the rotating angle 180
1.Translation
2.Rotation
3.Scaling
4.Exit
Enter your choice:3
Enter the scaling factor 2 4
1.Translation
2.Rotation
3.Scaling
4.Exit
Enter your choice:4
int x1,y1,x2,y2,x3,y3,gd=DETECT,gm,k;
initgraph(&gd,&gm," ");
printf("\n\t Enter the co-ordinates");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
Loop:
cleardevice();
printf("\n Main menu");
printf("\n 1.Creation of triangle");
printf("\n 2.X-axis reflection");
printf("\n 3.Y-axis reflection");
printf("\n 4.Exit");
printf("\n Enter ur choice");
scanf("%d",&k);
switch(k)
{
case 1:
triangle(x1,y1,x2,y2,x3,y3);
getch();
goto loop;
case 2:
line(0,200,630,200);
triangle(x1,y1,x2,y2,x3,y3);
getch();
triangle(x1,(200-y1)*2+y1,x2,(200-y2)*2+y2,x3,(200-y3)*2+y3);
getch();
goto loop;
case 3:
line(300,0,300,475);
triangle(x1,y1,x2,y2,x3,y3);
getch();
triangle((300-x1)*2+x1,y1,(300-x2)*2+x2,y2,(300-x3)*2+x3,y3);
getch();
goto loop;
case 4:
break;
}
}
(300100)
(200200)
Main menu
1.Creation of triangle
(300200)
2.x-axis reflection
3.y-axis reflection
4.Exit
Enter your choice 2
(300100)
(200200)
(300300)
Main menu
1.Creation of triangle
2.x-axis reflection
3.y-axis reflection
(300200)
4.Exit
Enter your choice 3
(300100)
(200200)
int gd=DETECT,gm;
int i,j,sh,n,x[50],y[50],sx[50],sy[50];
initgraph(&gd,&gm," ");
cleardevice();
(400200)
for(i=0;i<4;i++)
for(i=0;i<3;i++)
line(x[i],y[i],x[i+1],y[i+1]);
line(x[i],y[i],x[0],y[0]);
printf("\n 1.x-shearing\n 2.y-shearing\n 3.Exit");
printf("\n Enter ur choice:");
scanf("%d",&n);
printf("Enter the shearing factor:");
scanf("%d",&sh);
if(n==3)
exit(0);
switch(n)
{
case 1:
for(i=0;i<4;i++)
{
sx[i]=x[i]+(sh*y[i]);
sy[i]=y[i];
}
break;
case 2:
for(i=0;i<4;i++)
{
sx[i]=x[i];
sy[i]=(x[i]*sh)+y[i];
}
break;
for(i=0;i<3;i++)
line(x[i],y[i],x[i+1],y[i+1]);
line(x[i],y[i],x[0],y[0]);
for(i=0;i<3;i++)
line(sx[i],sy[i],sx[i+1],sy[i+1]);
line(sx[i],sy[i],sx[0],sy[0]);
getch();
closegraph();
2.y shearing
3.Exit
Enter ur choice 1
Enter the shearing factor :2
1.x-shearing
2.y shearing
3.Exit
Enter ur choice 2
Enter the shearing factor :2
#include<math.h>
void main()
{
int gd=DETECT,gm;
float x,y,x1,y1,xr,yr,xinc,yinc;
float len,i;
int opt;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"...//bgi");
setcolor(BLUE);
rectangle(200,200,400,400);
printf("\n Enter the points for line:\n");
printf("\n point x:\t");
scanf("%f",&x);
printf("\n point y:\t");
scanf("%f",&y);
printf("point x1:\t");
scanf("%f",&x1);
printf("point y1:\t");
scanf("%f",&y1);
cleardevice();
printf("\t\t\t LINE BEFORE CLIPPING\n\n");
rectangle(200,200,400,400);
setcolor(RED);
line(x,y,x1,y1);
printf("\t\t\t Do u want to clip[1/0]");
scanf("%d",&opt);
if(opt==1)
{
cleardevice();
printf("\t\tafter clipping\n");
setcolor(GREEN);
rectangle(200,200,400,400);
len=abs(x1-x);
if(abs(y1-y)>len)
{
len=abs(y1-y);
}
xr=x;
yr=y;
xinc=abs(x1-x)/len;
yinc=abs(y1-y)/len;
for(i=0;i<len;i++)
{
if(xr<200||xr>400||yr<200||yr>400)
{
}
else
{
putpixel(floor(xr),floor(yr),CYAN);
}
xr=xr+xinc;
yr=yr+yinc;
}
}
else
printf("\n\t Clipping not performed");
getch();
closegraph();
getch();
}
Point x1:400
Point y1:500
After clipping
scanf("%d",&ch);
switch(ch)
{
case 1:
Cleardevice();
printf("Enter the translation value");
scanf("%d",&x1);
a=a+x1;
b=b+x1;
c=c+x1;
d=d+x1;
bar3d(a,b,c,d,(c-a)/4,1);
getch();
break;
case 2:
cleardevice();
printf("Enter the scaling value");
scanf("%d",&x2);
a=a*x2;
b=b*x2;
c=c*x2;
d=d*x2;
bar3d(a,b,c,d,(c-a)/4,1);
getch();
break;
case 3:
cleardevice();
printf("Enter the rotation value");
scanf("%d",&x3);
a=a*cos(x3)+a*sin(x3);
b=b*sin(x3)-b*cos(x3);
c=c*cos(x3)+c*sin(x3);
d=d*sin(x3)-d*cos(x3);
bar3d(a,b,c,d,(c-a)/4,1);
getch();
break;
case 4:
exit(0);
}
}
}
OUTPUT OF 3D TRANSFORMATION
Enter the co-ordinates
200
200
300
300
1.Translation
2.Scaling
3.Rotation
4.Exit
Enter ur choice 1
1.Translation
2.Scaling
3.Rotation
4.Exit
Enter ur choice 2
Enter the scaling value 2
1.Translation
2.Scaling
3.Rotation
4.Exit
Enter ur choice 3
Enter the Roatation angle 20
BLACK
RED
BLUE
MEGENTA
LIGTHBLUE
BROWN
GREEN
LIGTHGRAY
CYAN
DARKGRAY
LIGTH
if(i%2==0)
{
circle(300,300,150);
ellipse(250,250,0,360,15,30);
ellipse(350,250,0,360,15,30);
fillellipse(250,265,14,14);
fillellipse(350,250,14,14);
line(300,275,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
}
else
{
circle(300,300,150);
ellipse(250,250,0,360,15,30);
ellipse(350,250,0,360,15,30);
fillellipse(250,265,14,14);
fillellipse(350,250,14,14);
line(300,275,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
}
}
getch();
closegraph();
}