Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.49 KB | None | 0 0
  1.  
  2. /*
  3. CHOINKA WERSJA 2.0
  4.  
  5. UWAGA!
  6. TEN PROGRAM DZIALA ZAROWNO NA SYSTEMACH Z RODZINY WINDOWS I UNIX.
  7.  
  8. PREFEROWANE JEST JEDNAK JEGO URUCHAMIANIE NA SYSTEMACH UNIX-OWYCH, PONIEWAZ
  9. NA TAKOWYM SYSTEMIE ZOSTAL UTWORZONY A "ANIMACJA" CHOINKI JEST BARDZIEJ
  10. PLYNNA.
  11.  
  12. NA WINDOWSIE PROGRAM DZIALA TAK SAMO, ALE MNIEJ PLYNNIE (ZE WZGLEDU NA DZIALANIE CLS I CLEAR).
  13. JESLI DROGI UZYTKOWNIKU WOLISZ URUCHOMIC PROGRAM NA WINDOWSIE, CZUJ SIE WOLNY (BUT YOU HAVE BEEN WARNED!)
  14.  
  15. WYMIARY CHOINKI SA CUSTOMIZOWALNE PRZY POMOCY ZMIENNYCH:
  16.  
  17.      "lights", "xmas_height", "stump_height", "stump_width" i "filled"
  18.  
  19. lights - oznacza jak czesto pojawiaja sie lampki choinkowe (ile ich jest, gestosc)
  20.          Im wieksza wartosc, tym MNIEJ swaitelek // 10 jest optymalne // 0 to zero lampek.
  21.  
  22. xmas_height - wysokosc zielonej czesci choinki.
  23.  
  24. stump_height - wysokosc pnia
  25.  
  26. stump_width -  szerokosc pnia
  27.  
  28. filled -       jesli "true" wypelnia choinke na zielono,
  29.                jesli false pozostawia ja pusta wewnatrz
  30.  
  31.  
  32.  
  33.  
  34. AUTOR: GRZEGORZ GAJEWSI
  35. NUMER ALBUMU:252978
  36.  
  37.  
  38.  
  39. */
  40.  
  41. #include <iostream>
  42. #include <random>
  43. #define OS "Unknown"
  44. #ifdef _WIN32
  45. // Windows
  46.     #include <windows.h>
  47.  
  48. #else
  49. // Not windows
  50.     #include <ctime>
  51.  
  52. #endif
  53. //
  54.  
  55. #include <unistd.h>
  56.  
  57.  
  58. #define RST  "\x1B[0m"
  59. #define KRED  "\x1B[31m"
  60. #define KGRN  "\x1B[32m"
  61. #define KYEL  "\x1B[33m"
  62. #define KBLU  "\x1B[34m"
  63. #define KMAG  "\x1B[35m"
  64. #define KCYN  "\x1B[36m"
  65. #define KWHT  "\x1B[37m"
  66.  
  67. #define FRED(x) KRED x RST
  68. #define FGRN(x) KGRN x RST
  69. #define FYEL(x) KYEL x RST
  70. #define FBLU(x) KBLU x RST
  71. #define FMAG(x) KMAG x RST
  72. #define FCYN(x) KCYN x RST
  73. #define FWHT(x) KWHT x RST
  74.  
  75. #define BOLD(x) "\x1B[1m" x RST
  76. #define UNDL(x) "\x1B[4m" x RST
  77.  
  78. #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
  79. using namespace std;
  80.  
  81. string randomColor() {
  82.  
  83.     int n = rand()%6;//7
  84.  
  85.     switch(n) {
  86.     case 0:
  87.         return KRED;
  88.     case 1:
  89.         return KGRN;
  90.     case 2:
  91.         return KYEL;
  92.     case 3:
  93.         return KBLU;
  94.     case 4:
  95.         return KMAG;
  96.     case 5:
  97.         return KCYN;
  98.     case 6:
  99.         return KWHT;
  100.     default:
  101.         return KWHT;
  102.  
  103.     }
  104.  
  105.  
  106. }
  107.  
  108. int main() {
  109.  
  110.     //Musialem dodac to, aby na Windowsie dzialaly escape characaters do sterowania kolorami...:
  111.    #ifdef _WIN32
  112.         HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
  113.         DWORD consoleMode;
  114.         GetConsoleMode(console, &consoleMode);
  115.         consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
  116.         SetConsoleMode(console, consoleMode);
  117.     #endif
  118.  
  119.     int lights = 10; // Im wiekszy numer, tym mniej swaitelek // 10 jest optymalne -- 0 to zero lampek.
  120.     int xmas_height=20;
  121.     int stump_height=3;
  122.     int stump_width=6;
  123.     bool filled = false;
  124.  
  125.     string treeChar = FGRN("#");
  126.     string currentChar =treeChar;
  127.  
  128.     //Opcje dla choinki:
  129.  
  130.  
  131.  
  132.     //Koniec opcji;
  133.     int mx = xmas_height;
  134.  
  135.  
  136.     for(long long int it = 0;; it++) {
  137.  
  138.         for(int row =1; row<xmas_height; row++) {
  139.             cout<<endl;
  140.             for(int i=0; i<mx-row; i++) {
  141.                 cout<<" ";
  142.  
  143.             }
  144.             for(int column = 1; column<row*2; column++) {
  145.                 srand(column*row*it);
  146.                 // cout<<(int)rand()%2<<endl;
  147.  
  148.                 if(lights>0)
  149.                     if((int)rand()%lights==0 && !(column== 1 || column == row*2-1 || row==xmas_height-1)) {
  150.                         string tmp = randomColor();
  151.                         currentChar=tmp+"o";
  152.  
  153.                     } else {
  154.                         currentChar=treeChar;
  155.  
  156.  
  157.                     }
  158.                 if(!filled) {
  159.                     if(column== 1 || column == row*2-1 || row==xmas_height-1 ||currentChar!=treeChar) {
  160.                         cout<<(currentChar);
  161.                     } else {
  162.                         cout<<FGRN(" ");
  163.  
  164.                     }
  165.  
  166.                 } else {
  167.                     cout<<(currentChar);
  168.  
  169.                 }
  170.             }
  171.         }
  172.  
  173.  
  174.         for(int row =0; row<stump_height; row++) {
  175.             cout<<endl;
  176.             for(int i=0; i<xmas_height-stump_width/2; i++) {
  177.                 cout<<" ";
  178.  
  179.             }
  180.             for(int column = 1; column<stump_width; column++) {
  181.                 cout<<FYEL("#");
  182.             }
  183.             cout<<flush;
  184.         }
  185.  
  186.         #ifdef _WIN32
  187.             Sleep(900);
  188.             system("cls");
  189.         #else
  190.             usleep(3600*150);
  191.             system("clear");
  192.  
  193.         #endif
  194.  
  195.  
  196.  
  197.  
  198.     }
  199.  
  200.  
  201.  
  202.     return 0;
  203.  
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement