Vous êtes sur la page 1sur 44

INDEX

S.No
.

Practical

Page
No.

1.

Introduction to
COMPUTER GRAPHICS.

2-3

2.

WAP to draw line using


DDA.

4-6

3.

WAP to draw line using


BRESENHAM'S METHOD.

7-9

4.

WAP to draw circle using


MID-POINT METHOD.

10-12

5.

WAP to draw circle using


BRESENHAM'S METHOD.

13-15

6.

WAP to draw THICK LINE.

16-18

7.

WAP to draw a line using


CLIPPING ALGO.

19-23

8.

WAP to Implement 2-D


transformation.

24-35

9.

WAP to Implement 3-D


transformation.

36-41

10.

WAP to draw Bezier curve.

42-44

Date

Signature

EXPERIMENT NO 1
1

INTRODUCTION TO COMPUTER GRAPHICS.


We use computer graphics in our daily life, use in the field of science, entertainment,
animated films and cartoons. It display the information in the form of graphics objects,
graphs and diagram instead of simple text.
In computer graphics, pictures and graphic objects are represented as a collection of the
discrete picture elements called PIXELS. Each pixel on the graphic display doesnt
represent mathematical point. It represent a region which theoretically contains an infinite
number of points.
RASTERLIZATION
The process of determining the appropriate pixels for the representation of picture or
graphic object is known as RASTERLIZATION.
SCAN CONVERSION
The process of representing continous pictures or graphic objects as a collection of
discrete pixel is called SCAN CONVERSION.
Computer graphics allow rotation translation and performing various projection on the
picture before displaying.
It also allows to add effect such as hidden surface removal, shading or transparency to the
picture before final representation.
Graphics device include both input and display devices.
APPLICATION OF COMPUTER GRAPHIC

USER INTERFACE
1. Graphic interface provide an attractive and easy interaction between users
and the computer.
2. Floating of the graphics and the charts:- in industry, educational
organization , business embedded computer graphics are used to create 2D
and 3D graphs of mathematics.
3. Office automation and desktop publishing
a) Desktop publishing on personal computer allows the user of
graphic for the creation and dissemination of information.

b) Desktop publishing allows user to create documents which contain


text, graphics etc.

ANIMATION
We use animation for the creating animated movies, cartoon movies etc.

ADVANTAGES
1. It has an ability to show moving pictures and thus it is possible to produce
animation with computer graphics.
2. The computer graphics provide tools called MOTION DYNAMICS.
3. Computer graphics also provide facility called UPDATE DYNAMICS.

EXPERIMENT NO 2
3

WRITE A PROGRAM TO DRAW A LINE USING DDA.


#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,length ;
int i,gd,gm;
clrscr();
cout<<"Enter the value of x1";
cin>>x1;
cout<<"Enter the value of y1";
cin>>y1;
cout<<"Enter the value of x2";
cin>>x2;
cout<<"Enter the value of y2";
cin>>y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
{
length=dx;
}
else
{
length=dy;
}
dx=(x2-x1)/length;
dy=(y2-y1)/length;
x=x1+0.5;
y=y1+0.5;
i=1;
while(i=<length);
{
putpixel(x,y,15);

x=x+dx;
y=y+dy;
i=i+1;
}
getch();
closegraph();
}

OUTPUT
5

EXPERIMENT NO 3
6

WAP TO DRAW A LINE USING BRESENHAM'S METHOD.


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd,gm;
clrscr();
cout<<"Enter the value of x1";
cin>>x1;
cout<<"Enter the value of y1";
cin>>y1;
cout<<"Enter the value of x2";
cin>>x2;
cout<<"Enter the value of y2";
cin>>y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
dx=abs(x2-x1);
dy=abs(y2-y1);
x=x1;
y=y1;
e=2*dy-dx;
i=1;
do
putpixel(x,y,15);
while(e>0)
{
y=y+1;
e=e-2*dy;
}
x=x+1;
e=e+2*dy;
i=i+1;
}

while(i<dy);
getch();
closegraph();
}

OUTPUT

EXPERIMENT NO 4
9

WRITE A PROGRAM TO DRAW A CIRCLE USING MID-POINT METHOD.


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
float p;
int i,gd,gm,x,y,r;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
cout<<"Enter the radius of circle";
cin>>r;
x=0;y=r;
p=1.25-r;
do
{
putpixel(200+x,200+y,15);
putpixel(200+y,200+x,15);
putpixel(200+x,200-y,15);
putpixel(200+y,200-x,15);
putpixel(200-x,200-y,15);
putpixel(200-x,200+y,15);
putpixel(200-y,200+x,15);
putpixel(200-y,200+x,15);
if(p<0)
{
x=x+1;
y=y;
p=p+2*x+1;
}
else
{
x=x+1;
y=y+1;
p=p+2*(x-y)+1;
}}
while(x<y);
getch();
closegraph();
1
0

OUTPUT

1
1

EXPERIMENT NO 5
WRITE A PROGRAM TO DRAW A CIRCLE USING BRESENHAM'S METHOD
1
2

#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
float d;
int i,gd,gm,x,y;
int r;
clrscr();
cout<<"Enter the radius of circle";
cin>>r;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
x=0;y=r;d=3-2*r;
do
{
putpixel(200+x,200+y,15);
putpixel(200+y,200+x,15);
putpixel(200+y,200-x,15);
putpixel(200+x,200-y,15);
putpixel(200-x,200-y,15);
putpixel(200-y,200-x,15);
putpixel(200-y,200+x,15);
putpixel(200-x,200+y,15);
if(d==0)
{
d=d+4*x+6;
}
else{
d=d+4*x-4*y+10;
y=y-1;
}
x=x+1;
}
while(x<y) ;
getch();
closegraph;
}
1
3

OUTPUT

1
4

EXPERIMENT NO 6
1
5

WRITE A PROGRAM TO DRAW A THICK LINE.


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT, gm;
float wy,wx,x1,x2,y1,y2;
int l,thickness;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cout<<"Enter the co-ordinatesb for line ="<<endl<<"x1=";
cin>>x1;
cout<<"enter the co-ordinates for line ="<<endl<<"x2=";
cin>>x2;
cout<<"enter the co-ordiantes for line "<<endl<<"y1=";
cin>>y1;
cout<<"enter the co-ordiantes for line"<<endl<<"y2=";
cin>>y2;
cout<<"enter the required thickness"<<endl;
cin>>thickness;
line(x1,x2,y1,y2);
if((y2-y1)/(x2-x1)<1)
{
wy=(thickness-1)*sqrt(pow((x2-x1),2))+pow((y2-y1),2)/(2*abs(x2-x1));
for(int i=0;i<wy;i++)
{
line(x1,y1-1,x2,y2-i);
line(x1,y1+1,x2,y2+i);
}
}
Else
{
wx=(thickness-1)*sqrt(pow((x2-x1),2)+pow((y2-y1),2)/(2*abs(y2-y1)));
{
line(x1-1,y1,x2-1,y2);
line(x1+1,y1,x2+1,y2);
}
}
cout<<"This is the line of thickness"<<thickness;
1
6

getch();
}

OUTPUT

1
7

EXPERIMENT NO 7
1
8

WRITE A PROGRAM TO DRAW A LINE USING CLLIPING ALGO.


#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
typedef struct coordinate
{
int x,y;
char code[4];
}
pt;
void drawwindow();
void drawline (pt p1, pt p2);
pt setcode(pt p);
int visibility (pt p1, pt p2);
main()
{
int gd=DETECT, gm,v;
pt p1,p2,ptemp;
initgraph(&gd,pgm,"C:\\TC\\BGI");
cout<<"enter the endpoint1(x,y):";
cin>>p1.x>>p1.y;
cout<<"enter the endpoint2(x,y):";
cin>>p2.x>>p2.y;
drawwindow();
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();

1
9

case 0: cleardevice();
p1=resetendpt(p1,p2);
p1=resetendpt(p2,p1);
drawwindow();
drawline(p1,p2,15);
break();
}
getch();
closegraph();
return (0);
}
void drawwindow()
{
setcolor(red);
line(150,100,450,100);
line(450,100,450,350);
line(450,350,150,350);
line(150,350,150,100);
}
void drawline(pt p1,pt p1,int cl)
{
setcolor(cl);
line(p1.x,p1.y,p2.x,p2.y);
}
pt setcode(pt p)
{
pt ptemp;
if(p.y<100)
ptemp.code[0]='1';
else
ptemp.code[0]='0';
if(p.y>350)
ptemp.code[1]='1';
else
ptemp.code[1]='0';
if(p.x>450)
ptemp.code[2]='0';
if(p.x<150)
ptemp.code[3]='1';
else
2
0

ptemp.code[3]='0';
ptemp.x=p.x;
ptemp.y;
return(ptemp);
{
int visibility(pt p1,pt p2)
{
int i, flag=0;
for(i=0;i<4;i++)
{
if((p1.code[1]!='0'||(p2.code[i]!='0'))
flag=1;
}
if(flag==0)
return(0);
for(i=0;i<4;i++)
{
if((p1.code[i]==p2.code[i]&&(p1.code[i]=='i'))
flag=0;
}
if(flag==0)
return(1);
return(2);
}
pt resetendpt(pt p1,pt p2)
{
pt temp;
int x,y,l;
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)/(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];
2
1

if(temp.y<=350&&temp.y>=100)
return(temp);
}
if(p1.code[0]=='1')
y=100;
if(p1.code[1]=='1')
y=350;
if((p1.code[0]='1'||(p1.code[1]=='1'))
{
m=(float)(p2.y-p1.y)/(p2.x-p1.x);
k=(flot)p1.x+(float)(y-p1.x)/m;
temp.x=k;
temp.y=y;
for (i=0;i<4;i<++)
temp.code[i]=p1.code[i];
return(temp);
}
else
return(p1);
}

OUTPUT

2
2

EXPRIMENT NO-8
2
3

Write a program to implement 2-Dimensional transformation.


#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<math.h>
#include<graphics.h>
#define max 20
float t[max][3],c[max][3],r[max][3];
int n,ct;
void trns();
void getdata();
void ytrnslate(float,float);
void draw axis();
void scale(float, float);
void rotate();
void reflect();
void shear();
void origin();
void point(float);
void clock(float);
void anti(float);
void display(float t[max][3]);
void drawaxis()
{
int i;
set color(WHITE);
line(0,240,640,240);
line(320,0,320,480);
for (i=0;i<=n-1;i++)
{
line(320+c[i][0],240-c[i][1],320+c[i+1][0],240-c[i+1][1]);
}
line (32+c[n-1][0],[240-c][1],[320+c][0][0],[240-c][0][1]);
}
void display(float t[max][3])
{
int i;
if (ct==0)
{
2
4

cout<<"vertices not available\n";


}
else
{
for(i=0;i<=n-1;i++)
{
line(320+t[i][0],220-t[i][1],320+t[i+1][0],240-t[i+1][1]);
}
line(320+t[n-1],240-t[n-1][1],320+t[0][0]240-t[0][1]);
}
}
void getdata()
{
struct polyg
{
int x,y;
}
s[20];
int i;
cout<<"given total number of vertices";
cin>>n;
if(ct==0)
{
ct=1;
}
if(n>20)
{
cout<<"enter vertices less than 20";
}
else
{
for(i=0;i<=n-1;i++)
{
cout<<"cordinate is i+1";
cin>>s[i].y;
c[i][1]=t[i][0]=s[i].x;
c[i][1]=t[i][1]=s[i].y;
c[i][2]=t[i][2]=1;
}
}
}
2
5

void multy(float tmat[3][3])


{
inti,j,sum,k;
for(j=0;j<3;j++)
{
sum=0;
for(k=0;k<3;k++)
{
sum=sum+c[i][k]*tmat[k][j];
}
r[i][j]=sum;
}}}
void translate(float tx,float ty)
{
float p[3][3]={1,0,0,0,1,0,0,0,1},sum;
int i,j,k;
p[2][0]=tx;
p[2][1]=ty;
for(i=o;i<n;i++)
{
for(j=0;j<3;j++)
{
sum=0;
for(k=o;k<3;k++)
{
sum=sum+t[i][k]*p[k][j];
}
r[i][j]=sum;
}}
cleardevice();
}
void scale(float sx,float sy)
{
int j,i,k,sum;
float p[3][3]={1,0,0,0,1,0,0,0,1};
p[0][0]=sx;
p[1][1]=sy;
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
2
6

sum=0;
for(k=0;k<3;k++)
{
sum=sum+c[i][k]*p[k][j];
}
r[i][j]=sum;
}}
cleardevice();
}
void clock(float x)
{
int i,j,k;
float p[3][3]={1,0,0,0,1,0,0,0,1},sum;
p[0][0]=cos(x);
p[0][1]=sin(x);
p[1][0]=sin(x);
p[1][1]=cos(x);
for(i=0;i<n;i++)
{
for(j=0;i<3;j++)
{
sum=0
for(k=0;k<3;k++)
{
sum=sum+t[i][k]*p[k][j];
}
r[i][j]=sum;
}}
cleardevice();
}
void anti(float x)
{
int i,j,k;
float sum;
float p[3][3]={0,0,0,0,0,0,0,0,1};
p[0][0]=cos(x);
p[0][1]=sin(x);
p[1][0]=sin(x);
p[1][1]=cos(x);
for(i=0;i<n;i++)
{
2
7

for(j=0;j<3;j++)
{
sum=0;
for(k=0;k<3;k++)
{
sum=sum+t[i][k]*p[k][j];
}
r[i][j]=sum;
}}
cleardevice();
}
void origin(float x)
{
int opt;
cout<<"\n\t 1.rotate clockwise.";
cout<<"\n\t 2.rotate anticlockwise.";
cout<<"\n\t enter ur choice.";
cin>>opt;
switch(opt)
{
case 1:clock(x);
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
case 2:anti(x);
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
}}
void point(float x)
{
int opt;
int a,b,i,j;
cout<<"\n\t give coordinates of point:";
cin>>a>>b;
cout<<"\n\t 1.rotate clockwise.";
cout<<"\n\t 2.rotate anticlockwise.";
2
8

cout<<"\n\t enter ur choice.";


cin>>opt;
switch(opt)
{
case 1:translate(-a,-b);
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
t[i][j]=r[i][j];
}}
clock(x);
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
t[i][j]=r[i][j];
}}
translate(a,b);
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
case 2:translate(-a,-b);
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
t[i][j]=r[i][j];
}}
anti(x);
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
t[i][j]=r[i][j];
}}
translate(a,b);
drawaxix();
setcolor(GREEN);
2
9

display(r);
getch();
break;
}}
void rotate()
{
int ch,i,opt;
char ans;
float angle;
cout<<"\n\t give angle";
cin>>angle;
angle=(angle*3.14)/180;
do
{
cout<<"\n\t 1.rotate w.r.t. origion.";
cout<<"\n\t 2.rotate w.r.t. some other point.";
cout<<"\n\t enter ur choice";
cin>>opt;
switch(opt)
{
case 1:origin(angle);
break;
case 2:point(angle);
break;
}
cout<<"\n\t do u want to continue[y/n]:";
cin>>ans;
}
while(ans=='y'||ans=='y');
}
void reflect()
{
int opt;
float tmat[3][3]={1,0,0,0,1,0,0,0,1};
clear device();
cout<<"\n 1.reflect abt y axis\n";
cout<<"\n 2.reflect abt x axis\n";
cout<<"\n 3.reflect abt origin\n";
cout<<"\n 4.reflect abt line y=x\n";
cout<<"\n 5.reflect abt line y=-x\n";
cout<<"\n give ur choice\n";
3
0

cin>>opt;
switch(opt)
{
case 1:tmat[0][0]=-1;
multy(tmat);
break;
case 2:tmat[1][1]=-1;
multy(tmat);
break;
case 3:tmat[0][0]=-1;
tmat[1][1]=-1;
multy(tmat);
break;
case 4:tmat[0][0]=0;
tmat[0][1]=1;
tmat[1][0]=1;
tmat[1][1]=0;
multy(tmat);
break;
case 5:tmat[0][0]=0;
tmat[0][1]=-1;
tmat[1][0]=-1;
tmat[1][1]=0;
multy(tmat);
break;
default:cout<<"\n invalid choice";
}
getch();
}
void shear()
{
int opt;
float tmat[3][3]={1,0,0,0,1,0,0,0,1},a,b;
clear device();
cout<<"\n 1.y-shear\n";
cout<<"\n 2.x-shear\n";
cout<<"\n 1.give ur choice\n";
cin>>opt;
switch(opt)
{
case 1:cout<<"\n enter value of a";
3
1

cin>>a;
tmat[0][1]=a;
multy(tmat);
break;
case 2:cout<<"\n enter value of b";
cin>>b;
tmat[1][0]=b;
multy(tmat);
break;
default:cout<<"\n invalid choice";
}
getch();
}
void main()
{
int opt;
char ans;
float tx,ty,sx,sy;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi";
cleardevice();
getdata();
do
{
cleardevice();
cout<<"***operation on polygon***";
cout<<"\n\n1.display original polygon";
cout<<"\n\n2.translate";
cout<<"\n\n3.scale";
cout<<"\n\n4.rotate";
cout<<"\n\n5.reflect";
cout<<"\n\n6.shear";
cout<<"\n\n7.exit";
cout<<"\n\n give ur choice";
cin>>opt;
switch(opt)
{
case 1:cleardevice();
drawaxix();
break;
case 2:cout<<"\n give value of tx";
3
2

cin>>tx;
cout<<"\n give value of ty";
cin>>ty;
translate(tx,ty);
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
case 3:cout<<"\n give value of sx";
cin>>sx;
cout<<"\n give value of sy";
cin>>sy;
scale(sx,sy);
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
case 4:rotate();
break;
case 5:reflect();
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
case 6:shear();
drawaxix();
setcolor(GREEN);
display(r);
getch();
break;
case 7:exit(0);
}
cout<<"\n do u want to continue[y/n]:";
cin>>ans;
}
while(ans=='y'||ans=='y');
getch();
closegraph();
3
3

OUTPUT

3
4

EXPERIMENT NO-9
3
5

Write a program to implement 3-Dimensional transformation.


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define pi 3 1 42
void show(float(a[2][2][4])
{
int x[8],y[8],l,j,k;
k=0;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
x[k]=a[i][i][0]-0.707*a[i][j][2];
y[k]=a[i][j][1]-0.707*a[i][j][2];
k++;
}
}
for(i=0;i<3;i++)
{
line(x[i]+320,240-y[i],x[i+1]+320,240-y[i+1]);
line(x[i]+320,240-y[i],x[i+4]+320,240-y[i+4]);
}
line(x[i]+320,240-y[i],x[i+4]+320,240-y[i+4]);
line(x[i]+320,240-y[i],x[0]+320,240-y[0]);
for(i=4;i<7;i++)
{
line(x[i]+320,240-y[i],x[i+1]+320,240-y[i+1]);
}
line(x[i]+320,240-y[i],x[4]+320,240-y[4]);
}
void mul(float a[2][4][4],float t[4][4],float b[2][4][4])
{
int sum,l,j,k,l;
for(i=0;i<2;i++)
for(j=0;j<4;j++)
for(k=0;k<4;k++)
3
6

{
sum=0
for(l=0;l<4;l++)
sum+=a[i][j][l]*t[l][k];
b[i][j][k]=sum;
}}
void trans(float a[2][4][4])
{
int l,j,tx,ty,tz;
float b[2][4][4],t[4][4];
cout<<"\n enter the X translation:";
cin>>tx;
cout<<"\n enter the Y translation:";
cin>>ty;
cout<<"\n enter the Z translation:";
cin>>tz;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(i==j)
t[i][j]=1;
else
t[i][j]=0;
}
t[3][0]=tx;
t[3][0]=ty;
t[3][2]=tz;
mul(a,t,b);
show(b);
}
void scale(float a[2][4][4])
{
int l,j;
float sx,sy,sz;
float b[2][4][4],s[4][4];
cout<<"\n enter the X scaling factor:";
cin>>sx;
cout<<"\n enter the Y scaling factor:";
cin>>sy;
cout<<"\n enter the Z scaling factor:";
cin>>sz;
3
7

for(i=0;i<4;i++)
for(j=0;j<4;j++)
s[i][j]=0;
s[0][0]=sx;
s[1][1]=sy;
s[2][2]=sz;
mul(a,s,b);
show(b);
void rot(float a[2][4][4])
{
int l,j,an,choice;
float b[2][4][4],r[4][4];
float angle;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
r[i][j]=0;
cout<<"\n\n abt which axis:";
cout<<"\n\n\n\t1.X axis";
cout<<"\n\n\n\t2.Y axis";
cout<<"\n\n\n\t3.Z axis";
cout<<"\n\n\n enter ur choice";
cin>>choice;
cout<<"\n enter the angle of rotation:";
cin>>an;
angle=an*pi/180;
switch(choice)
{
case 1:r[0][0]=1;
r[1][1]=r[2][2]=cos(angle);
r[1][2]=sin(angle);
r[2][1]=sin(angle);
break;
case 2:r[0][0]=r[2][2]=cos(angle);
r[0][2]=-sin(angle);
r[0][2]=sin(angle);
r[1][1]=1;
break;
case 3:r[0][0]=r[1][1]=cos(angle);
r[0][1]=sin(angle);
r[1][0]=sin(angle);
r[2][2]=1;
3
8

break;
}
r[3][3]=1;
mul(a,r,b);
show(b);
}
void ref(float a[2][4][4])
{
int i,j,choice;
float b[2][4][4],r[4][4];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(i==j)
r[i][j]=1;
else
r[i][j]=0;
}
cout>>"\n\n w.r.t. which plane";
cout>>"\n\n\n\t 1.XY plane";
cout<<"\n\n\n\t 2.YZ plane";
cout<<"\n\n\n\t 3.XZ plane";
cout<<"\n\n\n enter ur choice";
cin>>choice;
{
Case 1:r[2][2]=-1;
break;
case 2:r[0][0]=-1;
break;
case 3:r[1][1]=-1;
break;
}
mul(a,r,b);
show(b);
}
void main()
{
int gd=DETECT,gm,choice;
char ans;
floatqb[2][4][4]={{{0,0,0,1},{50,0,0,1},{50,50,0,1},{0,50,0,1}},{{0,0,50,1},
{50,0,50,1},{50,50,50,1},{0,50,50,1}}
3
9

};
initgraph(&gd,&gm,"c:\\tc\\bgi");
do
{
cleardevice();
cout<<"\n\n\t Which transformation do u want";
cout<<"\n\n\t\t 1.Translation";
cout<<"\n\n\t\t 2.scaling";
cout<<"\n\n\t\t 3.rotation";
cout<<"\n\n\t\t 4.reflection";
cout<<"\n\n enter ur choice";
cin>>choice;
clrscr();
cleardevice();
line(320,240,320,0);
line(320,240,639,240);
line(320,240,90,470);
setcolor(4);
show(qp);
setcolor(14);
{
case 1:trans(qb);
break;
case 2:scale(qb);
break;
case 3:rot(qb);
break;
case 4:ref(qb);
break;
cout<<"\n do u want to continue\n";
cin>>ans;
}
while(ans=='Y'||ans=='Y');
getch();
closegraph();
}
OUTPUT

4
0

EXPERIMENT NO. 10
4
1

Write a program for drawing Bezier curve.


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
int gd=DETECT,gm;
float xxx[4][2];
void line 1(float x2,y2)
{
Line (xxx[0][0], xxx[0][1], x2,y2);
Xxx[0][0]=2;
Xxx[0][1]=y2;
}
Void Bezier (float XB, floatYB, float XC, float YC, floatXD, floatYD, int N)
{
Float XAB, YAB, XBC, XCD, YCD;
Float XABC, YABC, XBCD, YBCD;
Float XABCD, YABCD;
If(n==0)
{
Line 1(XB, YB);
Line 1(XC, YC);
Line 1(XD, YD);
}
Else
{
XAB=(xxx[0][0]+XB)/2;
YAB=( xxx[1][0]+YB)/2;
XBC=(XB+XC)/2;
YBC=(YB+YC)/2;
XCD=(XC+XD)/2;
XABC=(XAB+XBC)/2;
YABC(YAB+YBC)/2;
XBCD=(XBC+XCD)/2;
YBCD=(YBC+YCD)/2;
XABCD=(XABC+XBCD)/2;
YABCD=(XABC+YBCD)/2;
Bezier(XAB, YAB, XABC,YABC, XABCD, YABCD,N-1);
Bezier (XBCD, YBCD, XCD, YCD, XD.YD, N-1);
4
2

}
}
Void main()
{
Int I,n;
Clrscr();
Initgraph (&gd,&gm,c:\\tc\\bgi);
For (i=0; i<4; i++)
{
Cout<<\n enter (x,y) coordinates of point %d, i+1;
Cin>>%f%f, &xxx[i][0], xxx[i][1];
}
Cout<<enter the number of iterations for the curve \n;
Cin>>%d,&n;
Bezier(xxx[1][0], xxx[1][1], xxx[2][0], xxx[2][1], xxx[3][0], xxx[3][1], n);
Getch();
Closegraph();
}

OUTPUT

4
3

4
4

Vous aimerez peut-être aussi