Created
April 1, 2014 18:03
-
-
Save vikrum/9919585 to your computer and use it in GitHub Desktop.
Terminal screensaver/session activity bumper thing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* .. spin .. | |
| * | |
| * $ gcc spin.c -o spin -lncurses -Wall -O3 | |
| * | |
| * vsn - 2006 | |
| */ | |
| #include <stdlib.h> // srand | |
| #include <time.h> // time | |
| #include <string.h> | |
| #include <ncurses.h> | |
| #define getrandom(min, max) ((rand() % (int)(((max-1)) - (min))) + (min)) | |
| const char | |
| rand_char(void) { | |
| static const char pick[] = "*.-@'+X\",#"; | |
| return(pick[getrandom(0, strlen(pick))]); | |
| } | |
| int | |
| main(void) { | |
| int ch, row, col; | |
| int x1, y1, x2, y2; | |
| ch = row = col = 0; | |
| x1 = x2 = y1 = y2 = 1; | |
| srand(time(NULL)); | |
| initscr(); | |
| curs_set(0); | |
| getmaxyx(stdscr,row,col); | |
| noecho(); | |
| raw(); | |
| keypad(stdscr, TRUE); | |
| nodelay(stdscr, TRUE); | |
| refresh(); | |
| while(1) { | |
| ch = getch(); | |
| if(ch == 'q') | |
| break; | |
| y1 = getrandom(1, row); | |
| x1 = getrandom(1, col); | |
| mvaddch(y1, x1, rand_char()); | |
| refresh(); | |
| mvaddch(y2, x2, ' '); | |
| refresh(); | |
| napms(175); | |
| mvaddch(y1, x1, ' '); | |
| refresh(); | |
| y2 = (row % getrandom(1, row)) + 1; | |
| x2 = (col % getrandom(1, col)) + 1; | |
| mvaddch(y2, x2, rand_char()); | |
| refresh(); | |
| napms(75); | |
| } | |
| endwin(); | |
| return(0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment