cgol

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

ascii.c (647B)


      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
#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;
}