mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-17 04:30:57 +01:00
added C test
This commit is contained in:
28
various-tests/raygol/grid.c
Normal file
28
various-tests/raygol/grid.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "grid.h"
|
||||
|
||||
Grid *NewGrid(int width, int height, int density) {
|
||||
Grid *grid = malloc(sizeof(struct Grid));
|
||||
grid->Width = width;
|
||||
grid->Height = height;
|
||||
grid->Density = density;
|
||||
|
||||
grid->Data = malloc(height * sizeof(int *));
|
||||
for (int y = 0; y < grid->Height; y++) {
|
||||
grid->Data[y] = malloc(width * sizeof(int *));
|
||||
}
|
||||
|
||||
FillRandom(grid);
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
void FillRandom(Grid *grid) {
|
||||
int r;
|
||||
for (int y = 0; y < grid->Width; y++) {
|
||||
for (int x = 0; x < grid->Height; x++) {
|
||||
r = GetRandomValue(0, grid->Density);
|
||||
if (r == 1)
|
||||
grid->Data[y][x] = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user