Advertisement
zoro-10

4A. Develop the program for DDA Line drawing algorithm

Apr 1st, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<graphics.h>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<math.h>
  5. #include<dos.h>
  6. void main()
  7. {
  8. float x,y,x1,y1,x2,y2,dx,dy,step;
  9. int i,gd=DETECT,gm;
  10. initgraph(&gd,&gm,"c:\\turboc3\\bgi");
  11. printf("Enter the value of x1 and y1 : ");
  12. scanf("%f%f",&x1,&y1);
  13. printf("Enter the value of x2 and y2: ");
  14. scanf("%f%f",&x2,&y2);
  15. dx=abs(x2-x1);
  16. dy=abs(y2-y1);
  17. if(dx>=dy)
  18. step=dx;
  19. else
  20. step=dy;
  21. dx=dx/step;
  22. dy=dy/step;
  23. x=x1;
  24. y=y1;
  25. i=1;
  26. while(i<=step)
  27. {
  28. putpixel(x,y,5);
  29. x=x+dx;
  30. y=y+dy;
  31. i=i+1;
  32. delay(100);
  33. }
  34. getch();
  35. closegraph();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement