我想要一个计算机图形学的程序,什么算法都行,要没有错误的,网上有很多,不过拿过来运行一下,都有一定的错误量,我用的是torbc,请高手帮一下,谢谢!!!
你想要什么嘛,我这学期也学了计算机图形学的,什么直线圆啊我都有#include<graphics.h>#include<math.h>void Put(int x,int y,int w,int c){int i,j;j=w/2; for(i=y-j;i<=y+j;i++) putpixel(x,i,c); }void BresenhamLine(int x1,int y1,int x2,int y2,int width,int color){int dx,dy,x,y,d,d1,d2,inc,tmp;dx=x2-x1;dy=y2-y1;if(dx*dy>=0)inc=1;else inc=-1;if(abs(dx)>abs(dy)){if(dx<0){tmp=x1;x1=x2;x2=tmp;tmp=y1;y1=y2;dx=-dx;dy=-dy;}d=2*dy-dx;d1=2*dy;d2=2*(dy-dx);x=x1;y=y1;Put(x,y,width,color);while(x<x2){x++;if(d<0)d+=d1;else{y+=inc;d+=d2;}Put(x,y,width,color);}}else{if(dy<0){tmp=x1;x1=x2;x2=tmp;tmp=y1;y1=y2;dx=-dx;dy=-dy;}d=2*dx-dy;d1=2*dx;d2=2*(dx-dy);x=x1;y=y1;Put(x,y,width,color);while(y<y2){y++;if(d<0)d+=d1;else{x+=inc;d+=d2;}Put(x,y,width,color);}}}void main(){int gdriver=DETECT,gmode,x1,x2,y1,y2,c,w;initgraph(&gdriver,&gmode,"");printf("Please enter the point of head and rear:");scanf("%d%d%d%d",&x1,&y1,&x2,&y2);printf("the color:");scanf("%d",&c);printf("the width:");scanf("%d",&w);BresenhamLine(x1,y1,x2,y2,w,c);getch();closegraph();} |
|