Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <stdlib.h>
- #include <chrono>
- #include <ctime>
- #include <thread>
- using namespace std;
- void gotoxy(int x, int z);
- void ShiftToRight(char* arr, int stepsToMoveTheCharToRight, int lenght);
- void ShuffleArray(char* arr, int lenght);
- int FindFirstSymbol(char* arr, int length);
- void ShuffleSymbols(char* arr, int length);
- int FindLastSymbolBeforeSpace(char* arr, int length);
- char** CreateMatrix(int, int, int);
- const int MATRIX_ROWS = 80;
- const int MATRIX_COLS = 25;
- int main()
- {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hConsole, 10);
- srand(time(NULL));
- char** matrix = CreateMatrix(MATRIX_ROWS, MATRIX_COLS, MATRIX_COLS * 3);
- for (int i = 0; i < MATRIX_ROWS; i++)
- {
- ShuffleArray(matrix[i], 75);
- }
- while (true) {
- for (int row = 0; row < MATRIX_ROWS; row++)
- {
- int randShift = rand() % 15;
- for (int col = 0; col < MATRIX_COLS; col++)
- {
- gotoxy(row, col);
- cout << matrix[row][col];
- }
- ShuffleSymbols(matrix[row], 75);
- ShiftToRight(matrix[row], 1, 75);
- }
- Sleep(20);
- }
- return 0;
- }
- void gotoxy(int x, int z) {
- COORD coord;
- coord.X = x;
- coord.Y = z;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- char** CreateMatrix(int rows, int colSizeWithSymbols, int colWholeSize) {
- char** matrix = new char* [rows];
- for (int row = 0; row < rows; row++)
- {
- matrix[row] = new char[colWholeSize + 1];
- for (int col = 0; col < colWholeSize; col++)
- {
- matrix[row][col] = ' ';
- }
- matrix[row][colWholeSize] = '\0';
- }
- for (int row = 0; row < rows; row++)
- {
- int howManyTimesToMoveTheTextToRight = rand() % 2;
- for (int col = 0; col < colSizeWithSymbols; col++)
- {
- int randSymbol = rand() % 127 + 32;
- matrix[row][col + (howManyTimesToMoveTheTextToRight * colSizeWithSymbols)] = randSymbol;
- }
- }
- return matrix;
- }
- void ShuffleArray(char* arr, int lenght) {
- int randHowManyTimesToShiftIt = rand() % 30;
- ShiftToRight(arr, randHowManyTimesToShiftIt, lenght);
- }
- void ShuffleSymbols(char* arr, int length) {
- int startPoint = FindFirstSymbol(arr, length);
- for (int i = startPoint; i < startPoint + MATRIX_COLS; i++)
- {
- arr[i % length] = arr[(i + 1) % length];
- }
- int randSymbol = rand() % 127 + 32;
- arr[((startPoint + MATRIX_COLS) - 2)% length ] = randSymbol;
- }
- int FindLastSymbolBeforeSpace(char* arr, int length) {
- int index = 0;
- for (int i = 0; i < length; i++)
- {
- if (arr[i] != ' ') {
- i++;
- while (arr[i] != ' ') {
- i++;
- }
- index = i - 1;
- break;
- }
- }
- return index;
- }
- int FindFirstSymbol(char* arr, int length) {
- int index = 0;
- for (int i = 0; i < length; i++)
- {
- if (i == 0 && arr[i] != ' ') {
- i++;
- while (arr[i] != ' ')
- i++;
- }
- if (arr[i] != ' ') {
- index = i;
- break;
- }
- }
- return index;
- }
- void ShiftToRight(char* arr, int stepsToMoveTheCharToRight, int lenght) {
- char* newText = new char[lenght];
- for (int i = 0; i < lenght; i++)
- {
- int newPosition = (i + stepsToMoveTheCharToRight) % (lenght);
- newText[newPosition] = arr[i];
- }
- for (int i = 0; i < lenght; i++)
- {
- arr[i] = newText[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement