Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <chrono>
  5. #include <ctime>
  6. #include <thread>
  7.  
  8. using namespace std;
  9. void gotoxy(int x, int z);
  10. void ShiftToRight(char* arr, int stepsToMoveTheCharToRight, int lenght);
  11. void ShuffleArray(char* arr, int lenght);
  12.  
  13. int FindFirstSymbol(char* arr, int length);
  14. void ShuffleSymbols(char* arr, int length);
  15. int FindLastSymbolBeforeSpace(char* arr, int length);
  16.  
  17. char** CreateMatrix(int, int, int);
  18.  
  19. const int MATRIX_ROWS = 80;
  20. const int MATRIX_COLS = 25;
  21.  
  22. int main()
  23. {
  24.  
  25.  
  26. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  27.  
  28. SetConsoleTextAttribute(hConsole, 10);
  29.  
  30. srand(time(NULL));
  31.  
  32. char** matrix = CreateMatrix(MATRIX_ROWS, MATRIX_COLS, MATRIX_COLS * 3);
  33. for (int i = 0; i < MATRIX_ROWS; i++)
  34. {
  35. ShuffleArray(matrix[i], 75);
  36. }
  37.  
  38. while (true) {
  39. for (int row = 0; row < MATRIX_ROWS; row++)
  40. {
  41. int randShift = rand() % 15;
  42.  
  43. for (int col = 0; col < MATRIX_COLS; col++)
  44. {
  45. gotoxy(row, col);
  46. cout << matrix[row][col];
  47. }
  48. ShuffleSymbols(matrix[row], 75);
  49. ShiftToRight(matrix[row], 1, 75);
  50. }
  51.  
  52.  
  53. Sleep(20);
  54. }
  55.  
  56.  
  57.  
  58. return 0;
  59. }
  60.  
  61. void gotoxy(int x, int z) {
  62. COORD coord;
  63. coord.X = x;
  64. coord.Y = z;
  65. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  66. }
  67.  
  68. char** CreateMatrix(int rows, int colSizeWithSymbols, int colWholeSize) {
  69.  
  70. char** matrix = new char* [rows];
  71. for (int row = 0; row < rows; row++)
  72. {
  73. matrix[row] = new char[colWholeSize + 1];
  74. for (int col = 0; col < colWholeSize; col++)
  75. {
  76. matrix[row][col] = ' ';
  77. }
  78. matrix[row][colWholeSize] = '\0';
  79. }
  80.  
  81. for (int row = 0; row < rows; row++)
  82. {
  83. int howManyTimesToMoveTheTextToRight = rand() % 2;
  84.  
  85. for (int col = 0; col < colSizeWithSymbols; col++)
  86. {
  87. int randSymbol = rand() % 127 + 32;
  88. matrix[row][col + (howManyTimesToMoveTheTextToRight * colSizeWithSymbols)] = randSymbol;
  89. }
  90.  
  91. }
  92.  
  93. return matrix;
  94. }
  95.  
  96. void ShuffleArray(char* arr, int lenght) {
  97. int randHowManyTimesToShiftIt = rand() % 30;
  98.  
  99. ShiftToRight(arr, randHowManyTimesToShiftIt, lenght);
  100. }
  101.  
  102. void ShuffleSymbols(char* arr, int length) {
  103. int startPoint = FindFirstSymbol(arr, length);
  104.  
  105.  
  106. for (int i = startPoint; i < startPoint + MATRIX_COLS; i++)
  107. {
  108. arr[i % length] = arr[(i + 1) % length];
  109. }
  110.  
  111. int randSymbol = rand() % 127 + 32;
  112.  
  113. arr[((startPoint + MATRIX_COLS) - 2)% length ] = randSymbol;
  114. }
  115.  
  116. int FindLastSymbolBeforeSpace(char* arr, int length) {
  117. int index = 0;
  118.  
  119. for (int i = 0; i < length; i++)
  120. {
  121. if (arr[i] != ' ') {
  122. i++;
  123. while (arr[i] != ' ') {
  124. i++;
  125. }
  126. index = i - 1;
  127. break;
  128. }
  129. }
  130.  
  131. return index;
  132. }
  133.  
  134. int FindFirstSymbol(char* arr, int length) {
  135. int index = 0;
  136.  
  137. for (int i = 0; i < length; i++)
  138. {
  139. if (i == 0 && arr[i] != ' ') {
  140. i++;
  141. while (arr[i] != ' ')
  142. i++;
  143. }
  144.  
  145. if (arr[i] != ' ') {
  146. index = i;
  147. break;
  148. }
  149. }
  150.  
  151. return index;
  152. }
  153.  
  154. void ShiftToRight(char* arr, int stepsToMoveTheCharToRight, int lenght) {
  155.  
  156. char* newText = new char[lenght];
  157.  
  158. for (int i = 0; i < lenght; i++)
  159. {
  160. int newPosition = (i + stepsToMoveTheCharToRight) % (lenght);
  161. newText[newPosition] = arr[i];
  162. }
  163.  
  164. for (int i = 0; i < lenght; i++)
  165. {
  166. arr[i] = newText[i];
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement