diff options
author | BurnZeZ <brz-9dev@feline.systems> | 2016-03-19 20:03:10 -0400 |
---|---|---|
committer | BurnZeZ <brz-9dev@feline.systems> | 2016-03-19 20:03:10 -0400 |
commit | 730578d40c8e1a46c76a83c4295e9ea8df611ea9 (patch) | |
tree | ad8fc870b7e3474e0da47f837d6dd51812192df6 | |
parent | 98eb99c376980643b013086ab728258744e33d03 (diff) |
games/life: add -d delay parameter, -b color reversal parameter, and update manpage
-rw-r--r-- | sys/man/1/games | 27 | ||||
-rw-r--r-- | sys/src/games/life.c | 28 |
2 files changed, 48 insertions, 7 deletions
diff --git a/sys/man/1/games b/sys/man/1/games index 4eb6a36a2..24c92c2eb 100644 --- a/sys/man/1/games +++ b/sys/man/1/games @@ -63,6 +63,19 @@ .I pattern .br .B games/life +[ +.B -3 +] [ +.B -o +] [ +.B -d +.I delay +] [ +.B -r +.I rules +] [ +.B -b +] .I startfile .br .B games/mandel @@ -209,6 +222,20 @@ There is a library of interesting initial positions; the library is consulted if .I startfile cannot be found. +The +.B -3 +and +.B -o +options select between rules known as +.IR 34-life " and " lineosc , +while +.B -o +allows specifying the rules explicitly as an argument. +The +.B -d +option allows specifying the delay in milliseconds between steps, and +.B -b +reverses the color scheme. .TP .B mahjongg Remove all tiles diff --git a/sys/src/games/life.c b/sys/src/games/life.c index 000134e8c..287dba02e 100644 --- a/sys/src/games/life.c +++ b/sys/src/games/life.c @@ -32,9 +32,10 @@ char action[18]; /* index by cell contents to find action */ char *adjust[NADJUST]; Point cen; -Image *box; +Image *bg, *box; int i0, i1, j0, j1; int needresize; +int reverse; void birth(int, int); void centerlife(void); @@ -65,7 +66,7 @@ clrbox(int i, int j) Point loc; loc = Pt(cen.x + j*PX, cen.y + i*PX); - draw(screen, Rpt(loc, addpt(loc, Pt(BX, BX))), display->white, nil, ZP); + draw(screen, Rpt(loc, addpt(loc, Pt(BX, BX))), bg, nil, ZP); } void @@ -89,7 +90,7 @@ g9err(Display *, char *err) void usage(void) { - fprint(2, "Usage: %s [-3o] [-r rules] file\n", argv0); + fprint(2, "Usage: %s [-3bo] [-d delay] [-r rules] file\n", argv0); exits("usage"); } @@ -117,6 +118,14 @@ main(int argc, char *argv[]) case '3': setrules(".d.d.db.b..d.d.d.d"); break; /* 34-life */ + case 'b': + reverse = ~0xff; + break; + case 'd': + delay = atoi(EARGF(usage())); + if(delay < 0) + sysfatal("invalid delay: %d", delay); + break; case 'o': setrules(".d.d.db.b.b..d.d.d"); break; /* lineosc? */ @@ -134,8 +143,13 @@ main(int argc, char *argv[]) cen = divpt(subpt(addpt(screen->r.min, screen->r.max), Pt(NLIFE * PX, NLIFE * PX)), 2); - box = allocimage(display, Rect(0, 0, BX, BX), RGB24, 1, DBlack); - assert(box != nil); + + bg = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DWhite^reverse); + if(bg == nil) + sysfatal("allocimage: %r"); + box = allocimage(display, Rect(0,0,BX,BX), screen->chan, 1, DBlack^reverse); + if(box == nil) + sysfatal("allocimage: %r"); redraw(); readlife(argv[0]); @@ -296,7 +310,7 @@ readlife(char *filename) if ((bp = Bopen(name, OREAD)) == nil) sysfatal("can't read %s: %r", name); } - draw(screen, screen->r, display->white, nil, ZP); + draw(screen, screen->r, bg, nil, ZP); for (i = 0; i != NLIFE; i++) { row[i] = col[i] = 0; for (j = 0; j != NLIFE; j++) @@ -373,7 +387,7 @@ redraw(void) int i, j; window(); - draw(screen, screen->r, display->white, nil, ZP); + draw(screen, screen->r, bg, nil, ZP); for (i = i0; i <= i1; i++) for (j = j0; j <= j1; j++) if (life[i][j] & 1) |