This repository was archived by the owner on Aug 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetPrint.cs
More file actions
72 lines (59 loc) · 2.33 KB
/
LeetPrint.cs
File metadata and controls
72 lines (59 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LeetPrint
{
internal class Printer
{
public void Print(string message, int delay = 10, int rounds = 10, bool newLine = false, string symbols = "!§$%&/?*+#-><^.:,;°[]{}##++")
{
// All symbols that will be used
Random ran = new Random();
// Get current console buffer and window sizes
// Needed to avoid system.OutOfArgumentsException when
// the string is wider than the consoles width
int bufferWidth = Console.BufferWidth;
int windowWidth = Console.WindowWidth;
// Get current cursor position
int cursorTop = Console.GetCursorPosition().Top;
int cursorLeft = 0;
// Foreach letter in the message
for (int i = 0; i < message.Length; i++)
{
// Check if cursor position is equal to console width
if (cursorLeft >= windowWidth)
{
// Enter next line
Console.WriteLine();
// Reset cursor position to zero
cursorLeft = 0;
// Increment cursor top value (one line down)
cursorTop++;
}
// go through the rounds to "obfuscate" the letters
for (int ii = 0; ii < rounds; ii++)
{
// Set desired cursor position
Console.SetCursorPosition(cursorLeft, cursorTop);
// Get random symbol
var random_symbol = symbols[ran.Next(symbols.Length)];
Console.Write(random_symbol);
// Sleep so the effect can be seen
Thread.Sleep(delay);
}
// Set desired cursor position
Console.SetCursorPosition(cursorLeft, cursorTop);
// Write actual symbol
Console.Write(message[i]);
// Increase left padding
cursorLeft++;
}
if (newLine)
{
Console.WriteLine();
}
}
}
}