- #include<iostream.h>
- #include<conio.h>
- #include<graphics.h>
- #include<math.h>
- #include<dos.h>
- void main()
- {
- clrscr();
- int x1,y1,x2,y2,i=1; float x,y,dx,dy,len;
- detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:\\tc\\bgi");
- textbackground(15); textcolor(15); 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);
- if(dy>dx)len=dy;
- else len=dx;
- dx=((x2-x1)/len);
- dy=((y2-y1)/len);
- x=x1+0.5*dx; y=y1+0.5*dy; while(i<=len)
- {
- putpixel(getmaxx()/2+x,getmaxy()/2-y,8);
- }
- x+=dx; y+=dy; i++;
- delay(20);
- }
- getch();
Thursday, June 21, 2018
DDA algorithm (Implementation of line drawing algorithm)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment