求助,急,在线等

zjunxt 2003-04-10 09:06:42
小弟正在学计算机图形学,请各位大哥给出一个用画线法画直线的源代码(不是用画线函数直接画的),我用的编译器是turboc 3.0 for DOS 在线等,谢谢
...全文
22 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjunxt 2003-04-10
  • 打赏
  • 举报
回复
我在程序中加上了registerbgidriver(EGAVGA_driver);但连接时显示EGAVGA_driver没有定义
zjunxt 2003-04-10
  • 打赏
  • 举报
回复
我的程序运行后显示 bgi error graphics not initialized(ues 'initgraph')
请问这是什么意思,怎么解决
程序如下:
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
int drawline(int strx,int stry,int endx,int endy);
int main()
{
int strx,stry;
int endx,endy;
cout<<"This is a drawline function"<<endl;
cout<<"Please input the start x coordinate:";
cin>>strx;
cout<<endl<<"Please input the start y coordinate:";
cin>>stry;
cout<<endl<<"please input the end x coordinate:";
cin>>endx;
cout<<endl<<"please input the end y coordinate:";
cin>>endy;
drawline(strx,stry,endx,endy);
return 0;

}
int drawline(int strx,int stry,int endx,int endy)
{
int driver=DETECT,mode;
int a,b,delta1,delta2,d,x,y,k;
int color=RED;
setcolor(BLUE);
initgraph(&driver,&mode,"");
k=(endy-stry)/(endx-strx);
if(k>0)
{
a=stry-endy;
b=endx-strx;
d=2*a+b;
delta1=2*a;
delta2=2*(a+b);
x=strx;
y=stry;
putpixel(x,y,color);
while(x<endx)
{
if(d<0)
{
x++;
y++;
d+=delta2;
}
else
{
x++;
d+=delta1;
}
putpixel(x,y,color);
}
}
getch();
closegraph();
return 0;
}

lwbhero 2003-04-10
  • 打赏
  • 举报
回复
#include<math.h>
#include<graphics.h>
int zhixian(int x1,int y1,int x2,int y2)
{
int dx,dy,dk,i,flag1,flag2,color=1;
dx=x2-x1;
dy=y1-y2;
if(!dx){ if(!dy){ putpixel(x1,y1,color);
return 0;
}
else
for(i=0,flag2=dy/abs(dy);i<=abs(dy);i++)
{ putpixel(x1,y2,color);
y2+=flag2;
}
return 0;
}
if(!dy){
for(i=0,flag1=dx/abs(dx);i<=abs(dx);i++)
{ putpixel(x1,y2,color);
x1+=flag1;
}
return 0;
}
flag1=dx/abs(dx);
flag2=dy/abs(dy);
if(fabs(double(dy)/double(dx))<=1)
{ dk=-2*dy-dx;
for(i=0;i<=abs(dx);i++)
{ putpixel(x1,y1,color);
x1+=flag1;
dk=dk+2*dy*flag2;
if(dk>=0)
{ y1-=flag2;
dk=dk-2*dx*flag1;
}
}
}
else{ dk=-2*dx-dy;
for(i=0;i<=abs(dy);i++)
{ putpixel(x1,y1,color);
y1-=flag2;
dk=dk+2*dx*flag1;
if(dk>=0)
{ x1+=flag1;
dk=dk-2*dy*flag2;
}
}
}
return 0;
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧