0% found this document useful (0 votes)
7 views

Dda Line

Uploaded by

pritish8754
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Dda Line

Uploaded by

pritish8754
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DDA Line Drawing program

#include<graphics.h>

1. #include<conio.h>

2. #include<stdio.h>

3. void main()

4. {

5. int gd= DETECT ,gm, i;

6. float x, y,dx,dy,steps;

7. int x0, x1, y0, y1;

8. initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

9. setbkcolor(WHITE);

10. x0 = 100 , y0 = 200, x1 = 500, y1 = 300;

11. dx = (float)(x1 - x0);

12. dy = (float)(y1 - y0);

13. if(dx>=dy)

14. {

15. steps = dx;

16. }

17. else

18. {

19. steps = dy;

20. }

21. dx = dx/steps;

22. dy = dy/steps;

23. x = x0;

24. y = y0;

25. i = 1;

26. while(i<= steps)


27. {

28. putpixel(x, y, RED);

29. x += dx;

30. y += dy;

31. i=i+1;

32. }

33. getch();

34. closegraph();

35. }

Solve on paper

1) (3,3) to (11,19)
2) (5,5) to (10,10)
3) (1,1) to (10,5)

You might also like