Date post: | 03-Apr-2018 |
Category: |
Documents |
Upload: | bernice-samina |
View: | 236 times |
Download: | 0 times |
of 32
7/28/2019 Graphics And Multimedia Lab Manual
1/32
EX NO 1A BRESENHAMS LINE DRAWING ALGORITHM
Program:
#include
#include#include
#includevoid main()
{int xa,xb,ya,yb,dx,dy,xend,x,y,p,gd=DETECT,gmode;
clrscr();
initgraph(&gd,&gmode," ");printf("\nEnter the start points:");
scanf("%d%d",&xa,&ya);
printf("\nEnter 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
7/28/2019 Graphics And Multimedia Lab Manual
2/32
Output:
Enter the start point :200 300
Enter the End point:
250 350
7/28/2019 Graphics And Multimedia Lab Manual
3/32
EXNO 1B BRESENHAMS CIRCLE DRAWING ALGORITHM
Program:
#include
#include#include
int x,y;void plotpoints(int,int);
void main(){
int p,x1,y1,r;
int gdriver=DETECT,gmode;initgraph(&gdriver,&gmode," ");
clearviewport();
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
7/28/2019 Graphics And Multimedia Lab Manual
4/32
}
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
Enter x co-ordinates: 200
Enter y co-ordinates: 300
Enter R-Radius: 50
7/28/2019 Graphics And Multimedia Lab Manual
5/32
7/28/2019 Graphics And Multimedia Lab Manual
6/32
EXNO 1C BRESENHAMS ELLIPSE DRAWING ALORITHM
Program:#include
#include#include
#includevoid 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
7/28/2019 Graphics And Multimedia Lab Manual
7/32
Output
Enter the center :200 300
Enter the radius 1 and 2:
75 50
7/28/2019 Graphics And Multimedia Lab Manual
8/32
EXNO 2 2D TRANSFORMATIONS
Progarm
#include
#include#include
#include#include
void main(){
int i,poly1[10],poly2[10],poly3[10],poly4[10],tx,ty,sx;
int n,xr,yr,a;int poly[10],poly5[10],sy;
int gd=DETECT,gm;
initgraph(&gd,&gm,"E:\\tc\\bgi");printf("\Enter the no of verticles for a polygon");scanf("%d",&n);
printf("\n Enter the (x,y)co-ordinates of verticles");
for(i=0;i
7/28/2019 Graphics And Multimedia Lab Manual
9/32
drawpoly(n+1,poly1);
getch();cleardevice();
outtextxy(30,30,"original image");
drawpoly(n+1,poly);outtextxy(10,10,"Enter the scaling Factor");
gotoxy(30,3);scanf("%d",&sx);
for(i=0;i
7/28/2019 Graphics And Multimedia Lab Manual
10/32
poly4[i+1]=poly[i+1];
}poly4[2*n]=poly4[0];
poly4[2*n+1]=poly4[1];
drawpoly(n+1,poly4);getch();
cleardevice();outtextxy(30,30,"original image");
drawpoly(n+1,poly);outtextxy(10,10,"Enter the shear factor");
gotoxy(30,3);
scanf("%d",&sy);for(i=0;i
7/28/2019 Graphics And Multimedia Lab Manual
11/32
Enter translation factor
100100
Original image
Enter the scaling factor: 2
Original image
Enter the rotation factor
250250
90Original image
7/28/2019 Graphics And Multimedia Lab Manual
12/32
7/28/2019 Graphics And Multimedia Lab Manual
13/32
EXNO 3A COHEN-SUTHERLAND CLIPPING
Program
#include
#include#include
int cliptest(float p,float q,float *u1,float *u2){
float r;int g;
g=1;
if(p*u2)g=0;else
if(r>*u1)
*u1=r;}
else
if(p>0.0){
r=q/p;
if(r
7/28/2019 Graphics And Multimedia Lab Manual
14/32
initgraph(&d,&m,"E:\\tc\\bgi");
printf("\n enter the window coordinates");scanf("%d%d%d%d",&wx1,&wy1,&wx2,&wy2);
printf("\n enter the line coordinates");
scanf("%d%d%d%d",&lx1,&ly1,&lx2,&ly2);printf("\n before clipping");
rectangle(wx1,wy1,wx2,wy2);line(lx1,ly1,lx2,ly2);
getch();u1=0.0;
u2=1.0;
dx=lx2-lx1;if(cliptest(-dx,lx1-wx1,&u1,&u2))
if(cliptest(dx,wx2-lx1,&u1,&u2))
{dy=ly2-ly1;if(cliptest(-dy,ly1-wy1,&u1,&u2))
if(cliptest(dy,wy2-ly1,&u1,&u2))
{if(u10.0)
{lx1=lx1+u1*dx;
ly1=ly1+u1*dy;}
cleardevice();
printf("\n after clipping");
rectangle(wx1,wy1,wx2,wy2);line(lx1,ly1,lx2,ly2);
}
getch();}
7/28/2019 Graphics And Multimedia Lab Manual
15/32
Output
Enter the window coordinates:100
100
200200
Enter the line coordinates:100
100300
300
Before Clipping
After Clipping:
7/28/2019 Graphics And Multimedia Lab Manual
16/32
EXNO 3B WINDOW VIEWPORT MAPPING
Program
#include
#include#include
#includemain()
{float sx,sy;
int w1,w2,w3,w4,x1,x2,x3,x4,y1,y2,y3,y4,v1,v2,v3,v4;
int gd=DETECT,gm;initgraph(&gd,&gm,"C:/tc/bgi");
printf("Enter the Co-ordinates x1,y1,x2,y2,x3,y3\n");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);cleardevice();w1=5;
w2=5;
w3=635;w4=465;
rectangle(w1,w2,w3,w4);
line(x1,y1,x2,y2);line(x2,y2,x3,y3);
getch();
v1=425;v2=75;
v3=550;v4=250;
sx=(float)(v3-v1)/(w3-w1);
sy=(float)(v4-v2)/(w4-w2);
rectangle(v1,v2,v3,v4);x1=v1+floor(((float)(x1-w1)*sx)+0.5);
x2=v1+floor(((float)(x2-w1)*sx)+0.5);
x3=v1+floor(((float)(x3-w1)*sx)+0.5);y1=v2+floor(((float)(y1-w2)*sy)+0.5);
y2=v2+floor(((float)(y2-w2)*sy)+0.5);
y3=v2+floor(((float)(y3-w2)*sy)+0.5);line(x1,y1,x2,y2);
line(x2,y2,x3,y3);line(x3,y3,x1,y1);
7/28/2019 Graphics And Multimedia Lab Manual
17/32
getch();
return 0;}
Output
Enter the Co-ordinates of x1,y1,x2,y2,x3,y3:
100 150120 200
180 150
7/28/2019 Graphics And Multimedia Lab Manual
18/32
EXNO 4 3D TRANSFORMATIONS
Program
#include
#include#include
#include#include
#includeint gd=DETECT,gm;
int x1,y1,x2,y2;
void draw_cube(double edge[20][3]){
initgraph(&gd,&gm,"E:\\tc\\bgi");
int i;clearviewport();for(i=0;i>b>>c;
initgraph(&gd,&gm,"E:\\tc\\bgi");clearviewport();
for(i=0;i
7/28/2019 Graphics And Multimedia Lab Manual
19/32
edge[i][0]=edge[i][0]*a;
edge[i][1]=edge[i][1]*b;edge[i][2]=edge[i][2]*c;
}
draw_cube(edge);closegraph();
}void translate(double edge[20][3])
{int a,b,c;
int i;
couta>>b>>c;
initgraph(&gd,&gm,"E:\\tc\\bgi");
clearviewport();for(i=0;i
7/28/2019 Graphics And Multimedia Lab Manual
20/32
temp=edge[i][1];
temp1=edge[i][2];edge[i][1]=temp*cos(theta)-temp1*sin(theta);
edge[i][2]=temp*sin(theta)+temp1*cos(theta);
}draw_cube(edge);
break;case 2:
couttheta;
theta=(theta*3.14)/180;
for(i=0;i
7/28/2019 Graphics And Multimedia Lab Manual
21/32
double edge[20][3]={100,0,0,
100,100,0,0,100,0,
0,100,100,
0,0,100,0,0,0,
100,0,0,100,0,100,
100,75,100,75,100,100,
100,100,75,
100,100,0,100,100,75,
100,75,100,
75,100,100,0,100,100,0,100,0,
0,0,0,
0,0,100,100,0,100};
while(1)
{clrscr();
cout
7/28/2019 Graphics And Multimedia Lab Manual
22/32
scale(edge);
break;case 5:
exit(0);
break;default:
cout
7/28/2019 Graphics And Multimedia Lab Manual
23/32
Enter your choice : 2
Enter the Translation factor:100
100
100
3D Transformation1.Draw cube
2.Tranformation3.Rotation
4.Scaling
5.Exit
Enter your choice : 3Rotation about..
1.X-axis 2.Y-axis 3.Z-axisEnter your choice :1
Enter the angle : 30
7/28/2019 Graphics And Multimedia Lab Manual
24/32
3D Transformation
1.Draw cube2.Tranformation
3.Rotation
4.Scaling5.Exit
Enter your choice : 4Enter the scaling factor
22
2
3D Transformation
1.Draw cube2.Tranformation3.Rotation
4.Scaling5.Exit
Enter your choice : 5
7/28/2019 Graphics And Multimedia Lab Manual
25/32
EXNO5 PROJECTION OF 3D IMAGES
Program
#include
#include #include
#includevoid 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
7/28/2019 Graphics And Multimedia Lab Manual
26/32
{
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
7/28/2019 Graphics And Multimedia Lab Manual
27/32
Output
7/28/2019 Graphics And Multimedia Lab Manual
28/32
EXNO 6 CONVERT BETWEEN COLOR MODELS
Program
Output
7/28/2019 Graphics And Multimedia Lab Manual
29/32
EXNO 7 IMPLEMENTATION OF TEXT COMPRESSISON ALGORITHM
Program
Output
7/28/2019 Graphics And Multimedia Lab Manual
30/32
EXNO 8 IMPLEMENTATION OF IMAGE
COMPRESSISON ALGORITHM
Program
Output
7/28/2019 Graphics And Multimedia Lab Manual
31/32
EXNO9 ANIMATION
Program
output
7/28/2019 Graphics And Multimedia Lab Manual
32/32
EXNO 10 IMAGE OPERATIONS
Program
Output