Advertisement
zoro-10

4B. Develop the program for Bresenham’s Line drawing algorithm

Apr 1st, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. void main()
  5. {
  6. int dx,dy,x,y,p,x1,y1,x2,y2;
  7. int gd=DETECT,gm;
  8. clrscr();
  9. initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
  10. printf("\n\n\tEnter the co-ordinates of first point : ");
  11. scanf("%d %d",&x1,&y1);
  12. printf("\n\n\tEnter the co-ordinates of second point : ");
  13. scanf("%d %d",&x2,&y2);
  14. dx = (x2 - x1);
  15. dy = (y2 - y1);
  16. p = 2 * (dy) - (dx);
  17. x = x1;
  18. y = y1;
  19. putpixel(x,y,WHITE);
  20. while(x <= x2)
  21. {
  22. if(p < 0)
  23. {
  24. x=x+1;
  25. y=y;
  26. p = p + 2 * (dy);
  27. }
  28. else
  29. {
  30. x=x+1;
  31. y=y+1;
  32. p = p + 2 * (dy - dx);
  33. }
  34. putpixel(x,y,WHITE);
  35. }
  36. getch();
  37. closegraph();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement