c语言画直线代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
return 0;
}
else y=y+s2;
e=e-2*x0;
}
if(interchange==1) y=y+s2;
else x=x+s1;
e=e+2*y0;
}
}
int main()
{
int x1,x2,y1,y2;
Initialize();
scanf("%d,%d,%d,%d",&x1,&y1,&x2,&y2);
Bresenham(x1,y1,x2,y2);
else s2=-1;
if (y0>x0)
{
temp=x0;
x0=y0;
y0=temp;
interchange=1;
}
else interchange=0;
e=2*(y0-x0);
fHale Waihona Puke Baidur (i=0;i<=x0;i++)
{
putpixel (x,y,c);
while (e>=0)
{
if (interchange==1) x=x+s1;
ErrorCode=graphresult();
if (ErrorCode!=grOk)
{ printf("Graphics System Error:%s\n",grapherrormsg(ErrorCode));
exit(1);
}
}
void Bresenham(int x1,int y1,int x2,int y2)
#include<math.h>
#include<graphics.h>
#include <stdlib.h>
void Initialize(void)
{
int GraphDriver;
int GraphMode;
int ErrorCode;
GraphDriver=DETECT;
initgraph (&GraphDriver,&GraphMode,"");
{
int x,x0,interchange;
int y,y0,temp;
int s1,s2,i;
float e;
int c=14;
x=x1;
y=y1;
x0=abs(x2-x1);
y0=abs(y2-y1);
if ((x2-x1)>0) s1=1;
else s1=-1;
if ((y2-y1)>0) s2=1;
}
else y=y+s2;
e=e-2*x0;
}
if(interchange==1) y=y+s2;
else x=x+s1;
e=e+2*y0;
}
}
int main()
{
int x1,x2,y1,y2;
Initialize();
scanf("%d,%d,%d,%d",&x1,&y1,&x2,&y2);
Bresenham(x1,y1,x2,y2);
else s2=-1;
if (y0>x0)
{
temp=x0;
x0=y0;
y0=temp;
interchange=1;
}
else interchange=0;
e=2*(y0-x0);
fHale Waihona Puke Baidur (i=0;i<=x0;i++)
{
putpixel (x,y,c);
while (e>=0)
{
if (interchange==1) x=x+s1;
ErrorCode=graphresult();
if (ErrorCode!=grOk)
{ printf("Graphics System Error:%s\n",grapherrormsg(ErrorCode));
exit(1);
}
}
void Bresenham(int x1,int y1,int x2,int y2)
#include<math.h>
#include<graphics.h>
#include <stdlib.h>
void Initialize(void)
{
int GraphDriver;
int GraphMode;
int ErrorCode;
GraphDriver=DETECT;
initgraph (&GraphDriver,&GraphMode,"");
{
int x,x0,interchange;
int y,y0,temp;
int s1,s2,i;
float e;
int c=14;
x=x1;
y=y1;
x0=abs(x2-x1);
y0=abs(y2-y1);
if ((x2-x1)>0) s1=1;
else s1=-1;
if ((y2-y1)>0) s2=1;