repl.it
@candh/

bresnham test

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 #include <stdio.h>  
 #include <math.h>

 void drawline(int x0, int y0, int x1, int y1)  
 {  
     int dx, dy, p, x, y;  
     dx=x1-x0;  
     dy=y1-y0;  
     x=x0;  
     y=y0;  
     p=2*dy-dx;  

		printf("%d %d", dy, dx);
		if (abs(dy / dx) > 1) {
			// steep
			printf("steep");
		}
		printf("%d %d\n", x, y);
     while(x<x1)  
     {  
         if(p>=0) {  
             y=y+1;  
             p=p+2*dy-2*dx;  
         } else {  

             p=p+2*dy; 
				 }  
             x=x+1;  
	 	  printf("%d %d\n", x, y);
     }  
 }  

 int main() {  
     int  error, x0, y0, x1, y1;  
     printf("Enter co-ordinates of first point: ");  
     scanf("%d%d", &x0, &y0);  
     printf("Enter co-ordinates of second point: ");  
     scanf("%d%d", &x1, &y1);  
     drawline(x0, y0, x1, y1);  
     return 0;  
 }  
Fetching token
?