first commit

This commit is contained in:
Sheldon Lee
2020-06-12 02:46:44 +01:00
commit e14c7e8576
6 changed files with 147 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#include <stdlib.h>
#include "grid.h"
// maps x, y coordinate to array index of grid
unsigned int toIndex(Grid* grid, int x, int y)
{
return (grid->width*y + x)%grid->size;
}
void clearGrid(Grid* grid)
{
for (int i = 0; i < grid->size; i++) grid->arr[i]=false;
}
void initGrid(Grid* grid, unsigned int width, unsigned int height)
{
grid->size = width*height;
grid->width = width;
grid->arr = (bool*)malloc(sizeof(bool)*grid->size);
}
void putPixel(Grid* grid, int x, int y)
{
grid->arr[toIndex(grid, x, y)] = true;
}
void drawGrid(Grid* grid)
{
unsigned int width, height;
width = grid->width;
height = grid->size/width;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (grid->arr[toIndex(grid, x, y)]) mvprintw(y, x, "x");
else mvprintw(y, x, " ");
}
}
}