Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- CHOINKA WERSJA 2.0
- UWAGA!
- TEN PROGRAM DZIALA ZAROWNO NA SYSTEMACH Z RODZINY WINDOWS I UNIX.
- PREFEROWANE JEST JEDNAK JEGO URUCHAMIANIE NA SYSTEMACH UNIX-OWYCH, PONIEWAZ
- NA TAKOWYM SYSTEMIE ZOSTAL UTWORZONY A "ANIMACJA" CHOINKI JEST BARDZIEJ
- PLYNNA.
- NA WINDOWSIE PROGRAM DZIALA TAK SAMO, ALE MNIEJ PLYNNIE (ZE WZGLEDU NA DZIALANIE CLS I CLEAR).
- JESLI DROGI UZYTKOWNIKU WOLISZ URUCHOMIC PROGRAM NA WINDOWSIE, CZUJ SIE WOLNY (BUT YOU HAVE BEEN WARNED!)
- WYMIARY CHOINKI SA CUSTOMIZOWALNE PRZY POMOCY ZMIENNYCH:
- "lights", "xmas_height", "stump_height", "stump_width" i "filled"
- lights - oznacza jak czesto pojawiaja sie lampki choinkowe (ile ich jest, gestosc)
- Im wieksza wartosc, tym MNIEJ swaitelek // 10 jest optymalne // 0 to zero lampek.
- xmas_height - wysokosc zielonej czesci choinki.
- stump_height - wysokosc pnia
- stump_width - szerokosc pnia
- filled - jesli "true" wypelnia choinke na zielono,
- jesli false pozostawia ja pusta wewnatrz
- AUTOR: GRZEGORZ GAJEWSI
- NUMER ALBUMU:252978
- */
- #include <iostream>
- #include <random>
- #define OS "Unknown"
- #ifdef _WIN32
- // Windows
- #include <windows.h>
- #else
- // Not windows
- #include <ctime>
- #endif
- //
- #include <unistd.h>
- #define RST "\x1B[0m"
- #define KRED "\x1B[31m"
- #define KGRN "\x1B[32m"
- #define KYEL "\x1B[33m"
- #define KBLU "\x1B[34m"
- #define KMAG "\x1B[35m"
- #define KCYN "\x1B[36m"
- #define KWHT "\x1B[37m"
- #define FRED(x) KRED x RST
- #define FGRN(x) KGRN x RST
- #define FYEL(x) KYEL x RST
- #define FBLU(x) KBLU x RST
- #define FMAG(x) KMAG x RST
- #define FCYN(x) KCYN x RST
- #define FWHT(x) KWHT x RST
- #define BOLD(x) "\x1B[1m" x RST
- #define UNDL(x) "\x1B[4m" x RST
- #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
- using namespace std;
- string randomColor() {
- int n = rand()%6;//7
- switch(n) {
- case 0:
- return KRED;
- case 1:
- return KGRN;
- case 2:
- return KYEL;
- case 3:
- return KBLU;
- case 4:
- return KMAG;
- case 5:
- return KCYN;
- case 6:
- return KWHT;
- default:
- return KWHT;
- }
- }
- int main() {
- //Musialem dodac to, aby na Windowsie dzialaly escape characaters do sterowania kolorami...:
- #ifdef _WIN32
- HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
- DWORD consoleMode;
- GetConsoleMode(console, &consoleMode);
- consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
- SetConsoleMode(console, consoleMode);
- #endif
- int lights = 10; // Im wiekszy numer, tym mniej swaitelek // 10 jest optymalne -- 0 to zero lampek.
- int xmas_height=20;
- int stump_height=3;
- int stump_width=6;
- bool filled = false;
- string treeChar = FGRN("#");
- string currentChar =treeChar;
- //Opcje dla choinki:
- //Koniec opcji;
- int mx = xmas_height;
- for(long long int it = 0;; it++) {
- for(int row =1; row<xmas_height; row++) {
- cout<<endl;
- for(int i=0; i<mx-row; i++) {
- cout<<" ";
- }
- for(int column = 1; column<row*2; column++) {
- srand(column*row*it);
- // cout<<(int)rand()%2<<endl;
- if(lights>0)
- if((int)rand()%lights==0 && !(column== 1 || column == row*2-1 || row==xmas_height-1)) {
- string tmp = randomColor();
- currentChar=tmp+"o";
- } else {
- currentChar=treeChar;
- }
- if(!filled) {
- if(column== 1 || column == row*2-1 || row==xmas_height-1 ||currentChar!=treeChar) {
- cout<<(currentChar);
- } else {
- cout<<FGRN(" ");
- }
- } else {
- cout<<(currentChar);
- }
- }
- }
- for(int row =0; row<stump_height; row++) {
- cout<<endl;
- for(int i=0; i<xmas_height-stump_width/2; i++) {
- cout<<" ";
- }
- for(int column = 1; column<stump_width; column++) {
- cout<<FYEL("#");
- }
- cout<<flush;
- }
- #ifdef _WIN32
- Sleep(900);
- system("cls");
- #else
- usleep(3600*150);
- system("clear");
- #endif
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement