Guest User

Untitled

a guest
Jan 24th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace MatrixRevolution
  7. {
  8.     class Program
  9.     {
  10.         private static readonly int MatrixWidth = Console.LargestWindowWidth;
  11.         private static readonly int MatrixHeight = Console.LargestWindowHeight;
  12.  
  13.         private static char[,] matrix;
  14.  
  15.         private static Random rand = new Random();
  16.  
  17.         private static void InitializeMatrix(out char[,] matrix, int width, int height)
  18.         {
  19.             matrix = new char[width, height];
  20.  
  21.             for (int x = 0; x < matrix.GetLength(0); x++)
  22.             {
  23.                 int y = 0;
  24.                 int odd = x % 2 == 0 ? 0 : 1;
  25.  
  26.                 while (y < matrix.GetLength(1))
  27.                 {
  28.                     int tmpHeight = rand.Next(1, height);
  29.  
  30.                     if (y + tmpHeight > height)
  31.                         break;
  32.  
  33.                     for (int i = 0; i < tmpHeight; i++)
  34.                     {
  35.                         matrix[x,y+i] = odd % 2 == 0 ? (char)rand.Next(32,125) : ' ';
  36.                     }
  37.  
  38.                     odd++;
  39.                     y += tmpHeight;
  40.                 }
  41.             }
  42.         }
  43.  
  44.         private static void PrintMatrix(char [,] matrix)
  45.         {
  46.             for (int x = 0; x < matrix.GetLength(0); x++)
  47.             {
  48.                 for (int y = 0; y < matrix.GetLength(1); y++)
  49.                 {
  50.                     Console.SetCursorPosition(x, y);
  51.                     Console.Write(matrix[x, y]);
  52.                 }
  53.             }
  54.         }
  55.  
  56.         private static void MoveRows(char [,] matrix)
  57.         {
  58.             for (int x = 0; x < matrix.GetLength(0); x++)
  59.             {
  60.                 char last = matrix[x, matrix.GetLength(1) - 1];
  61.                 for (int y = matrix.GetLength(1) - 1; y > 0; y--)
  62.                 {
  63.                     matrix[x, y] = matrix[x, y-1];
  64.                 }
  65.                 matrix[x, 0] = last;
  66.             }
  67.         }
  68.  
  69.         static void Main(string[] args)
  70.         {
  71.             Console.WindowHeight = Console.BufferHeight = MatrixHeight;
  72.             Console.WindowWidth = Console.BufferWidth = MatrixWidth;
  73.             Console.ForegroundColor = ConsoleColor.DarkGreen;
  74.             Console.WindowLeft = Console.WindowTop = 0;
  75.  
  76.             //InitializeMatrix(out matrix, MatrixWidth, MatrixHeight);
  77.             //PrintMatrix(matrix);
  78.  
  79.             //for (int i = 0; i < 50; i++)
  80.             //{
  81.             //    MoveRows(matrix);
  82.             //    PrintMatrix(matrix);
  83.             //}
  84.  
  85.             int[] y = new int[MatrixWidth];
  86.             int[] length = new int[MatrixWidth];
  87.  
  88.             for (int x = 0; x < MatrixWidth; x++)
  89.             {
  90.                 y[x] = rand.Next(1, MatrixHeight);
  91.                 length[x] = rand.Next(1, MatrixHeight - y[x]);
  92.             }
  93.  
  94.             for (int x= 0; x < MatrixWidth; x++)
  95.             {
  96.                 for (int i = 0; i < length[x]; i++)
  97.                 {
  98.                     Console.CursorVisible = false;
  99.                     Console.SetCursorPosition(x, y[x] + i);
  100.                     Console.Write((char)rand.Next(32, 125));
  101.                 }
  102.             }
  103.  
  104.  
  105.             //int newY = y[5] + length[5];
  106.  
  107.             for (int i = 0; i < 6000; i++)
  108.             {
  109.                 for (int x = 0; x < MatrixWidth-1; x++)
  110.                 {
  111.                     y[x] = y[x] < MatrixHeight ? y[x] : 0;
  112.                     Console.SetCursorPosition(x, y[x]++);
  113.                     Console.Write(' ');
  114.  
  115.                     int newY = y[x] + length[x] < MatrixHeight ? y[x] + length[x] : (y[x] + length[x]) - MatrixHeight;
  116.                     Console.SetCursorPosition(x, newY++);
  117.                     Console.Write((char)rand.Next(32, 125));
  118.                    
  119.                     x = i % 2 == 0 ? x : x + 1;
  120.                     x = i % 3 == 0 ? x : x + 2;
  121.                 }
  122.  
  123.                 System.Threading.Thread.Sleep(40);
  124.             }
  125.  
  126.             Console.ReadLine();
  127.         }
  128.     }
  129. }
Add Comment
Please, Sign In to add comment