From b21675e7c36acd7095e1efdcf370d304ac291b17 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Sun, 28 May 2023 00:34:42 +0200 Subject: [PATCH] first commit --- build.sh | 5 ++++ main | Bin 0 -> 15984 bytes main.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100755 build.sh create mode 100755 main create mode 100644 main.c diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..4aac112 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -xe + +gcc -Wall -Wextra -o main main.c diff --git a/main b/main new file mode 100755 index 0000000000000000000000000000000000000000..fb53280c0368e3c951c26b47a0d5f47288a132b6 GIT binary patch literal 15984 zcmeHOeQX@X6`woD#FWH#q67>H@reS(&|GXMar2>+i{o?FkOUI~1p(b$?#}ip_SwBV zgM)xtGND{krv}lqMQP=xQW2#esHIg)Dfr?lPNFI@(4vS&s)eBS)h@jh7dh0;_4j7x zt=C(dK!x~g-)Z;F`@Q$(&Agr6o86uLa&TL{*W(dP1>*C9q~}T%63~iVjV^!%#5%DM z`xW9!aS`Ns5>xtsV$do&?VZVsG+qEseq~gcg)djIV9qThPJVOI@O-6VE_6T0uaHz) zcJgmar4YDQ(GoV-rkGp86tx4oT;{6Fy;wcm1|tVTFF$6?O# zZiOG^<--ym=AAm;T*skO9|z_-tzuPcY){RaRjrYgt+9A#*UGMSH7je@_>=AaYS{#8 zS0y$YHd}YxF1+1hfH3y=2+s`Jt7Vu-BHJa{DDC7w@%=N^FZEy9A4%Tu>&e7W-L=o( z`v*RUO5N;FmT^2_Lt0IUpEI%ZJjOdsyXndfcvmH z>1F`4)l)VH{tR#*HYcqGaFr8;OviS%`b9hxZ%?*HqaC87GnJ%WxFwVjsaRW7m?lO| z*i5EEiImwEip51T5sF8Ehr2>%Q!E~8jXe+*9f?>x)g;=YZQ+i6f?Q}^)rhUz8fv$g z)&8nAR&n)ovD&{@m<_wOn~`WD+8j%!qKRG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&VaEAp3EBKX&-@{D(Q;&#=9tI`MPu&-oWVZK*jQe~rpx#bx5Z!AAXO|K&aiAm(*S zwD!*UC!n$W@AfHE<}`1#6CXduUPGZ6n?7x=@2&XzMyEZ?%xNA{V)N(wxYH{Eg4j+; z(=y{@P|(=n_&ndXzE`ErfoS{_u^%7D31DQx{`{TSz$&s9;yT5wJ^M312aVmI?*m7* z|DBenDzG1OFP!cEfq=3LR4VRM%-VCi87P7?)y3`K9Z;Ix+P{%*6l~<6>akcIBz|rS#GjG{}LJXvNhc=CHH- NzqVFcTzUcj{{lSh*#H0l literal 0 HcmV?d00001 diff --git a/main.c b/main.c new file mode 100644 index 0000000..c9b2724 --- /dev/null +++ b/main.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include + +#define WIDTH 100 +#define HEIGHT 100 + +#define true 1 +#define false 0 + +#define emod(x, y) ((((x) % (y)) + (y)) % (y)) +typedef unsigned char bool ; + +bool grid[HEIGHT][WIDTH], step[HEIGHT][WIDTH]; + +bool randb(){ + return rand() % 2; +} + +void gen_grid(){ + for(int i = 0; i < HEIGHT; i++){ + for(int j = 0; j < HEIGHT; j++){ + grid[i][j] = randb(); + } + } +} + +void draw_grid(){ + for(int i = 0; i < HEIGHT; i++){ + for(int j = 0; j < HEIGHT; j++){ + if(grid[i][j]){ + printf("\033[107m■ "); + }else{ + printf("\033[49m "); + } + } + printf("\033[0m\n"); + } +} + +void step_grid(){ + for(int i = 0; i < HEIGHT; i++){ + for(int j = 0; j < WIDTH; j++){ + + int count = 0; + for(int di = i-1; di < i+2; di++){ + for(int dj = j-1; dj < j+2; dj++){ + if(di == i && dj == j){ + continue; + } + if(grid[emod(di, HEIGHT)][emod(dj, WIDTH)]){ + count++; + } + } + } + step[i][j] = false; + if(count == 3 || (count == 2 && grid[i][j])){ + step[i][j] = true; + } + + } + } + memcpy(grid, step, sizeof(char) * HEIGHT * WIDTH); +} + +struct timespec ts = { 0, 100 * 1000}; + +int main(void) +{ + srand(time(0)); + gen_grid(); + + while(true){ + ts.tv_nsec= 10 * 1000 * 1000; + for(int i = 0; i < HEIGHT; i++){ + printf("\n"); + } + draw_grid(); + /* getchar(); */ + step_grid(); + nanosleep(&ts, NULL); + } +} + +