- #include<iostream.h>
- #include<conio.h>
- #include<graphics.h>
- #include<math.h>
- #include<dos.h>
- void main()
- {
- clrscr();
- int gm,gd;
- int x1,y1,x2,y2,i;
- float x,y,dx,dy,len,e;
- detectgraph(&gd,&gm);
- initgraph(&gd,&gm,"c:\\tc\\bgi");
- //textbackground(15);
- //textcolor(8);
- //setbkcolor(15);
- //setcolor(8);
- cout<<"Enter starting pixels for point (x1,y1): "; cin>>x1>>y1;
- cout<<"\nEnter ending pixels for point (x2,y2): "; cin>>x2>>y2;
- line(0,getmaxy()/2,getmaxx(),getmaxy()/2); line(getmaxx()/2,0,getmaxx()/2,getmaxy());dx=abs(x2-x1);
- dy=abs(y2-y1);
- x=x1;
- y=y1;
- e=2*dy-dx;
- for(i=1;i<=dx;i++)
- {
- putpixel(getmaxx()/2+x,getmaxy()/2-y,8); while(e>=0)
- {
- y++;
- e-=2*dx;
- delay(20)
- }
- x++;
- e+=2*dy;
- }
- getch();
- }
Thursday, June 21, 2018
Bresenham's algorithm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment