-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
66 lines (57 loc) · 2.26 KB
/
Copy pathProgram.cs
File metadata and controls
66 lines (57 loc) · 2.26 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
using System.Diagnostics;
using System.Text;
namespace NeonGrid;
/// <summary>
/// NEONGRID — a cyberpunk "digital rain" terminal renderer.
/// Pure C#, zero dependencies, raw ANSI escape codes, double-buffered.
/// Each column is an independent falling "stream" with a bright head and a fading neon tail.
/// </summary>
internal static class Program
{
private static void Main(string[] args)
{
var palette = Palette.From(args);
Console.OutputEncoding = Encoding.UTF8;
Console.CursorVisible = false;
Console.Clear();
// Switch terminal to alternate screen buffer so the user's scrollback is preserved.
Console.Write(Ansi.EnterAltScreen);
var stopwatch = Stopwatch.StartNew();
var cancel = false;
Console.CancelKeyPress += (_, e) => { e.Cancel = true; cancel = true; };
try
{
int width = 0, height = 0;
GridRenderer? renderer = null;
while (!cancel)
{
// Handle live resize and keypresses without blocking the render loop.
if (Console.WindowWidth != width || Console.WindowHeight != height || renderer is null)
{
width = Math.Max(Console.WindowWidth, 10);
height = Math.Max(Console.WindowHeight - 1, 5);
renderer = new GridRenderer(width, height, palette);
Console.Write(Ansi.Clear);
}
if (Console.KeyAvailable)
{
var key = Console.ReadKey(intercept: true).Key;
if (key is ConsoleKey.Q or ConsoleKey.Escape) break;
if (key is ConsoleKey.Spacebar) palette = palette.Next();
renderer = new GridRenderer(width, height, palette);
}
renderer.Step();
Console.Write(renderer.Compose(stopwatch.Elapsed.TotalSeconds));
Thread.Sleep(33); // ~30 FPS
}
}
finally
{
Console.Write(Ansi.LeaveAltScreen);
Console.CursorVisible = true;
Console.ResetColor();
Console.Clear();
Console.WriteLine("NEONGRID // session terminated. stay jacked in.\n");
}
}
}