forked from dranga/GOL-framebuffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.c
36 lines (31 loc) · 1.04 KB
/
grid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "grid.h"
#include "framebuffer.h"
//void newGrid(grid_t *grid, FrameBuffer_t *frame, int pixelPerXdiv, int pixelPerYdiv) {
void newGrid(Grid_t *grid, FrameBuffer_t *frame, int XPixelPerDiv, int YPixelPerDiv) {
grid->frame = frame;
grid->XPixelPerDiv = XPixelPerDiv;
grid->YPixelPerDiv = YPixelPerDiv;
grid->gridXMax = frame->xmax/XPixelPerDiv;
grid->gridYMax = frame->ymax/YPixelPerDiv;
}
void GridPaintCell(Grid_t *grid, int x,int y, int red, int blue, int green, int transparency) {
int xMax = (x + 1) * grid->XPixelPerDiv;
int yMax = (y + 1) * grid->YPixelPerDiv;
int border = 2;
int frameX, frameY;
for(frameX = x * grid->XPixelPerDiv + border; frameX < xMax - border; frameX++) {
for(frameY = y * grid->YPixelPerDiv + border; frameY < yMax - border; frameY++) {
FrameBufferWritePixel(grid->frame, frameX, frameY, red, blue, green, transparency);
}
}
}
void ClearGrid(Grid_t *grid) {
int x, y;
for (x = 0; x < grid->gridXMax; x++)
{
for (y = 0; y < grid->gridYMax; y++)
{
GridPaintCell(grid, x, y, 0, 0, 0, 0);
}
}
}