Advertisement
Guest User

text-mode glitch art

a guest
Mar 31st, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. /* http://en.wikipedia.org/wiki/ANSI_escape_code */
  5.  
  6. #define G 100
  7. #define L 10
  8. #define I 10
  9. #define T 100
  10. #define C 50
  11. #define H 20
  12.  
  13. int main(int argc,char *argv[]) {
  14.  short in;
  15.  srandom(getpid() + time(0));
  16.  while((in=fgetc(stdin)) != -1) {
  17.   if(!(random() % G)) {
  18.    printf("\x1b[3%1dm",random() % L);
  19.    printf("\x1b[4%1dm",random() % I);
  20.   }
  21.   if(!(random() % T)) {
  22.    printf(" ");
  23.   }
  24.   if(!(random() % C)) {
  25.    printf("\x1b[1m");
  26.   }
  27.   if(in != '\n') {
  28.    if(!(random() % H)) in^=(1<<(random()%8));
  29.    printf("%c",in);
  30.   }
  31.   else printf("\n");
  32.  }
  33.  printf("\x1b[00m");
  34.  return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement