Advertisement
Spectrewiz

Matrix Code

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