You are on page 1of 50

VICKRAM

COLLEGE OF ENGINEERING, ENATHI 630 516


Approved by AICTE, New Delhi.
Affiliated to Anna University Trichirappalli.

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)

Bresenham's Line Drawing Algorithm


Using C programming.

1
(b)

Bresenham's Circle Drawing


Algorithm Using C programming

1
(c)

Bresenham's Ellipse Drawing


Algorithm Using C programming

.
Two Dimensional
Transformation Using C programming

Two Dimensional
Reflection Using C programming

Page Staff's Initial


Number

Two Dimensional Shearing Using C


programming.

Two Dimensional Line Clipping


Using C programming

Three Dimensional Transformation


Using C programming

.
7

Color Models Using C programming

String Compression Using C


programming

Graphical Animation Using C


programming.

10

Frame By Frame
Animation Using Flash

11

Motion Tweening
Using Flash

.
12

Shape Tweening
Using Flash

13

Study Of Tools

Program: BRESENHAMS LINE DRAWING ALGORITHM


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int xa,xb,ya,yb,dx,dy,xend,x,y,p,gd=DETECT,gmode;
clrscr();
initgraph(&gd,&gmode," ");
printf("\n\t Bresenhams line drawing algorithm");
printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\n\n\tEnter the starting points:");
scanf("%d%d",&xa,&ya);
printf("\n\n\tEnter the end points:");
scanf("%d%d",&xb,&yb);
dx=abs(xa-xb);
dy=abs(ya-yb);
if(xa>xb)
x=xb,y=yb,xend=xa;
else
x=xa,y=yb,xend=xb;
putpixel(x,y,7);
while(x<xend)
{

x+=1;
if(p<0)
p=p+2*dy;
else
y+=1,p=p+2*(dy-dx);
putpixel(x,y,7);
}
getch();
closegraph();

OUTPUT OF BRESENHAMS LINE DRAWING ALGORITHM


Enter the starting point
200 300
Enter the End point
250 350

Program: BRESENHAMS CIRCLE DRAWING ALGORITHM


#include<graphics.h>
#include<stdio.h>
#include<conio.h>
int x,y;
void plotpoints(int,int);
void main()
{

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);
}

OUTPUT OF BRESENHAMS CIRCLE DRAWING ALGORITHM

Enter the x co-ordinates 200


Enter the y co-ordinates 300
Enter R-Radius 50

Program: BRESENHAMS ELLIPSE DRAWING ALORITHM


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main() { int i,gd=DETECT,gm,x1=0,y1=0,r1=0,r2=0;
float x=0,y=0,t,d;
initgraph(&gd,&gm,"f:\\");
setbkcolor(BLACK);
setcolor(YELLOW);
fflush(stdin);
printf("enter the center:");
scanf("%d%d",&x1,&y1);
printf("enter the radius 1 and 2:");
scanf("%d%d",&r1,&r2);
for(i=0;i<360;i++)
{

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();
}

OUTPUT OF BRESENHAMS ELLIPSE DRAWING ALGORITHM

Enter the center : 200 300


Enter the radius 1 and 2: 75 50

Program: TWO DIMENSIONAL TRANSFORMATION


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define pi 3.148
int gd,gm;
void box(int x1,int y1,int x2,int y2)
{
char start[20],end[20];
line(x1,y1,x2,y1);
line(x2,y1,x2,y2);
line(x2,y2,x1,y2);
line(x1,y2,x1,y1);
}
void main()
{
int x1,x2,y1,y2,x3,y3,tx,ty,i,j,theta,ch,cho;
int a,b,c,d,e,f,x,y;
float sx,sy,m,n;
clrscr();
do
{
printf("\n\n\t\t sample i/p and o/p");

printf("\n\t Enter the value of x1,y1");


scanf("%d%d",&x1,&y1);
printf("\n\t Enter the value of x2,y2");
scanf("%d%d",&x2,&y2);
printf("\n\t1.Translation");
printf("\n\t2.Rotation");
printf("\n\t3.scaling");
printf("\n\t4.Exit");
printf("\n\t Enter ur choice");
scanf("%d",&ch);
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
switch(ch)
{
case 1:
setcolor(5);
box(x1,y1,x2,y2);
printf("Enter the hori and verti translation");
scanf("%d%d",&tx,&ty);
setcolor(35);
box(x1+tx,y1+ty,x2+tx,y2+ty);
getch();
goto p;
break;
case 2:

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

Program: TWO DIMENSIONAL REFLECTION


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void triangle(int x1,int y1,int x2,int y2,int x3,int y3)
{
char start[30],mid[50],end[30];
sprintf(start,"(%d%d)",x2,y2);
outtextxy(x1-5,y1-5,start);
sprintf(mid,"(%d%d)",x2,y2);
outtextxy(x2-5,y2-5,mid);
sprintf(end,"(%d%d)",x3,y3);
outtextxy(x3-5,y3-5,end);
setcolor(15);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
void main()
{

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;
}
}

OUTPUT OF PROGRAM FOR REFLECTION

Enter the co-ordinates: 200 200 300 100 300 200


Main menu
1.Creation of triangle
2.x-axis reflection
3.y-axis reflection
4.Exit
Enter your choice 1

(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)

Program: TWO DIMENSIONAL SHEARING


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
void main()

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++)

printf("Enter the %d value \n",i+1);


scanf("%d%d",&x[i],&y[i]);
sy[i]=y[i];
sx[i]=x[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();

OUTPUT OF PROGRAM FOR SHEARING


Enter the 1 value
100 100
Enter the 2 value
0 100
Enter the 3 value
00
Enter the 4 value
100 0 1.x-shearing

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

Program: TWO DIMENSIONAL LINE CLIPPING


#include<stdio.h>
#include<conio.h>
#include<graphics.h>

#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();
}

OUTPUT OF LINE CLIPPING


Enter the point for line:
Point x:200
Point y:300

Point x1:400
Point y1:500

Line before clipping


Do u want to clip [1/0]1

After clipping

Program: THREE DIMENSIONAL TRANSFORMATION


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int a,b,c,d,e,f,g;
int x1,x2,x3,y,ch;
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
printf("Enter the co-ordinates");
scanf("%d%d%d%d",&a,&b,&c,&d);
bar3d(a,b,c,d,(c-a)/4,1);
getch();
while(1)
{
printf("1.translation\n2.scaling\n3.Rotation4.Exit\n");
printf("Enter ur choice");

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

Enter the translation value 2

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

Program: COLOR MODELS


#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i,j,x,y,s;
char st1[15]
[20]={"EMPTY_FILL","SOLID_FILL","LINE_FILL","LTSLASH_FILL","SLASH_
FILL","BKSLASH_FILL","LTBKSLASH_FILL","HATCH
_FILL","XHATCH_FILL","INTERLEAVE_FILL","WID_DOT_FILL","CLOSE_D
OT_FILL","USER_FILL"};
initgraph(&gd,&gm," ");
s=y=0;
for(i=0;i<3;i++)
{
x=20;
y=y+50;
for(j=0;j<4;j++)
{
x=x+70;
setfillstyle(s,MAGENTA);
rectangle(x,y,x+80,y+80);
floodfill(x+1,y+1,WHITE);
outtextxy(x,y+90,st1[s]);
x=x+50;
s++;
}
y=y+100;
}
getch();
closegraph();
}

OUTPUT DISPLAY FOR COLOR MODELS

BLACK
RED

BLUE

MEGENTA
LIGTHBLUE

BROWN

GREEN

LIGTHGRAY

LIGTHGREEN LIGTHCYAN LIGTHRED


YELLOW
MEGENTA

CYAN

DARKGRAY

LIGTH

Program: STRING COMPRESSION


#include<stdio.h>
#include<conio.h>
void main()
{
int i,t=1;
char str[15],c;
clrscr();
printf("Enter the string");
gets(str);
for(i=0;str[i]!=NULL;i++)
{
c=str[i];
if(str[i]==str[i+1])
{
t+=1;
continue;
}
else
{
printf("%c%d\n",c,t);
t=1;
}
}
getch();

OUTPUT OF STRING COMPRESSION


Enter the string apple
a1
p2
l1
e1

Program: GRAPHICAL ANIMATION


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i,j;
initgraph(&gd,&gm," ");
setbkcolor(5);
for(i=0;i<10;i++)
{
delay(1000);
cleardevice();
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,265,14,14);
line(300,725,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
line(300,150,300,50);
line(265,155,245,90);
line(325,155,345,90);
}
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,265,14,14);
line(300,275,300,325);
line(301,275,301,325);
arc(300,320,220,330,70);
line(300,150,300,50);
line(265,155,245,90);
line(325,155,345,90);
}
}
for(i=0;i<10;i++)
{
delay(1000);
cleardevice();

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();
}

OUTPUT FOR GRAPHICAL ANIMATION

OUTPUT FOR MOTION TWEENING

OUTPUT FOR SHAPE TWEENING

You might also like