Advertisement
namkongkirat

DDA Line Drawing

Jun 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<graphics.h>
  3. #include<math.h>
  4. #include<dos.h>
  5. #include<conio.h>
  6.  
  7.  
  8.  
  9. int ROUND(float a){
  10.     a=a+0.5;
  11.     return ((int)a);
  12. }
  13.  
  14. void lineDDA(int x1, int y1, int x2, int y2){
  15.      int dx=x2-x1,dy=y2-y1, steps, k;
  16.      float xincrement, yincrement, x=x1, y=y1;
  17.      if(abs(dx)>abs(dy))steps=abs(dx);
  18.      else steps=abs(dy);
  19.       xincrement=dx/(float)steps;
  20.       yincrement=dy/(float)steps;
  21.       putpixel(ROUND(x), ROUND(y),5);
  22.      for(k=0;k<steps;k++){
  23.               delay(50);
  24.               x+=xincrement;
  25.               y+=yincrement;
  26.               putpixel (ROUND(x), ROUND(y), 5);
  27.               }
  28. }
  29.  
  30.  
  31. void main()
  32. {
  33.     int x1,y1,x2,y2,gmode,gdriver=DETECT;
  34.     initgraph(&gdriver, &gmode,"C:\\TURBOC3\\BGI");
  35.  
  36.     printf("Enter the Start point.");
  37.     scanf("%d%d",&x1,&y1);
  38.     printf("Enter the End point.");
  39.     scanf("%d%d",&x2,&y2);
  40.     clrscr();
  41.     lineDDA(x1,y1,x2,y2);
  42.     getch();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement