diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2017-12-28 21:52:04 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2017-12-28 21:52:04 +0100 |
commit | 3282ab0cd838ab7e070021cd2a537d78e60d263a (patch) | |
tree | a05ead754b3dd1ac8bf2dc9549c77d5ab135d238 /src/line.c |
Imported sources files into the Git
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'src/line.c')
-rw-r--r-- | src/line.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/line.c b/src/line.c new file mode 100644 index 0000000..6f0f749 --- /dev/null +++ b/src/line.c @@ -0,0 +1,56 @@ +/* +** line.c for in /home/gayot_o/prog/lib/sdl-digit +** +** Made by olivier gayot +** Login <gayot_o@epitech.net> +** +** Started on Mon Apr 23 08:07:45 2012 olivier gayot +** Last update Mon Apr 23 08:07:45 2012 olivier gayot +*/ + +#include "sdl_digit.h" + +static void perform_draw_line(SDL_Surface *, SDL_Rect, SDL_Rect, t_vect, Uint32); + +void draw_line(SDL_Surface *surf, SDL_Rect r1, SDL_Rect r2, Uint32 color) { + t_vect vect; + SDL_Rect begin, end; + + if (ABS(r2.x - r1.x) > ABS(r2.y - r1.y)) { + if (r1.x < r2.x) { + begin = r1; + end = r2; + } + else { + begin = r2; + end = r1; + } + vect.x = 1; + vect.y = (float)(end.y - begin.y) / (float)(end.x - begin.x); + } + else { + if (r1.y < r2.y) { + begin = r1; + end = r2; + } + else { + begin = r2; + end = r1; + } + vect.y = 1; + vect.x = (float)(end.x - begin.x) / (float)(end.y - begin.y); + } + perform_draw_line(surf, begin, end, vect, color); +} + +static void perform_draw_line(SDL_Surface *surf, SDL_Rect begin, + SDL_Rect end, t_vect vect, Uint32 color) { + float x = (float)begin.x; + float y = (float)begin.y; + + while (x != (float)end.x || y != (float)end.y) { + set_pixel_color(surf, (int)x, (int)y, color); + x += vect.x; + y += vect.y; + } +} |