jgtrosh

cmatrix

Jul 6th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define WIDTH 250
  5.  
  6. inline int prob(int n) {
  7.     switch (n) {
  8.     case 2:  return 20;
  9.     case 1:  return 10;
  10.     default: return 20;
  11.     }
  12. }
  13.  
  14. int main() {
  15.     unsigned char cols[WIDTH];
  16.     int i, j;
  17.     struct timespec t;
  18.     srand(time(NULL));
  19.     t.tv_sec = 0;
  20.     t.tv_nsec = 5e7L;
  21.     fputs("\033[38;5;82m", stdout);
  22.     for (i=0; i<WIDTH; i++)
  23.         cols[i] = rand()%3;
  24.     while (1) {
  25.         for (i=0; i<WIDTH; i++) {
  26.             j = cols[i];
  27.             if (j == 2) fputs("\033[38;5;82m", stdout);
  28.             else if (j) fputs("\033[38;5;28m", stdout);
  29.             else        fputs("\033[30m",      stdout);
  30.             putchar(32+rand()%(126-32));
  31.             if (!(rand()%prob(j))) cols[i] = (j+2)%3;
  32.         }
  33.         fflush(stdout);
  34.         nanosleep(&t, NULL);
  35.         putchar('\n');
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment