📄 duobianxing.c
字号:
#include "graphics.h"
#include "math.h"
#define X 0
#define Y 1
#define Z 2
typedef float point[3];
int x=0,y=0;
void display(point * P,int n,int color)
{
float C[3][4],t,deltat;
point point1,point2;
int i,j;
setcolor(color);
for(j=0;j<3;j++)
{ C[j][0]=P[0][j];
C[j][1]=-3*P[0][j]+3*P[1][j];
C[j][2]=3*P[0][j]-6*P[1][j]+3*P[2][j];
C[j][3]=-P[0][j]+3*P[1][j]-3*P[2][j]+P[3][j];
/*C[j][0]=P[0][j]-3*P[1][j]+3*P[2][j]-P[3][j];
C[j][1]=-3*P[1][j]-6*P[2][j]+3*P[3][j];
C[j][2]=3*P[2][j]-3*P[3][j];
C[j][3]=P[3][j]; */
}
point1[X]=P[0][X];point1[Y]=P[0][Y];point1[Z]=P[0][Z];
deltat=1.0/n;
t=0.0;
for(i=1;i<=n;i++)
{ t+=deltat;
point2[X]=C[X][0]+t*(C[X][1]+t*(C[X][2]+t*C[X][3]));
point2[Y]=C[Y][0]+t*(C[Y][1]+t*(C[Y][2]+t*C[Y][3]));
point2[Z]=C[Z][0]+t*(C[Z][1]+t*(C[Z][2]+t*C[Z][3]));
line(point1[0],point1[1], point2[0],point2[1]);
point1[X]=point2[X];point1[Y]=point2[Y]; point1[Z]=point2[Z];
}
}
void zhongxing(int x,int y,int s)
{ int i;
for(i=x-5;i<=x+5;i++)
{ putpixel(i,y,s);}
for(i=y-5;i<=y+5;i++)
{ putpixel(x,i,s);
}
}
void kongdian(point * pot,int color)
{ int i;
setcolor(color);
for(i=0;i<4;i++)
{ circle(pot[i][X],pot[i][Y],3); }
}
void shuchu(char * s,int color)
{ setcolor(color);
outtextxy(0,0,s);
}
void main()
{int driver=DETECT,mode; int i=0,j,key,s=1;
point pot[4]={{100,200,0},{200,250,0},{300,200,0},{400,250,0}};
char s1[]="PLEASE CHOOSE THE CONTROL POINT",s2[]="PLEASE MOVE THE CONTROL POINT",s3[]="ESC BE PRESSED";
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"\\tc");
shuchu(s1,14);
kongdian(pot,5);
display(pot,50,4);
zhongxing(pot[i][X],pot[i][Y],2);
for(;;)
{ if(bioskey(1))
{ key=bioskey(0);
if(key==0x4d00)
{ if(s==1)
{ if(i!=3)
{zhongxing(pot[i][X],pot[i][Y],0);
i+=1;
zhongxing(pot[i][X],pot[i][Y],2);
}
}
if(s==-1)
{ display(pot,50,0);kongdian(pot,0);zhongxing(pot[i][X],pot[i][Y],0);
pot[i][X]+=1;
display(pot,50,4);kongdian(pot,5);zhongxing(pot[i][X],pot[i][Y],2);
}
}
if(key==0x011b)
{ outtextxy(0,20,s3);
break;
}
if(key==0x4b00)
{
if(s==1)
{if(i!=0)
{zhongxing(pot[i][X],pot[i][Y],0);
i-=1;
zhongxing(pot[i][X],pot[i][Y],2);}
}
if(s==-1)
{display(pot,50,0);kongdian(pot,0);zhongxing(pot[i][X],pot[i][Y],0);
pot[i][X]-=1;
display(pot,50,4);kongdian(pot,5);zhongxing(pot[i][X],pot[i][Y],2);
}
}
if(key==0x5000)
{
if(s==-1)
{display(pot,50,0);kongdian(pot,0);zhongxing(pot[i][X],pot[i][Y],0);
pot[i][Y]+=1;
display(pot,50,4);kongdian(pot,5);zhongxing(pot[i][X],pot[i][Y],2);
}
}
if(key==0x4800)
{
if(s==-1)
{display(pot,50,0);kongdian(pot,0);zhongxing(pot[i][X],pot[i][Y],0);
pot[i][Y]-=1;
display(pot,50,4);kongdian(pot,5);zhongxing(pot[i][X],pot[i][Y],2);
}
}/**/
if(key==0x1c0d)
{ if(s==1) { shuchu(s1,0);shuchu(s2,14); }
else { shuchu(s2,0);shuchu(s1,14); }
s=-s;
}
}
}
getch();
closegraph();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -