计算机图形学问题,在C++环境下编写程序,希望给出完整代码
2013-06-25
展开全部
这个要你自己给出起点和终点:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
void swap_start_end(int &x1,int &y1,int &x2,int &y2);
void s_line(int x1,int y1,int x2,int y2);
main()
{
int x1,y1,x2,y2;
printf("Please input the start dot:\n");
scanf("%d%d",&x1,&y1);
printf("Please input the end dot:\n");
scanf("%d%d",&x2,&y2);
swap(x1,y1,x2,y2);
s_line(x1,y1,x2,y2);
}
void swap_start_end(int &x1,int &y1,int &x2,int &y2)
{
int mid;
mid=x1;
x1=y1;
y1=mid;
mid=x2;
x2=y2;
y2=mid;
}
void s_line(int x1,int y1,int x2,int y2)
{
int driver=DETECT,mode;
int curx,cury,dx,dy,tx,ty,mid,d,flag,i;
initgraph(&driver,&mode,"");
curx=x1;
cury=y1;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(x2-x1>=0)
tx=1;
else
tx=-1;
if(y2-y1>=0)
ty=1;
else
ty=-1;
if(dx>dy)
flag=0;
else
{
flag=1;
mid=dx;dx=dy;dy=mid;
mid=tx;tx=ty;ty=mid;
mid=x1;x1=y1;y1=mid;
mid=x2;x2=y2;y2=mid;
}
if(flag)
putpixel(cury,curx,2);
else
putpixel(curx,cury,2);
d=2*dy-dx;
for(i=0;i<dx;i++)
{
if(d>=0)
{
d=d+2*(dy-dx);
cury+=ty;
}
else
d=d+2*dy;
curx+=tx;
if(flag)
putpixel(cury,curx,2);
else
putpixel(curx,cury,2);
}
getch();
closegraph();
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
void swap_start_end(int &x1,int &y1,int &x2,int &y2);
void s_line(int x1,int y1,int x2,int y2);
main()
{
int x1,y1,x2,y2;
printf("Please input the start dot:\n");
scanf("%d%d",&x1,&y1);
printf("Please input the end dot:\n");
scanf("%d%d",&x2,&y2);
swap(x1,y1,x2,y2);
s_line(x1,y1,x2,y2);
}
void swap_start_end(int &x1,int &y1,int &x2,int &y2)
{
int mid;
mid=x1;
x1=y1;
y1=mid;
mid=x2;
x2=y2;
y2=mid;
}
void s_line(int x1,int y1,int x2,int y2)
{
int driver=DETECT,mode;
int curx,cury,dx,dy,tx,ty,mid,d,flag,i;
initgraph(&driver,&mode,"");
curx=x1;
cury=y1;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(x2-x1>=0)
tx=1;
else
tx=-1;
if(y2-y1>=0)
ty=1;
else
ty=-1;
if(dx>dy)
flag=0;
else
{
flag=1;
mid=dx;dx=dy;dy=mid;
mid=tx;tx=ty;ty=mid;
mid=x1;x1=y1;y1=mid;
mid=x2;x2=y2;y2=mid;
}
if(flag)
putpixel(cury,curx,2);
else
putpixel(curx,cury,2);
d=2*dy-dx;
for(i=0;i<dx;i++)
{
if(d>=0)
{
d=d+2*(dy-dx);
cury+=ty;
}
else
d=d+2*dy;
curx+=tx;
if(flag)
putpixel(cury,curx,2);
else
putpixel(curx,cury,2);
}
getch();
closegraph();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-25
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询