Kjetil's Information Center: A Blog About My Projects

Curses Snow Crash

On my way to work one morning I got the idea for this program. Can it actually be called a program? It's more like a novelty, but so simple to make. Take a look at the excellent cmatrix for a similar, but much more advanced program.

The name is from Neal Stephenson's novel, where I imagine that the "Snow Crash" would look something like the output of this program.

Use it as a screen saver or just for fun, so check out the code:

#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <curses.h>

int main(int argc, char *argv[])
  int x, y, maxy, maxx;


  atexit((void *)endwin);

  while (1) {
    if (getch() != ERR)
      return 0; /* Stop on any key press. */

    getmaxyx(stdscr, maxy, maxx);
    for (y = 0; y < maxy; y++) {
      for (x = 0; x < maxx; x++) {
        mvaddch(y, x, (rand() % 0x5E) + 0x21); /* 0x21 -> 0x7E */
    usleep(40000); /* ~24 frames per second. */

  return 0;

Compiled and run; it will look something like this for each frame, just random characters splattered over the screen:

Snow Crash!

Here's a statically linked Win32 binary for convenience.

Topic: Scripts and Code, by Kjetil @ 01/12-2013, Article Link