Graphic Design | Digital Differential Analyzer (DDA) Algorithm


/ Published in: C
Save to your folder(s)

This is an implementation of the DDA (Digital Differential Analyzer) Algorithm in Computer Graphics Design in the C programming language.


Copy this code and paste it in your HTML
  1. //Shubham Mehta, Write a program to implement Digital Differential Analyzer Algorithm.
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<graphics.h>
  5. void main()
  6. {
  7. int gd, gm;
  8. float x, y, x1, x2, y1, y2, slope;
  9. clrscr();
  10. printf("%s", "Please enter x1: ");
  11. scanf("%f", &x1);
  12. printf("%s", "Please enter y1: ");
  13. scanf("%f", &y1);
  14. printf("%s", "Please enter x2: ");
  15. scanf("%f", &x2);
  16. printf("%s", "Please enter y2: ");
  17. scanf("%f", &y2);
  18. slope=(y2-y1)/(x2-x1);
  19. gd=DETECT, gm;
  20. initgraph(&gd, &gm, "C:\\TC\\BGI");
  21. if(slope<1)
  22. {
  23. for(; x1<=x2; x1++)
  24. {
  25. y1+=slope;
  26. putpixel(x1, y1, RED);
  27. }
  28. }
  29. else
  30. {
  31. for(; y1<=y2; y1++)
  32. {
  33. x1+=slope;
  34. putpixel(x1, y1, RED);
  35. }
  36. }
  37. getch();
  38. closegraph();
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.