BEZIER CURVE IN COMPUTER GRAPHICS


#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<iostream.h>
#include<stdlib.h>
int gd,gm,maxx,maxy;
float X[4][2];
void line(float x2,float y2)
{
line(X[0][0],X[0][1],x2,y2);
X[0][0]=x2;
X[0][1]=y2;
}
void bezier(float xb,float yb,float xc,float yc,float xd,float yd,int n)
{
float xab,yab,xbc,ybc,xcd,ycd;
float xabc,yabc,xbcd,ybcd;
float xabcd,yabcd;
if(n==0)
{
line(xb,yb);
delay(20);
line(xc,yc);
delay(20);
line(xd,yd);
delay(20);
}
else
{
xab=(X[0][0]+xb)/2 ;
yab=(X[0][1]+yb)/2 ;
xbc=(xb+xc)/2 ;
ybc=(yb+yc)/2;
xcd=(xc+xd)/2 ;
ycd=(yc+yd)/2 ;
xabc=(xab+xbc)/2;
yabc=(yab+ybc)/2 ;
xbcd=(xbc+xcd)/2;
ybcd=(ybc+ycd)/2;
xabcd=(xabc+xbcd)/2;
n=n-1;
bezier(xab,yab,xabc,yabc,xabcd,yabcd,n);
bezier(xbcd,ybcd,xcd,ycd,xd,yd,n);
}
}
void igraph()
{
detectgraph(&gd,&gm);
if(gd<0)
{
printf("\n \t cannot detect a graphics card!!!");
exit(1);
}
initgraph(&gd,&gm,"");
}
void main()
{
int i;
float temp1,temp2;
igraph();
for(i=0;i<4;i++)
{
printf("\n\n enter the Xcoordinates of point");
scanf("%d",&temp1);
      printf("\n\n enter the ycoordinates of point");
scanf("%d",&temp2);
X[i][0]=temp1;
X[i][1] =temp2;
}
cleardevice();
setcolor(10);
for(i=0;i<3;i++)
{
line(X[i][0],X[i][1],X[i+1][0],X[i+1][1]);
}
setcolor(9);
outtextxy(50,50,"Bezier curve");
bezier(X[1][0],X[1][1],X[2][0],X[2][1],X[3][0],X[3][1],8);
getch();
closegraph();
}

Comments

Popular posts from this blog

REFLECTION OF A TRIANGLE (COMPUTER GRAPHICS)