Write maze drawing procedure

This commit is contained in:
Camden Dixie O'Brien 2024-11-03 19:52:28 +00:00
parent 560d9f48b6
commit 9646a67faa

38
main.c
View File

@ -18,6 +18,40 @@
#define PX(x) ((x) << 3) #define PX(x) ((x) << 3)
typedef struct {
bool cells[GRID_SIZE][GRID_SIZE];
} maze_t;
static void draw_maze(Display *dpy, Window w, GC gc, const maze_t *m)
{
// Draw walls
XFillRectangle(
dpy, w, gc, PX(MARGIN), PX(MARGIN), PX(GRID_SIZE + 2),
PX(WALL_THICKNESS));
XFillRectangle(
dpy, w, gc, PX(MARGIN), PX(MARGIN + WALL_THICKNESS + GRID_SIZE),
PX(GRID_SIZE + 2), PX(WALL_THICKNESS));
XFillRectangle(
dpy, w, gc, PX(MARGIN), PX(MARGIN + WALL_THICKNESS + 1),
PX(WALL_THICKNESS), PX(GRID_SIZE - 1));
XFillRectangle(
dpy, w, gc, PX(MARGIN + WALL_THICKNESS + GRID_SIZE),
PX(MARGIN + WALL_THICKNESS), PX(WALL_THICKNESS), PX(GRID_SIZE));
// Draw cells
for (int x = 0; x < GRID_SIZE; ++x) {
for (int y = 0; y < GRID_SIZE; ++y) {
if (m->cells[x][y])
continue;
const int left = PX(MARGIN + WALL_THICKNESS + x);
const int top = PX(MARGIN + WALL_THICKNESS + y);
XFillRectangle(dpy, w, gc, left, top, PX(1), PX(1));
}
}
XFlush(dpy);
}
int main(void) int main(void)
{ {
XEvent evt; XEvent evt;
@ -42,6 +76,10 @@ int main(void)
XNextEvent(dpy, &evt); XNextEvent(dpy, &evt);
while (MapNotify != evt.type); while (MapNotify != evt.type);
maze_t m;
memset(&m, 0, sizeof(maze_t));
draw_maze(dpy, w, gc, &m);
// Wait for window exit // Wait for window exit
bool is_del = false; bool is_del = false;
do { do {