From 8e29b5ba0f8afdcfd8d9962573fcdf1307d424a1 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 6 Feb 2020 20:55:18 -0500 Subject: [PATCH] add highcon demo #181 --- doc/man/man1/notcurses-demo.1.md | 3 +- src/demo/demo.c | 8 ++--- src/demo/demo.h | 1 + src/demo/highcon.c | 62 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/demo/highcon.c diff --git a/doc/man/man1/notcurses-demo.1.md b/doc/man/man1/notcurses-demo.1.md index a12eeb89c..273badb98 100644 --- a/doc/man/man1/notcurses-demo.1.md +++ b/doc/man/man1/notcurses-demo.1.md @@ -27,6 +27,7 @@ The demonstrations include (see NOTES below): * (e)agle—they took some time off my life, back in the day * (f)allin'—the screen falls apart under heavy blows * (g)rid—a gradient of color lain atop a great grid +* (h)ighcon—high contrast text atop various colors * (j)ungle—low-bandwidth color cycling reveals ancient ruins * (l)uigi-a dashing Apennine plumber in a world of fire * (r)eel—demonstration of the ncreel high-level widget @@ -62,7 +63,7 @@ At any time, press 'q' to quit. The demo is best run in at least a 80x45 termina **-V**: Print the program name and version, and exit with success. -demospec: Select which demos to run, and what order to run them in. The default is **ixetbcgrwuvlfsjo**. See above for a list of demos. +demospec: Select which demos to run, and what order to run them in. The default is **ixethbcgrwuvlfsjo**. See above for a list of demos. # NOTES diff --git a/src/demo/demo.c b/src/demo/demo.c index 57010f143..280eac1cf 100644 --- a/src/demo/demo.c +++ b/src/demo/demo.c @@ -22,12 +22,12 @@ static char datadir[PATH_MAX]; static atomic_bool interrupted = ATOMIC_VAR_INIT(false); #ifdef DISABLE_FFMPEG -static const char DEFAULT_DEMO[] = "itbgrwus"; +static const char DEFAULT_DEMO[] = "ithbgrwus"; #else #ifdef DFSG_BUILD -static const char DEFAULT_DEMO[] = "ixtbgrwuso"; +static const char DEFAULT_DEMO[] = "ixthbgrwuso"; #else -static const char DEFAULT_DEMO[] = "ixetbcgrwuvlfsjo"; +static const char DEFAULT_DEMO[] = "ixethbcgrwuvlfsjo"; #endif #endif @@ -105,7 +105,7 @@ static struct { NONFREE("eagle", eagle_demo), NONFREE("fallin'", fallin_demo), { "grid", grid_demo, }, - { NULL, NULL, }, + { "highcon", highcontrast_demo, }, { "intro", intro, }, NONFREE("jungle", jungle_demo), { NULL, NULL, }, diff --git a/src/demo/demo.h b/src/demo/demo.h index b5aefcaff..296651f86 100644 --- a/src/demo/demo.h +++ b/src/demo/demo.h @@ -34,6 +34,7 @@ int trans_demo(struct notcurses* nc); int chunli_demo(struct notcurses* nc); int grid_demo(struct notcurses* nc); int fallin_demo(struct notcurses* nc); +int highcontrast_demo(struct notcurses* nc); int jungle_demo(struct notcurses* nc); int sliding_puzzle_demo(struct notcurses* nc); int view_demo(struct notcurses* nc); diff --git a/src/demo/highcon.c b/src/demo/highcon.c new file mode 100644 index 000000000..dc8adfe5d --- /dev/null +++ b/src/demo/highcon.c @@ -0,0 +1,62 @@ +#include "demo.h" + +// Derive the next color based on current state. *'total' ranges from 0 to 768 +// in steps of 4. We increment it upon exhaustion of component colors summing +// to that value. While the 'r', 'g', and 'b', components range from 0 to 256, +// the return value caps each component at 255. +static unsigned +generate_next_color(unsigned *total, unsigned *r, unsigned *g, unsigned *b){ +} + +int highcontrast_demo(struct notcurses* nc){ + int dimy, dimx; + struct ncplane* n = notcurses_stdplane(nc); + ncplane_dim_yx(n, &dimy, &dimx); + int totcells = dimy * dimx; + unsigned iteration = 0; + // circular array of current background colors, starting logically at + // iteration % totcells. + unsigned* scrcolors = malloc(sizeof(*scrcolors) * totcells); + if(scrcolors == NULL){ + return -1; + } + // build up the initial screen + do{ + }while(iterations < totcells); + // we want to fill one screen (totcells) with a broad spectrum of color. rgb + // can have between 0 and 765 total component units (0/0/0 vs 255/255/255). + // each of those totals can result in 1 color. the total 384 will maximize + // the number of colors, with 200 at intervals of 16. at 512+, all components + // must be positive; at 254-, no components can be maximized. at intervals of + // 4, we have ~5M colors between 0..765. + unsigned total, r, g, b; + total = r = g = b = 0; + unsigned rgb; + // each iteration, generate the next color, and introduce it at the lower + // right. start at the upper left, from the logical beginning of the array. + cell c = CELL_SIMPLE_INITIALIZER(' '); + do{ + int idx = iterations % totcells; // first color for upper-left + for(int y = 0 ; y < dimy ; ++y){ + for(int x = 0 ; x < dimx ; ++x){ + cell_set_fg(); + if(ncplane_putc_yx(n, y, x, &c) < 0){ + goto err; + } + } + } + rgb = generate_next_color(&total, &r, &g, &b); + if(notcurses_render(nc)){ + goto err; + } + }while(rgb < 0xffffff); + // FIXME fill screen with a matrix of text, all high-contrast + // FIXME cycle the background matrix + free(scrcolors); + return 0; + +err: + release_cell(n, &c); + free(scrcolors); + return -1; +}