demos: lock in some backgrounds

This commit is contained in:
nick black 2020-01-16 23:35:57 -05:00 committed by Nick Black
parent 44af796e74
commit 97e17c6cf5
9 changed files with 107 additions and 185 deletions

View File

@ -18,8 +18,8 @@ int box_demo(struct notcurses* nc){
}
struct timespec start, now;
clock_gettime(CLOCK_MONOTONIC, &start);
int zbonus = 40;
int zbonusdelta = 20;
int zbonus = 0;
int zbonusdelta = 16;
int ylen, xlen;
ncplane_dim_yx(n, &ylen, &xlen);
// target grid is 7x7
@ -57,18 +57,30 @@ int box_demo(struct notcurses* nc){
int y = 0, x = 0;
ncplane_dim_yx(n, &ylen, &xlen);
while(ylen - y >= targy && xlen - x >= targx){
cell_set_fg_rgb(&ul, 107 - (y * 2), zbonus, 107 + (y * 2));
cell_set_bg_rgb(&ul, 20, zbonus, 20);
cell_set_fg_rgb(&ur, 107 - (y * 2), zbonus, 107 + (y * 2));
cell_set_bg_rgb(&ur, 20, zbonus, 20);
cell_set_fg_rgb(&hl, 107 - (y * 2), zbonus, 107 + (y * 2));
cell_set_bg_rgb(&hl, 20, zbonus, 20);
cell_set_fg_rgb(&ll, 107 - (y * 2), zbonus, 107 + (y * 2));
cell_set_bg_rgb(&ll, 20, zbonus, 20);
cell_set_fg_rgb(&lr, 107 - (y * 2), zbonus, 107 + (y * 2));
cell_set_bg_rgb(&lr, 20, zbonus, 20);
cell_set_fg_rgb(&vl, 107 - (y * 2), zbonus, 107 + (y * 2));
cell_set_bg_rgb(&vl, 20, zbonus, 20);
if(cell_set_fg_rgb(&ul, zbonus, 255 - (y * 2), zbonus)){
return -1;
}
if(cell_set_bg_rgb(&ul, 20, zbonus, 20)){
return -1;
}
if(cell_set_fg_rgb(&ur, 255 - (y * 2), zbonus, 255 - (y * 2))){
return -1;
}
if(cell_set_bg_rgb(&ur, 20, zbonus, 20)){
return -1;
}
if(cell_set_fg_rgb(&ll, 255 - (y * 2), zbonus, 255 - (y * 2))){
return -1;
}
if(cell_set_bg_rgb(&ll, 20, zbonus, 20)){
return -1;
}
if(cell_set_fg_rgb(&lr, zbonus, 255 - (y * 2), zbonus)){
return -1;
}
if(cell_set_bg_rgb(&lr, 20, zbonus, 20)){
return -1;
}
if(ncplane_cursor_move_yx(n, y, x)){
return -1;
}

View File

@ -98,103 +98,6 @@ usage(const char* exe, int status){
exit(status);
}
static int
intro(struct notcurses* nc){
struct ncplane* ncp;
if((ncp = notcurses_stdplane(nc)) == NULL){
return -1;
}
cell c = CELL_TRIVIAL_INITIALIZER;
cell_set_bg_rgb(&c, 0x20, 0x20, 0x20);
ncplane_set_base(ncp, &c);
int x, y, rows, cols;
ncplane_dim_yx(ncp, &rows, &cols);
cell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
cell ll = CELL_TRIVIAL_INITIALIZER, lr = CELL_TRIVIAL_INITIALIZER;
cell hl = CELL_TRIVIAL_INITIALIZER, vl = CELL_TRIVIAL_INITIALIZER;
if(ncplane_cursor_move_yx(ncp, 0, 0)){
return -1;
}
if(cells_rounded_box(ncp, CELL_STYLE_BOLD, 0, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}
channels_set_fg_rgb(&ul.channels, 0xff, 0, 0);
channels_set_fg_rgb(&ur.channels, 0, 0xff, 0);
channels_set_fg_rgb(&ll.channels, 0, 0, 0xff);
channels_set_fg_rgb(&lr.channels, 0xff, 0xff, 0xff);
if(ncplane_box_sized(ncp, &ul, &ur, &ll, &lr, &hl, &vl, rows, cols,
NCBOXGRAD_TOP | NCBOXGRAD_BOTTOM |
NCBOXGRAD_RIGHT | NCBOXGRAD_LEFT)){
return -1;
}
cell_release(ncp, &ul); cell_release(ncp, &ur);
cell_release(ncp, &ll); cell_release(ncp, &lr);
cell_release(ncp, &hl); cell_release(ncp, &vl);
const char* cstr = "Δ";
cell_load(ncp, &c, cstr);
cell_set_fg_rgb(&c, 200, 0, 200);
int ys = 200 / (rows - 2);
for(y = 5 ; y < rows - 6 ; ++y){
cell_set_bg_rgb(&c, 0, y * ys , 0);
for(x = 5 ; x < cols - 6 ; ++x){
if(ncplane_putc_yx(ncp, y, x, &c) <= 0){
return -1;
}
}
}
cell_release(ncp, &c);
uint64_t channels = 0;
channels_set_fg_rgb(&channels, 90, 0, 90);
channels_set_bg_rgb(&channels, 0, 0, 180);
if(ncplane_cursor_move_yx(ncp, 4, 4)){
return -1;
}
if(ncplane_rounded_box(ncp, 0, channels, rows - 6, cols - 6, 0)){
return -1;
}
const char s1[] = " Die Welt ist alles, was der Fall ist. ";
const char str[] = " Wovon man nicht sprechen kann, darüber muss man schweigen. ";
if(ncplane_set_fg_rgb(ncp, 192, 192, 192)){
return -1;
}
if(ncplane_set_bg_rgb(ncp, 0, 40, 0)){
return -1;
}
if(ncplane_putstr_aligned(ncp, rows / 2 - 2, NCALIGN_CENTER, s1) != (int)strlen(s1)){
return -1;
}
ncplane_styles_on(ncp, CELL_STYLE_ITALIC | CELL_STYLE_BOLD);
if(ncplane_putstr_aligned(ncp, rows / 2, NCALIGN_CENTER, str) != (int)strlen(str)){
return -1;
}
ncplane_styles_off(ncp, CELL_STYLE_ITALIC);
ncplane_set_fg_rgb(ncp, 0xff, 0xff, 0xff);
if(ncplane_printf_aligned(ncp, rows - 3, NCALIGN_CENTER, "notcurses %s. press 'q' to quit.", notcurses_version()) < 0){
return -1;
}
ncplane_styles_off(ncp, CELL_STYLE_BOLD);
const wchar_t wstr[] = L"▏▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁▕";
if(ncplane_putwstr_aligned(ncp, rows / 2 - 5, NCALIGN_CENTER, wstr) < 0){
return -1;
}
if(rows < 45){
ncplane_set_fg_rgb(ncp, 0xc0, 0, 0x80);
ncplane_set_bg_rgb(ncp, 0x20, 0x20, 0x20);
ncplane_styles_on(ncp, CELL_STYLE_BLINK); // heh FIXME replace with pulse
if(ncplane_putstr_aligned(ncp, 2, NCALIGN_CENTER, "demo runs best with at least 45 lines") < 0){
return -1;
}
ncplane_styles_off(ncp, CELL_STYLE_BLINK); // heh FIXME replace with pulse
}
if(demo_render(nc)){
return -1;
}
nanosleep(&demodelay, NULL);
struct timespec fade = demodelay;
ncplane_fadeout(ncp, &fade, demo_fader);
return 0;
}
static struct {
const char* name;
int (*fxn)(struct notcurses*);

View File

@ -31,6 +31,7 @@ int eagle_demo(struct notcurses* nc);
int panelreel_demo(struct notcurses* nc);
int xray_demo(struct notcurses* nc);
int luigi_demo(struct notcurses* nc);
int intro(struct notcurses* nc);
int outro(struct notcurses* nc);
/*------------------------------- demo input API --------------------------*/

View File

@ -11,7 +11,6 @@ drop_bricks(struct notcurses* nc, struct ncplane** arr, int arrcount){
ns_to_timespec(timespec_to_ns(&demodelay) * 5 / arrcount, &iterdelay);
ncplane_erase(notcurses_stdplane(nc));
for(int n = 0 ; n < arrcount ; ++n){
fprintf(stderr, "PLANE %d: %p\n", n, arr[n]);
ncplane_erase(arr[n]);
if(notcurses_render(nc)){
return -1;
@ -35,7 +34,6 @@ shuffle_in(struct ncplane** arr, int count, struct ncplane* n){
arr = tmp;
// location of new element
int pos = random() % (count + 1);
fprintf(stderr, "pos %d count %d moving %d\n", pos, count, count - pos);
if(pos < count){
// move everything, starting at our new location, one spot right
memmove(arr + pos + 1, arr + pos, sizeof(*arr) * (count - pos));

View File

@ -109,6 +109,68 @@ bgnext(cell* c, int* r, int* g, int* b){
return ret;
}
static int
gridinv_demo(struct notcurses* nc, struct ncplane *n){
ncplane_erase(n);
cell ul, ll, cl, cr, lc, lr, ur, uc, cc;
prep_cells2(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
for(int i = 0 ; i < 256 ; ++i){
int maxx, maxy;
notcurses_term_dim_yx(nc, &maxy, &maxx);
int rs = 255 / maxx;
int gs = 255 / (maxx + maxy);
int bs = 255 / maxy;
int x = 0;
int y = 0;
// top line
ccell_set_fg_rgb(&ul, i / 2, i, i / 2);
ccell_set_bg_rgb(&ul, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc_yx(n, y, x, &ul);
for(x = 1 ; x < maxx - 1 ; ++x){
ccell_set_fg_rgb(&uc, i / 2, i, i / 2);
ccell_set_bg_rgb(&uc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &uc);
}
ccell_set_fg_rgb(&ur, i / 2, i, i / 2);
ccell_set_bg_rgb(&ur, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &ur);
// center
for(y = 1 ; y < maxy - 1 ; ++y){
x = 0;
ccell_set_fg_rgb(&cl, i / 2, i, i / 2);
ccell_set_bg_rgb(&cl, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc_yx(n, y, x, &cl);
for(x = 1 ; x < maxx - 1 ; ++x){
ccell_set_fg_rgb(&cc, i / 2, i, i / 2);
ccell_set_bg_rgb(&cc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cc);
}
ccell_set_fg_rgb(&cr, i / 2, i, i / 2);
ccell_set_bg_rgb(&cr, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cr);
}
// bottom line
x = 0;
ccell_set_fg_rgb(&ll, i / 2, i, i / 2);
ccell_set_bg_rgb(&ll, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc_yx(n, y, x, &ll);
for(x = 1 ; x < maxx - 1 ; ++x){
ccell_set_fg_rgb(&lc, i / 2, i, i / 2);
ccell_set_bg_rgb(&lc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &lc);
}
ccell_set_fg_rgb(&lr, i / 2, i, i / 2);
ccell_set_bg_rgb(&lr, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &lr);
demo_render(nc);
}
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
return 0;
}
static int
gridswitch_demo(struct notcurses* nc, struct ncplane *n){
ncplane_erase(n);
@ -179,69 +241,7 @@ gridswitch_demo(struct notcurses* nc, struct ncplane *n){
demo_render(nc);
}
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
return ret;
}
static int
gridinv_demo(struct notcurses* nc, struct ncplane *n){
ncplane_erase(n);
cell ul, ll, cl, cr, lc, lr, ur, uc, cc;
prep_cells2(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
for(int i = 0 ; i < 256 ; ++i){
int maxx, maxy;
notcurses_term_dim_yx(nc, &maxy, &maxx);
int rs = 255 / maxx;
int gs = 255 / (maxx + maxy);
int bs = 255 / maxy;
int x = 0;
int y = 0;
// top line
ccell_set_fg_rgb(&ul, i / 2, i, i / 2);
ccell_set_bg_rgb(&ul, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc_yx(n, y, x, &ul);
for(x = 1 ; x < maxx - 1 ; ++x){
ccell_set_fg_rgb(&uc, i / 2, i, i / 2);
ccell_set_bg_rgb(&uc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &uc);
}
ccell_set_fg_rgb(&ur, i / 2, i, i / 2);
ccell_set_bg_rgb(&ur, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &ur);
// center
for(y = 1 ; y < maxy - 1 ; ++y){
x = 0;
ccell_set_fg_rgb(&cl, i / 2, i, i / 2);
ccell_set_bg_rgb(&cl, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc_yx(n, y, x, &cl);
for(x = 1 ; x < maxx - 1 ; ++x){
ccell_set_fg_rgb(&cc, i / 2, i, i / 2);
ccell_set_bg_rgb(&cc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cc);
}
ccell_set_fg_rgb(&cr, i / 2, i, i / 2);
ccell_set_bg_rgb(&cr, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &cr);
}
// bottom line
x = 0;
ccell_set_fg_rgb(&ll, i / 2, i, i / 2);
ccell_set_bg_rgb(&ll, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc_yx(n, y, x, &ll);
for(x = 1 ; x < maxx - 1 ; ++x){
ccell_set_fg_rgb(&lc, i / 2, i, i / 2);
ccell_set_bg_rgb(&lc, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &lc);
}
ccell_set_fg_rgb(&lr, i / 2, i, i / 2);
ccell_set_bg_rgb(&lr, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
ncplane_putc(n, &lr);
demo_render(nc);
}
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
return gridswitch_demo(nc, n);
return gridinv_demo(nc, n);
}
// red across, blue down, green from UL to LR
@ -328,5 +328,5 @@ int grid_demo(struct notcurses* nc){
}
}
release_cells(n, &ul, &uc, &ur, &cl, &cc, &cr, &ll, &lc, &lr);
return gridinv_demo(nc, n);
return gridswitch_demo(nc, n);
}

View File

@ -19,10 +19,14 @@ int intro(struct notcurses* nc){
if(cells_rounded_box(ncp, CELL_STYLE_BOLD, 0, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}
channels_set_fg_rgb(&ul.channels, 0xff, 0, 0);
channels_set_fg_rgb(&ur.channels, 0, 0xff, 0);
channels_set_fg_rgb(&ll.channels, 0, 0, 0xff);
channels_set_fg_rgb(&lr.channels, 0xff, 0xff, 0xff);
cell_set_fg(&ul, 0xff0000);
cell_set_bg(&ul, 0x002000);
cell_set_fg(&ur, 0x00ff00);
cell_set_bg(&ur, 0x002000);
cell_set_fg(&ll, 0x0000ff);
cell_set_bg(&ll, 0x002000);
cell_set_fg(&lr, 0xffffff);
cell_set_bg(&lr, 0x002000);
if(ncplane_box_sized(ncp, &ul, &ur, &ll, &lr, &hl, &vl, rows, cols,
NCBOXGRAD_TOP | NCBOXGRAD_BOTTOM |
NCBOXGRAD_RIGHT | NCBOXGRAD_LEFT)){

View File

@ -29,8 +29,9 @@ legend(struct notcurses* nc, const char* msg){
int dimx, dimy;
notcurses_term_dim_yx(nc, &dimy, &dimx);
// FIXME replace with ncplane_new_aligned()
struct ncplane* n = ncplane_new(nc, 3, strlen(msg) + 2, dimy - 4,
(dimx - ((strlen(msg) + 2))) / 2, NULL);
struct ncplane* n = ncplane_aligned(notcurses_stdplane(nc), 3,
strlen(msg) + 4, dimy - 4,
NCALIGN_CENTER, NULL);
if(n == NULL){
return NULL;
}
@ -41,7 +42,7 @@ legend(struct notcurses* nc, const char* msg){
ncplane_set_base(n, &c);
ncplane_set_fg(n, 0xd78700);
ncplane_set_bg(n, 0);
if(ncplane_putstr_yx(n, 1, 1, msg) < 0){
if(ncplane_putstr_aligned(n, 1, NCALIGN_CENTER, msg) < 0){
ncplane_destroy(n);
return NULL;
}

View File

@ -173,12 +173,14 @@ int unicodeblocks_demo(struct notcurses* nc){
cell c = CELL_TRIVIAL_INITIALIZER;
cell_set_fg_alpha(&c, CELL_ALPHA_BLEND);
cell_set_fg(&c, 0x004000);
cell_set_bg(&c, 0x0);
ncplane_set_base(header, &c);
for(sindex = 0 ; sindex < sizeof(blocks) / sizeof(*blocks) ; ++sindex){
ncplane_set_bg_rgb(n, 0, 0, 0);
uint32_t blockstart = blocks[sindex].start;
const char* description = blocks[sindex].name;
ncplane_set_fg_rgb(header, 0xbd, 0xe8, 0xf6);
ncplane_set_bg(header, 0);
ncplane_set_fg(header, 0xbde8f6);
if(ncplane_printf_aligned(header, 1, NCALIGN_CENTER, "Unicode points 0x%05x—0x%05x (%u—%u)",
blockstart, blockstart + BLOCKSIZE,
blockstart, blockstart + BLOCKSIZE) <= 0){

View File

@ -24,6 +24,7 @@ mathplane(struct notcurses* nc){
ncplane_set_base(n, &b);
cell_release(n, &b);
ncplane_set_fg(n, 0xd4af37); // metallic gold
ncplane_set_bg(n, 0x0);
if(n){
ncplane_printf_aligned(n, 0, NCALIGN_RIGHT, "∮E⋅da=Q,n→∞,∑f(i)=∏g(i)⎧⎡⎛┌─────┐⎞⎤⎫");
ncplane_printf_aligned(n, 1, NCALIGN_RIGHT, "⎪⎢⎜│a²+b³ ⎟⎥⎪");