From b2a911d0ca1bf5da967be4ee6921471dedcefd53 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Fri, 11 Oct 2024 00:25:31 +0700 Subject: amusing --- sources/main.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 sources/main.c (limited to 'sources') diff --git a/sources/main.c b/sources/main.c new file mode 100644 index 0000000..a84e253 --- /dev/null +++ b/sources/main.c @@ -0,0 +1,96 @@ +#include "raylib.h" +#include +#include + +int main(void) +{ + const int pixSize = 5; + const int padding = 2; + const int dim = 80; + const int space = pixSize + (2 * padding); + const int winSize = space * dim; + + bool (*currState)[dim]; + bool (*nextState)[dim]; + currState = malloc(dim * dim * sizeof(bool)); + nextState = malloc(dim * dim * sizeof(bool)); + + srand(time(NULL)); + int prob = 30; + for (int i=0; i 0 && j > 0) { + n1 = currState[i - 1][j - 1]; + n2 = currState[i - 1][j]; + n4 = currState[i][j - 1]; + } + if (i > 0 && j < dim-1) { + n3 = currState[i - 1][j + 1]; + } + if (i < dim-1 && j < dim-1) { + n5 = currState[i][j + 1]; + n7 = currState[i + 1][j]; + } + if (i < dim-1 && j > 0) { + n6 = currState[i + 1][j - 1]; + } + if (i < dim-1 && j < dim-1) { + n8 = currState[i + 1][j + 1]; + } + + int total = n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8; + if (total < 2) nextState[i][j] = 0; + if (total > 3) nextState[i][j] = 0; + if ((total == 2 || total == 3) && currState[i][j]) nextState[i][j] = false; + if (total == 3 && !currState[i][j]) nextState[i][j] = true; + } + } + + bool (*temp)[dim] = currState; + currState = nextState; + nextState = temp; + + EndDrawing(); + } + + free(currState); + free(nextState); + + CloseWindow(); + + return 0; +} -- cgit v1.2.3-70-g09d2