当前位置: 代码迷 >> C语言 >> 急急急,高手指点....
  详细解决方案

急急急,高手指点....

热度:220   发布时间:2008-05-27 17:18:19.0
急急急,高手指点....
#include "graphics.h"
#include "display.h"
#include "math.h"
#define N 6
#define UPDRAW(x,y) moveto(x,y)
#define UNDRAW(x,y) lineto(x,y)

void B2_curves(char pflag,long xq[2][2],int m,long lxx,long lyy)
{

int i,j;
long lx1,ly1;
double t0,t1,t2;
lx1=(xq[0][0]+xq[1][0])/2+lxx;
ly1=(xq[0][1]+xq[1][1])/2+lyy;
if(pflag=='p')
{
for(i=1;i<m;i++)
for(j=0;j<=10;j++)
{
t2=1.0*j/10;
  t0=1-t2;
  t0=0.5*t0*t0;
  t1=0.5*(1.0+(2.0-2.0*t2)*t2);
  t2=1.0-t0-t1;
  lx1=xq[i-1][0]*t0+xq[i][0]*t1+xq[i+1][0]*t2+lxx;
  ly1=xq[i-1][1]*t0+xq[i][1]*t1+xq[i+1][1]*t2+lyy;
  if(pflag=='p')UNDRAW(lx1,ly1);
  }
  }
}
void main(void)
{
static long p[N+2][2]={50,400,100,120,260,180,500,120,600,300,590,420,50,400,100,120};
int i, color;
Initialize();
color=WHITE;
  setcolor(color);
moveto(p[0][0],p[0][1]);
for(i=1;i<N;i++)
  lineto(p[i][0],p[i][1]);
setcolor(BLUE);
B2_curves('p',p,N-1,0,0);
while(getch()!=ESC);
setcolor(RED);
p[0][0]=2*p[0][0]-p[1][0];
p[0][1]=2*p[0][1]-p[1][1];
p[N-1][0]=2*p[N-1][0]-p[N-2][0];
p[N-1][1]=2*p[N-1][1]-p[N-2][1];
B2_curves('p',p,N-1,0,0);
while(getch()!=ESC);
setcolor(GREEN);
p[0][0]=50;
p[0][1]=400;
p[N-1][0]=590; p[N-1][1]=420;
B2_curves('p',p,N+1,0,0);
while(getch()!=ESC);
closegraph();
}
还有一个错误,谁来帮我看看,谢谢
----------------解决方案--------------------------------------------------------
这种代码你想叫别人怎么看啊??
特别是你用TC的,我根本懒得去编译一下看结果了
TC的10有9在现代的编译器上过不了,特别是graphics。。。。

[color=white]
----------------解决方案--------------------------------------------------------
LS..........申请这么多号,当真不要钱啊???
----------------解决方案--------------------------------------------------------
代码有些难度呃,不过主要的错误找到了。
要注意的是,ESC用getchar()是无法得到的。所要要使用,bioskey(int cmd) 来判断按键。
还有就是 头文件 display.h 是自定义的。
程序代码:

#include "graphics.h"
#include "display.h"
#include "math.h"
#define N 6
#define UPDRAW(x,y) moveto(x,y)
#define UNDRAW(x,y) lineto(x,y)

void B2_curves(char pflag,long xq[2][2],int m,long lxx,long lyy)
{

int i,j;
long lx1,ly1;
double t0,t1,t2;
lx1=(xq[0][0]+xq[1][0])/2+lxx;
ly1=(xq[0][1]+xq[1][1])/2+lyy;
if(pflag=='p')
{
for(i=1;i<m;i++)
for(j=0;j<=10;j++)
{
t2=1.0*j/10;
  t0=1-t2;
  t0=0.5*t0*t0;
  t1=0.5*(1.0+(2.0-2.0*t2)*t2);
  t2=1.0-t0-t1;
  lx1=xq[i-1][0]*t0+xq[i][0]*t1+xq[i+1][0]*t2+lxx;
  ly1=xq[i-1][1]*t0+xq[i][1]*t1+xq[i+1][1]*t2+lyy;
  if(pflag=='p')UNDRAW(lx1,ly1);
  }
  }
}
void main(void)
{
static long p[N+2][2]={50,400,100,120,260,180,500,120,600,300,590,420,50,400,100,120};
int i, color;
Initialize();
color=WHITE;
  setcolor(color);
moveto(p[0][0],p[0][1]);
for(i=1;i<N;i++)
  lineto(p[i][0],p[i][1]);
setcolor(BLUE);
B2_curves('p',p,N-1,0,0);
while(bioskey(0)==0x11B);
setcolor(RED);
p[0][0]=2*p[0][0]-p[1][0];
p[0][1]=2*p[0][1]-p[1][1];
p[N-1][0]=2*p[N-1][0]-p[N-2][0];
p[N-1][1]=2*p[N-1][1]-p[N-2][1];
B2_curves('p',p,N-1,0,0);
while(bioskey(0)==0x11B);
setcolor(GREEN);
p[0][0]=50;
p[0][1]=400;
p[N-1][0]=590; p[N-1][1]=420;
B2_curves('p',p,N+1,0,0);
while(bioskey(0)==0x11B);
closegraph();
}

----------------解决方案--------------------------------------------------------
谢谢,谢谢,由于论文的需要,只有用TC谢谢,谢谢大家了
----------------解决方案--------------------------------------------------------
LZ+LS:你可以在别的地方写了编译了,最后放TC里面编译验证的嘛……
----------------解决方案--------------------------------------------------------
  相关解决方案