#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<process.h>
int gd,gm,maxx,maxy;
float xx[4][2];
void line1(float x2,float y2)
{
line(xx[0][0],xx[0][1],x2,y2);
xx[0][0]=x2;
xx[0][1]=y2;
}
void besier(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)
{
line1(xb,yb);
line1(xc,yc);
line1(xd,yd);
}
else
{
xab=(xx[0][0]+xb)/2;
yab=(xx[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;
yabcd=(yabc+ybcd)/2;
n=n-1;
besier(xab,yab,xabc,yabc,xabcd,yabcd,n);
besier(xbcd,ybcd,xcd,ycd,xd,yd,n);
}
}
void igraph()
{
detectgraph(&gd,&gm);
if(gd<0)
{
puts("Cannot detect driver card");
exit(0);
}
initgraph(&gd, &gm, "Z:/Tc/BGI");
}
void main()
{
int i;
float temp1, temp2;
igraph();
for(i=0;i<4;i++)
{
printf("Enter the co-ordinates of the point %d\n", i+1);
scanf("%f %f", &temp1, &temp2);
xx[i][0]= temp1;
xx[i][1]= temp2;
}
besier(xx[1][0], xx[1][1], xx[2][0], xx[2][1], xx[3][0], xx[3][1], 4);
getch();
closegraph();
}
0 comments :