skipter

Matrix effect in cmd by M7tr1x

May 24th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.95 KB | None | 0 0
  1.  
  2. using System;
  3.  
  4.     namespace m7tr1x
  5.     {
  6.         class Program
  7.         {
  8.             static void Main(string[] args)
  9.             {
  10.                 Console.Title = "Learning";
  11.                 Console.ForegroundColor = ConsoleColor.DarkGreen;
  12.                 Console.WindowLeft = Console.WindowTop = 0;
  13.                 Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
  14.                 Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
  15. #if readkey
  16.                 Console.WriteLine("H1T 7NY K3Y T0 C0NT1NU3 =/");
  17.                 Console.ReadKey();
  18. #endif
  19.                 Console.CursorVisible = false;
  20.                 int width, height;
  21.                 int[] y;
  22.                 int[] l;
  23.                 Initialize(out width, out height, out y, out l);
  24.                 int ms;
  25.                 while (true)
  26.                 {
  27.                     DateTime t1 = DateTime.Now;
  28.                     MatrixStep(width, height, y, l);
  29.                     ms = 10 - (int)((TimeSpan)(DateTime.Now - t1)).TotalMilliseconds;
  30.                     if (ms > 0)
  31.                         System.Threading.Thread.Sleep(ms);
  32.                     if (Console.KeyAvailable)
  33.                         if (Console.ReadKey().Key == ConsoleKey.F5)
  34.                             Initialize(out width, out height, out y, out l);
  35.                 }
  36.             }
  37.  
  38.             static bool thistime = false;
  39.  
  40.             private static void MatrixStep(int width, int height, int[] y, int[] l)
  41.             {
  42.                 int x;
  43.                 thistime = !thistime;
  44.                 for (x = 0; x < width; ++x)
  45.                 {
  46.                     if (x % 11 == 10)
  47.                     {
  48.                         if (!thistime)
  49.                             continue;
  50.                         Console.ForegroundColor = ConsoleColor.White;
  51.                     }
  52.                     else
  53.                     {
  54.                         Console.ForegroundColor = ConsoleColor.DarkGreen;
  55.                         Console.SetCursorPosition(x, inBoxY(y[x] - 2 - (l[x] / 40 * 2), height));
  56.                         Console.Write(R);
  57.                         Console.ForegroundColor = ConsoleColor.Green;
  58.                     }
  59.                     Console.SetCursorPosition(x, y[x]);
  60.                     Console.Write(R);
  61.                     y[x] = inBoxY(y[x] + 1, height);
  62.                     Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height));
  63.                     Console.Write(' ');
  64.                 }
  65.             }
  66.  
  67.             private static void Initialize(out int width, out int height, out int[] y, out int[] l)
  68.             {
  69.                 int h1;
  70.                 int h2 = (h1 = (height = Console.WindowHeight) / 2) / 2;
  71.                 width = Console.WindowWidth - 1;
  72.                 y = new int[width];
  73.                 l = new int[width];
  74.                 int x;
  75.                 Console.Clear();
  76.                 for (x = 0; x < width; ++x)
  77.                 {
  78.                     y[x] = r.Next(height);
  79.                     l[x] = r.Next(h2 * ((x % 11 != 10) ? 2 : 1), h1 * ((x % 11 != 10) ? 2 : 1));
  80.                 }
  81.             }
  82.  
  83.             static Random r = new Random();
  84.             static char R
  85.             {
  86.                 get
  87.                 {
  88.                     int t = r.Next(10);
  89.                     if (t <= 2)
  90.                         return (char)('0' + r.Next(10));
  91.                     else if (t <= 4)
  92.                         return (char)('a' + r.Next(27));
  93.                     else if (t <= 6)
  94.                         return (char)('A' + r.Next(27));
  95.                     else
  96.                         return (char)(r.Next(32, 255));
  97.                 }
  98.             }
  99.  
  100.             public static int inBoxY(int n, int height)
  101.             {
  102.                 n = n % height;
  103.                 if (n < 0)
  104.                     return n + height;
  105.                 else
  106.                     return n;
  107.             }
  108.         }
  109.     }
Advertisement
Add Comment
Please, Sign In to add comment