Advertisement
Shailrshah

House by DDA Line Drawing Algorithm

Jul 23rd, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <graphics.h>
  4.  
  5. void dda(float x1, float y1, float x2, float y2){
  6.     detectgraph(&gd,&gm);
  7.     initgraph(&gd,&gm,"C:\\TC\\BGI");
  8.        
  9.     float x, y, dx, dy, length;
  10.     int i, intx, inty;
  11.     abs(x2 - x1) > abs(y2 - y1) ? (length = abs(x2 - x1)) : (length = abs(y2 - y1));
  12.     dx = (x2 - x1) / length;
  13.     dy = (y2 - y1) / length;
  14.     dx >= 0 ? (x = x1 + 0.5) : (x = x1 - 0.5);
  15.     dy >= 0 ? (y = y1 + 0.5) : (y = y1 - 0.5);
  16.     for(i = 0, intx = x, inty = y; i <= length; i++, x += dx, y += dy, intx = x, inty = y)
  17.         putpixel(intx, inty, 30);
  18.  
  19.     delay(100);
  20. }
  21. int main(){
  22.     dda(50,100,100,100);
  23.     dda(50,100,50, 50);
  24.     dda(100, 100, 100, 50);
  25.     dda(50, 50, 75, 0);
  26.     dda(100, 50, 75, 0);
  27.     dda(100, 50, 50, 50);
  28.     closegraph();
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement