Advertisement
avr39ripe

BR012cycleFrame

Feb 10th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <thread>
  4.  
  5.  
  6. /*
  7. *******
  8. *#####*
  9. *#***#*
  10. *#***#*
  11. *#***#*
  12. *#####*
  13. *******
  14. */
  15.  
  16. int main()
  17. {
  18.     const char* CSI = "\033[";
  19.     const char* CLRSCR = "2J";
  20.  
  21.     int side{15};
  22.     int sub{ 1 };
  23.     //std::cout << "enter line length\n";
  24.     //std::cin >> side;
  25.     const char pos = '#';
  26.     const char neg = ' ';
  27.     bool positive{ false };
  28.     bool hPositive{ false };
  29.     bool vPositive{ false };
  30.  
  31.     const int maxLoop{ 6 };
  32.     const int minLoop{ 0 };
  33.  
  34.     int loop{ minLoop };
  35.     int loopStep{ 1 };
  36.  
  37.  
  38.     while (true)
  39.     {
  40.         if ((loop >= maxLoop and loopStep > 0) or (loop <= minLoop and loopStep < 0))
  41.         {
  42.             loopStep *= -1;
  43.             std::cout << '\n';
  44.         }
  45.  
  46.         sub = loop;
  47.  
  48.         for (int y{ 0 }; y < side; ++y)
  49.         {
  50.             for (int x{ 0 }; x < side; ++x)
  51.             {
  52.                 hPositive = ((y == sub or y == (side - 1 - sub)) and (x >= sub and x <= (side - 1 - sub)));
  53.                 vPositive = ((x == sub or x == (side - 1 - sub)) and (y >= sub and y <= (side - 1 - sub)));
  54.                 positive = (hPositive or vPositive);
  55.  
  56.                 std::cout << ' ' << (positive ? pos : neg) << ' ';
  57.             }
  58.             std::cout << '\n';
  59.         }
  60.         std::this_thread::sleep_for(std::chrono::milliseconds(1000)); //make some pause for better output look :)
  61.         std::cout << CSI << CLRSCR; //portable clear screen
  62.  
  63.         loop += loopStep;
  64.     }
  65.    
  66.     return 0;
  67. }
  68. //std::this_thread::sleep_for(std::chrono::milliseconds(200)); //make some pause for better output look :)
  69. //const char* CSI = "\033[";
  70. //std::cout << CSI << "2J"; //portable clear screen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement