Skip to content
Snippets Groups Projects
Commit e6580eff authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

ADD: draw_everything(...)

parent a26003e4
No related branches found
No related tags found
No related merge requests found
#include <stdbool.h>
#include "../utils/gfx/gfx.h" #include "../utils/gfx/gfx.h"
#include "field.h" #include "field.h"
void gfx_draw_line(struct gfx_context_t *ctxt, coordinates_t p0, coordinates_t p1, uint32_t color) { void gfx_draw_line(struct gfx_context_t *ctxt, coordinates_t p0, coordinates_t p1, uint32_t color) {
int dx = abs(p1.column - p0.column); int dx = abs(p1.column - p0.column);
int sx = p0.column < p1.column ? 1 : -1; int sx = p0.column < p1.column ? 1 : -1;
int dy = -abs(p1.row - p0.row); int dy = -abs(p1.row - p0.row);
int sy = p0.row < p1.row ? 1 : -1; int sy = p0.row < p1.row ? 1 : -1;
int error = dx + dy; int error = dx + dy;
while (true) { while (true) {
gfx_putpixel(ctxt, p0.column, p0.row, color); gfx_putpixel(ctxt, p0.column, p0.row, color);
if (p0.column == p1.column && p0.row == p1.row) if (p0.column == p1.column && p0.row == p1.row)
break; break;
int e2 = 2 * error; int e2 = 2 * error;
if (e2 >= dy) { if (e2 >= dy) {
if (p0.column == p1.column) if (p0.column == p1.column)
break; break;
error = error + dy; error = error + dy;
p0.column = p0.column + sx; p0.column = p0.column + sx;
} }
if (e2 <= dx) { if (e2 <= dx) {
if (p0.row == p1.row) if (p0.row == p1.row)
break; break;
error = error + dx; error = error + dx;
p0.row = p0.row + sy; p0.row = p0.row + sy;
} }
} }
} }
void gfx_draw_circle(struct gfx_context_t *ctxt, coordinates c, uint32_t r, uint32_t color) { void gfx_draw_circle(struct gfx_context_t *ctxt, coordinates c, uint32_t r, uint32_t color) {
int x = 0; int x = 0;
int y = r; int y = r;
int d = r - 1; int d = r - 1;
while(y >= x){ while (y >= x) {
gfx_putpixel(ctxt, c.row + x, c.column + y, color); gfx_putpixel(ctxt, c.row + x, c.column + y, color);
gfx_putpixel(ctxt, c.row + y, c.column + x, color); gfx_putpixel(ctxt, c.row + y, c.column + x, color);
gfx_putpixel(ctxt, c.row - x, c.column + y, color); gfx_putpixel(ctxt, c.row - x, c.column + y, color);
gfx_putpixel(ctxt, c.row - y, c.column + x, color); gfx_putpixel(ctxt, c.row - y, c.column + x, color);
gfx_putpixel(ctxt, c.row + x, c.column - y, color); gfx_putpixel(ctxt, c.row + x, c.column - y, color);
gfx_putpixel(ctxt, c.row + y, c.column - x, color); gfx_putpixel(ctxt, c.row + y, c.column - x, color);
gfx_putpixel(ctxt, c.row - x, c.column - y, color); gfx_putpixel(ctxt, c.row - x, c.column - y, color);
gfx_putpixel(ctxt, c.row - y, c.column - x, color); gfx_putpixel(ctxt, c.row - y, c.column - x, color);
if(d >= 2*x){ if (d >= 2 * x) {
d = d-2*x-1; d = d - 2 * x - 1;
x++; x++;
}else if(d < 2 * (r-y)){ } else if (d < 2 * (r - y)) {
d = d + 2*y-1; d = d + 2 * y - 1;
y--; y--;
}else { } else {
d = d + 2 * (y-x-1); d = d + 2 * (y - x - 1);
y--; y--;
x++; x++;
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment