diff --git a/graphics.c b/graphics.c index b530165..1f6240e 100644 --- a/graphics.c +++ b/graphics.c @@ -38,32 +38,42 @@ void dot(Canvas* c, uint x, uint y){ * Draws a line from (start_x, start_y) to (end_x, end_y) */ void line(Canvas* c, uint start_x, uint start_y, uint end_x, uint end_y){ -#ifndef abs -#define abs(x) ((x<0)?(-x):(x)) - int dx = abs(end_x - start_x); - int dy = abs(end_y - start_y); + int dx = end_x - start_x; + int dy = end_y - start_y; + if (dx<0) dx *= -1; + if (dy<0) dy *= -1; + dx++; + dy++; + + if((dx>=dy && start_x>end_x) || ( dxend_y)){ + int temp; + + temp = end_x; + end_x = start_x; + start_x = temp; + + temp = end_y; + end_y = start_y; + start_y = temp; + } int direction_x = start_x < end_x ? 1 : -1; int direction_y = start_y < end_y ? 1 : -1; - printf("dx:%i dy:%i direction:%i,%i \n", dx, dy, direction_x, direction_y); - if(dx>=dy){ float small = direction_y * (float)dy/(float)dx; - for(int i=0; i