grid demo

pull/30/head
nick black 5 years ago
parent 414b2694ba
commit 3d5ba40352
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -95,6 +95,9 @@ int main(int argc, char** argv){
goto err;
}
sleep(1);
if(grid_demo(nc)){
goto err;
}
if(box_demo(nc)){
goto err;
}

@ -11,6 +11,7 @@ extern "C" {
int widecolor_demo(struct notcurses* nc, struct ncplane* n);
int box_demo(struct notcurses* nc);
int grid_demo(struct notcurses* nc);
#ifdef __cplusplus
}

@ -0,0 +1,71 @@
#include <unistd.h>
#include "demo.h"
// red across, blue down, green from UL to LR
int grid_demo(struct notcurses* nc){
int maxx, maxy;
notcurses_term_dimyx(nc, &maxy, &maxx);
int rs = 256 / maxx;
int gs = 256 / (maxx + maxy);
int bs = 256 / maxy;
int y, x;
struct ncplane* n = notcurses_stdplane(nc);
cell ul, ll, cl, cr, lc, lr, ur, uc, cc;
cell_init(&ul);
cell_init(&uc);
cell_init(&cl);
cell_init(&cr);
cell_init(&ll);
cell_init(&lc);
cell_init(&lr);
cell_init(&ur);
cell_init(&cc);
cell_load(n, &ul, "");
cell_load(n, &uc, "");
cell_load(n, &ur, "");
cell_load(n, &cl, "");
cell_load(n, &cc, "");
cell_load(n, &cr, "");
cell_load(n, &ll, "");
cell_load(n, &lc, "");
cell_load(n, &lr, "");
ncplane_cursor_move_yx(n, 0, 0);
y = 0;
// top line
cell_set_fg(&ul, 255, 255, 255);
ncplane_putc(n, &ul);
for(x = 1 ; x < maxx - 1 ; ++x){
cell_set_fg(&uc, 255 - rs * x, 255 - gs * (x + y), 255);
ncplane_putc(n, &uc);
}
cell_set_fg(&ur, 1, 255 - gs * (x + y), 255);
ncplane_putc(n, &ur);
// center
for(y = 1 ; y < maxy - 1 ; ++y){
cell_set_fg(&cl, 255, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cl);
for(x = 1 ; x < maxx - 1 ; ++x){
cell_set_fg(&cc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cc);
}
cell_set_fg(&cr, 1, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cr);
}
// bottom line
cell_set_fg(&ll, 255, 255 - gs * (x + y), 1);
ncplane_putc(n, &ll);
for(x = 1 ; x < maxx - 1 ; ++x){
cell_set_fg(&lc, 255 - rs * x, 255 - gs * (x + y), 1);
ncplane_putc(n, &lc);
}
cell_set_fg(&lr, 1, 255 - gs * (x + y), 1);
ncplane_putc(n, &lr);
// render!
notcurses_render(nc);
sleep(1);
return 0;
}
Loading…
Cancel
Save