Skip to content

Instantly share code, notes, and snippets.

@vikrum vikrum/spin.c
Created Apr 1, 2014

Embed
What would you like to do?
Terminal screensaver/session activity bumper thing.
/* .. 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
You can’t perform that action at this time.