C Program For Bressenhams Line Drawing Algorithm Source Code: #include<graphics.h> #include<stdio.h> #include<math.h> #include<conio.h> void bshmLine(int x1,int y1,int x2,int y2) { int x=x1,y=y1,dx,dy,s1,s2; int length,i,dp,temp,swap=0; putpixel(x1,y1,WHITE); dx=abs(x2-x1); dy=abs(y2-y1); if(x2x1) s1=1; else s1=0; if(y2 y1) s2=1; else s2=0; dp=2*dy-dx; if(dy>dx) { temp=dx; dx=dy; dy=temp; swap=1; } for(i=1;i<=dx;i++) { if(dp<0) { if(swap) putpixel(x,y=y+s2,WHITE); else putpixel(x=x+s1,y,WHITE); dp+=2*dy; } else { putpixel(x=x+s1,y=y+s2,WHITE); dp=dp+2*dy-2*dx; } } } void main() { int x1,y1,x2,y2; int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "c:/tc/bgi"); printf("Enter the starting co-ordinates: "); scanf("%d %d",&x1,&y1); printf("Enter the ending co-ordinates: "); scanf("%d %d",&x2,&y2); bshmLine(x1,y1,x2,y2); getch(); }
Tags:
Graphics& Multimedia
1 comments
Nice post. check this out fun time for tweenskids doodle
ReplyDelete