avr39-ripe

bounce2

May 8th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <chrono>
  4. #include <thread>
  5.  
  6. using namespace std;
  7. int main()
  8. {
  9.     const char* CSI = "\033[";
  10.     cout << CSI << "?25l"; //Remove cursor from screen
  11.     for (int x = 1, y = 1, x1 = 10, y1 = 10, dx = 1, dy = 1, dx1 = 2, dy1 = -2; ; x += dx, y += dy, x1 += dx1, y1 += dy1)
  12.     {
  13.         if (y > 24 or y < 1) { dy = dy * (-1); y += dy; }
  14.         if (x > 79 or x < 1) { dx = dx * (-1); x += dx; }
  15.  
  16.         if (y1 > 24 or y1 < 1) { dy1 = dy1 * (-1); y1 += dy1; }
  17.         if (x1 > 79 or x1 < 1) { dx1 = dx1 * (-1); x1 += dx1; }
  18.  
  19.         //std::cout << CSI << "2J" << std::endl; //clear screen
  20.  
  21.         // \033[y;xH = position output to y,x \033[XXm = change text color to XX color, \033[0m = change color to default
  22.  
  23.         std::cout << CSI << y << ";" << x << "H" << CSI << 31 << "m" << "*" << CSI << "0m" << std::endl;
  24.         std::cout << CSI << y1 << ";" << x1 << "H" << CSI << 33 << "m" << "*" << CSI << "0m" << std::endl;
  25.        
  26.         std::this_thread::sleep_for(std::chrono::milliseconds(100));
  27.  
  28.         std::cout << CSI << y << ";" << x << "H" << CSI << 30 << "m" << "*" << CSI << "0m" << std::endl;
  29.         std::cout << CSI << y1 << ";" << x1 << "H" << CSI << 30 << "m" << "*" << CSI << "0m" << std::endl;
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment