, List<string> lines;, , , . , ( lines[0]) .
. - , . , , .
, . , , , (Console.WindowHeight). , lines[0], . , List<string> lines "" .
Thread.Sleep, Timer , (, "", "" ). , , enum , , Thread.Sleep:
class Program
{
enum MatrixCodeSpeed
{
Fastest = 0,
Faster = 33,
Fast = 67,
Normal = 100,
Slow = 333,
Slower = 667,
Slowest = 1000
}
, "" . , "", , . density , , 10, 0 99, 10, ( ).
, , 4 , . , , :
private static Random rnd = new Random();
private static char[] matrixChars = new[] { '░', '▒', '▓', '█' };
static string GetMatrixLine(int density)
{
var line = new StringBuilder();
for (int i = 0; i < Console.WindowWidth; i++)
{
line.Append(rnd.Next(100) > density
? ' '
: matrixChars[rnd.Next(matrixChars.Length)]);
}
return line.ToString();
}
, ( 10%), , , ( if ):
static void Main()
{
var lines = new List<string>();
var density = 10;
var speed = MatrixCodeSpeed.Normal;
Console.CursorVisible = false;
Console.ForegroundColor = ConsoleColor.DarkGreen;
while (true)
{
if (lines.Count >= Console.WindowHeight)
{
lines.Remove(lines[0]);
}
lines.Add(GetMatrixLine(density));
Console.SetCursorPosition(0, 0);
for (int i = lines.Count - 1; i >= 0; i--)
{
Console.Write(lines[i]);
}
Thread.Sleep(TimeSpan.FromMilliseconds((int)speed));
}
}
}
gif , , ( gif , ):
