From 5e61f536e8d012122fedd2b625dcef269fca29ef Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 24 Nov 2019 21:18:02 -0500 Subject: [PATCH] gridinverse, gridswitch demos #16 --- src/bin/demo.c | 2 +- src/bin/grid.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/bin/demo.c b/src/bin/demo.c index 14d8a5454..2220b2432 100644 --- a/src/bin/demo.c +++ b/src/bin/demo.c @@ -85,7 +85,7 @@ int main(int argc, char** argv){ if(ncplane_fg_rgb8(ncp, 176, 121, 176)){ goto err; } - if(ncplane_bg_rgb8(ncp, 255, 255, 255)){ + if(ncplane_bg_rgb8(ncp, 100, 100, 100)){ goto err; } if(ncplane_putstr(ncp, str) != (int)strlen(str)){ diff --git a/src/bin/grid.c b/src/bin/grid.c index 34ff018b7..3950677ac 100644 --- a/src/bin/grid.c +++ b/src/bin/grid.c @@ -1,11 +1,77 @@ #include #include "demo.h" +static int +gridswitch_demo(struct notcurses* nc, struct ncplane *n, + cell* ul, cell* uc, cell* ur, + cell* cl, cell* cc, cell* cr, + cell* ll, cell* lc, cell* lr){ + // ncplane_erase(n); + int maxx, maxy; + notcurses_term_dimyx(nc, &maxy, &maxx); + int rs = 256 / maxx; + int gs = 256 / (maxx + maxy); + int bs = 256 / maxy; + int x = 0; + int y = 0; + if(ncplane_cursor_move_yx(n, y, x)){ + return -1; + } + // top line + cell_set_fg(ul, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(ul, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, ul); + for(x = 1 ; x < maxx - 1 ; ++x){ + cell_set_fg(uc, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(uc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, uc); + } + cell_set_fg(ur, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(ur, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, ur); + + // center + x = 0; + for(y = 1 ; y < maxy - 1 ; ++y){ + cell_set_fg(cl, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(cl, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, cl); + for(x = 1 ; x < maxx - 1 ; ++x){ + cell_set_fg(cc, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(cc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, cc); + } + cell_set_fg(cr, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(cr, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, cr); + } + + // bottom line + x = 0; + cell_set_fg(ll, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(ll, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, ll); + for(x = 1 ; x < maxx - 1 ; ++x){ + cell_set_fg(lc, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(lc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, lc); + } + cell_set_fg(lr, 255 - rs * y, 255 - gs * (x + y), 255 - bs * x); + cell_set_bg(lr, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); + ncplane_putc(n, lr); + + // render! + notcurses_render(nc); + sleep(5); + return 0; +} + static int gridinv_demo(struct notcurses* nc, struct ncplane *n, cell* ul, cell* uc, cell* ur, cell* cl, cell* cc, cell* cr, cell* ll, cell* lc, cell* lr){ + // ncplane_erase(n); int maxx, maxy; notcurses_term_dimyx(nc, &maxy, &maxx); int rs = 256 / maxx; @@ -62,7 +128,7 @@ gridinv_demo(struct notcurses* nc, struct ncplane *n, // render! notcurses_render(nc); sleep(1); - return 0; + return gridswitch_demo(nc, n, ul, uc, ur, cl, cc, cr, ll, lc, lr); } // red across, blue down, green from UL to LR @@ -74,6 +140,7 @@ int grid_demo(struct notcurses* nc){ int bs = 256 / maxy; int y, x; struct ncplane* n = notcurses_stdplane(nc); + // ncplane_erase(n); cell ul, ll, cl, cr, lc, lr, ur, uc, cc; cell_init(&ul); cell_init(&uc);