demo: reject multiplier <= 0

This commit is contained in:
nick black 2020-01-12 04:25:36 -05:00 committed by Nick Black
parent 4fca9425d9
commit f8c870bb76
2 changed files with 9 additions and 8 deletions

View File

@ -341,6 +341,10 @@ handle_opts(int argc, char** argv, notcurses_options* opts, bool* use_hud){
fprintf(stderr, "Couldn't get a float from %s\n", optarg); fprintf(stderr, "Couldn't get a float from %s\n", optarg);
usage(*argv, EXIT_FAILURE); usage(*argv, EXIT_FAILURE);
} }
if(f <= 0){
fprintf(stderr, "Invalid multiplier: %f\n", f);
usage(*argv, EXIT_FAILURE);
}
uint64_t ns = f * GIG; uint64_t ns = f * GIG;
demodelay.tv_sec = ns / GIG; demodelay.tv_sec = ns / GIG;
demodelay.tv_nsec = ns % GIG; demodelay.tv_nsec = ns % GIG;

View File

@ -71,18 +71,13 @@ lighten(struct ncplane* n, cell* c, int distance, int y, int x){
r += rand() % ((r + 16) / (5 * distance + 1) + 1); r += rand() % ((r + 16) / (5 * distance + 1) + 1);
g += rand() % ((g + 16) / (5 * distance + 1) + 1); g += rand() % ((g + 16) / (5 * distance + 1) + 1);
b += rand() % ((b + 16) / (5 * distance + 1) + 1); b += rand() % ((b + 16) / (5 * distance + 1) + 1);
if(r > 255) r = 255; cell_set_fg_rgb_clipped(c, r, g, b);
if(g > 255) g = 255;
if(b > 255) b = 255;
if(cell_set_fg_rgb(c, r, g, b)){
return -1;
}
return ncplane_putc_yx(n, y, x, c); return ncplane_putc_yx(n, y, x, c);
} }
static void static void
surrounding_cells(struct ncplane* n, cell* cells, int y, int x){ surrounding_cells(struct ncplane* n, cell* cells, int y, int x){
ncplane_at_yx(n, y - 1, x - 1, &cells[0]); /*ncplane_at_yx(n, y - 1, x - 1, &cells[0]);
ncplane_at_yx(n, y - 1, x, &cells[1]); ncplane_at_yx(n, y - 1, x, &cells[1]);
ncplane_at_yx(n, y - 1, x + 1, &cells[2]); ncplane_at_yx(n, y - 1, x + 1, &cells[2]);
ncplane_at_yx(n, y, x + 1, &cells[3]); ncplane_at_yx(n, y, x + 1, &cells[3]);
@ -93,13 +88,14 @@ surrounding_cells(struct ncplane* n, cell* cells, int y, int x){
ncplane_at_yx(n, y - 2, x, &cells[8]); ncplane_at_yx(n, y - 2, x, &cells[8]);
ncplane_at_yx(n, y + 2, x, &cells[9]); ncplane_at_yx(n, y + 2, x, &cells[9]);
ncplane_at_yx(n, y, x - 2, &cells[10]); ncplane_at_yx(n, y, x - 2, &cells[10]);
ncplane_at_yx(n, y, x + 2, &cells[11]); ncplane_at_yx(n, y, x + 2, &cells[11]);*/
ncplane_at_yx(n, y, x, &cells[12]); ncplane_at_yx(n, y, x, &cells[12]);
} }
static int static int
lightup_surrounding_cells(struct ncplane* n, const cell* cells, int y, int x){ lightup_surrounding_cells(struct ncplane* n, const cell* cells, int y, int x){
cell c = CELL_TRIVIAL_INITIALIZER; cell c = CELL_TRIVIAL_INITIALIZER;
/*
cell_duplicate(n, &c, &cells[0]); cell_duplicate(n, &c, &cells[0]);
lighten(n, &c, 2, y - 1, x - 1); lighten(n, &c, 2, y - 1, x - 1);
cell_duplicate(n, &c, &cells[1]); cell_duplicate(n, &c, &cells[1]);
@ -124,6 +120,7 @@ lightup_surrounding_cells(struct ncplane* n, const cell* cells, int y, int x){
lighten(n, &c, 2, y, x - 2); lighten(n, &c, 2, y, x - 2);
cell_duplicate(n, &c, &cells[11]); cell_duplicate(n, &c, &cells[11]);
lighten(n, &c, 2, y, x + 2); lighten(n, &c, 2, y, x + 2);
*/
cell_duplicate(n, &c, &cells[12]); cell_duplicate(n, &c, &cells[12]);
lighten(n, &c, 0, y, x); lighten(n, &c, 0, y, x);
cell_release(n, &c); cell_release(n, &c);