cgol

a cairo-based Game Of Life
git clone git://bvnf.space/cgol.git
Log | Files | Refs

commit 6f160593ce5caa4db311d3eafce03dde9c387536
parent 886b458fdc9e494d67221faf33357dfed80ed55c
Author: aabacchus <ben@bvnf.space>
Date:   Tue,  4 Jan 2022 01:53:26 +0000

add ascii drawing backend

need to add options to change this at compile/run time
and need to document it

Diffstat:
MMakefile | 5+++--
Aascii.c | 33+++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,16 +7,17 @@ XCFLAGS := $(CFLAGS) -Wall -Wextra -Wpedantic $(DEBUG) $(XXCFLAGS) -D_XOPEN_SOUR XLDFLAGS = $(LDFLAGS) $(XXLDFLAGS) OBJS = \ - image.o \ main.o \ rules.o \ + ascii.o \ +# image.o \ all: cgol images cgol: $(OBJS) $(CC) $(XLDFLAGS) $(OBJS) -o cgol -$(OBJS): $(OBJS:.o=.c) cgol.h +$(OBJS): cgol.h .c.o: $(CC) -c $(XCFLAGS) $< diff --git a/ascii.c b/ascii.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <time.h> +#include "cgol.h" + +#define ESC_CLEAR "\033[2J" +#define ESC_HOME "\033[H" +#define ESC_SAVE "\033[s" +#define ESC_RESTORE "\033[u" + +#define ALIVE_CHAR '#' + +int +png(struct imgdata *img, short *cells, char *fn) { + (void)fn; + int nx, ny; + nx = img->nx; + ny = img->ny; + + printf(ESC_CLEAR ESC_HOME); + for (int j = 0; j < ny; j++) { + for (int i = 0; i < nx; i++) { + printf("%c", *(cells + j * nx + i) ? ALIVE_CHAR : ' '); + } + puts(""); + } + + const struct timespec req = { + 0, 200000000 /* 0.2 s */ + }; + nanosleep(&req, NULL); + + return 0; +}