DDA算法画直线求助
我写了一个用DDA算法画直线得程序,但是一直显示不了图形,实在找不出问题了,望各位大虾指点一二,小弟不胜感激,叩谢了!!假设编译程序TC(版本2。0)在C盘,源程序如下:
#include "graphics.h"
#include "stdio.h"
#include "conio.h"
main()
{
int gdriver=DETECT,gmode;
int x0,y0,x1,y1colour=WHITE;
initgraph(&gdriver,&gmode,"c:\\TC\\bgi");
scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
DDNline(x0,y0,x1,y1,colour);
getchar();
closegraph();
return(0);
}
int DDNline(int x0,int y0,int x1,int y1,int colour)
{
int i;
float dx,dy,length,x,y;
if(fabs(x0-x1)>=fabs(y0-y1))
length=fabs(x0-x1);
else length=fabs(y0-y1);
dx=(x1-x0)/length;
dy=(y1-y0)/length;
x=x0;
y=y0;
for(i=1;i<=length;i++)
{
putpixel((int)(x+0.5),(int)(y+0.5),colour);
x=x+dx;
y=y+dy;
}
}
页:
[1]