Advertisement
Smortypi

Color Stream

Nov 21st, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. //A quick and dirty program to print a randomly colored, randomly generated stream of numbers.
  2. //Released as wtfpl and whatnot. http://www.wtfpl.net/about/
  3.  
  4. /*version 3.2: adding srand() broke it so goodbye srand()*/
  5.  
  6. #include <stdio.h> //I/O Junk
  7. #include <stdlib.h> //used for rand()
  8. #include <unistd.h> //used for usleep()
  9.  
  10. int main(){
  11.         int speed, input;
  12.         printf("Select the  speed:\n\t1 (Slow)\n\t2 (Medium)\n\t3 (Fast)\n");
  13.         scanf("%d", &input);
  14.         switch(input){
  15.                 case  1 :
  16.                         speed = 10000; //speed should be in microseconds, blame usleep.
  17.                         break;
  18.                 case  2 :
  19.                         speed = 5000;
  20.                         break;
  21.                 case  3 :
  22.                         speed = 1000;
  23.                         break;
  24.                 default:
  25.                         printf("\nInvalid input. Reverting to default (Fast).\n");
  26.                         speed = 1000;
  27.                         break;
  28.         }
  29.         while(1){
  30.                 usleep(speed);
  31.                 fflush(stdout);;
  32.                 //jury rigged random color and number generator. Hey, it works.
  33.         printf("\033[22;3%dm %d", rand() % 10, rand() % 10);
  34.         }
  35. return(0);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement