#include "graphics.h"
#include "malloc.h"
#include "math.h"
#define MULTIPLE 7
#define ROW 4
struct node{
float x,y;
};
void draw_polygon(struct node a[],int originx,int originy)
{
int n;
for (n=0;n<ROW;n++){
if (n==0) moveto(originx+a[0].x,originy-a[0].y);
lineto(originx+a[n].x,originy-a[n].y);
}
}
struct node decasteljau(struct node p[],int n,float u)
{
int i,r;
struct node point,q[20];
for(i=0;i<n;i++)
q[i]=p[i];
for(r=1;r<n;r++)
for(i=0;i<n-r;i++){
q[i].x=(1.0-u)*q[i].x+u*q[i+1].x;
q[i].y=(1.0-u)*q[i].y+u*q[i+1].y;
}
return q[0];
}
void draw_bezier_curve(struct node p[],int n,int x0,int y0)
{
int i,x,y;
float u,delta;
struct node point;
delta=1.0/(float)(MULTIPLE*ROW);
for(i=0,u=0;u<=1.0;i++,u=u+delta){
point=decasteljau(p,n,u);
if(i==0)moveto(x0+point.x,y0-point.y);
lineto(x0+point.x,y0-point.y);
}
}
main()
{
int gdriver=DETECT,gmode;
int number,n,originx,originy;
struct node a[]={{120,0},{45,0},{0,45},{0,120}};
initgraph(&gdriver,&gmode,"");
originx=getmaxx()/2;
originy=getmaxy()/2;
setcolor(BLUE);
draw_polygon(a,originx,originy);
setcolor(RED);