add highcon demo #181

This commit is contained in:
nick black 2020-02-06 20:55:18 -05:00 committed by Nick Black
parent ac7c247afc
commit 8e29b5ba0f
4 changed files with 69 additions and 5 deletions

View File

@ -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

View File

@ -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, },

View File

@ -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);

62
src/demo/highcon.c Normal file
View File

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