💾 Archived View for thrig.me › blog › 2024 › 02 › 05 › noiseshow.c captured on 2024-03-21 at 15:43:27.
-=-=-=-=-=-=-
#include <locale.h> #include <ncurses.h> #include <stdio.h> #include <stdlib.h> #include "jsf.h" static const char noise[] = "..,`':;~+=< _ij\"^\\l(amxvu04PYW"; inline static char rndchar(void) { size_t index = 0; size_t len = sizeof(noise) / sizeof(char); while (1) { size_t x = jsf_below(8); index += x; if (x < 5) break; } if (index >= len) index = 0; return noise[index]; } int main(void) { jsf_init(arc4random()); setlocale(LC_ALL, ""); initscr(); cbreak(); curs_set(FALSE); leaveok(stdscr, TRUE); noecho(); int percent = LINES * COLS / 5; for (int i = 0; i < percent; ++i) { int yy = (int) jsf_below((unsigned) LINES); int xx = (int) jsf_below((unsigned) COLS); mvaddch(yy, xx, rndchar()); } getch(); endwin(); }