- [DEVEXPRESS] Chia sẻ code các tạo report in nhiều hóa đơn trên XtraReport C#
- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
[C#] Chia sẽ source code Matrix Rain trên Console
Xin chào các bạn, bài viết hôm nay mình tiếp tục chia sẻ đến các bạn source code Matrix Rain trên Console lập trình C#.
[C#] Effect matrix rain console
Bài viết source code được mình lấy từ tác giả: theilgazcode trên github nhé các bạn.
Dưới đây là giao diện demo ứng dụng Matrix Rain C#:
Video demo:
Full source code C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MatrixRain
{
class Program
{
// fields
static Random rand = new Random();
// properties
static char AsciiCharacter
{
get
{
int t = rand.Next(10);
if (t <= 2)
// returns a number
return (char)('0' + rand.Next(10));
else if (t <= 4)
// small letter
return (char)('a' + rand.Next(27));
else if (t <= 6)
// capital letter
return (char)('A' + rand.Next(27));
else
// any ascii character
return (char)(rand.Next(32, 255));
}
}
// methods
static void Main()
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WindowLeft = Console.WindowTop = 0;
Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
//Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
//Console.WriteLine("1LG4ZD0TC0M");
//Console.WriteLine("H1T 4NY K3Y T0 C0NT1NU3");
//Console.ReadKey();
Console.CursorVisible = false;
int width, height;
// setup array of starting y values
int[] y;
// width was 209, height was 81
// setup the screen and initial conditions of y
Initialize(out width, out height, out y);
// do the Matrix effect
// every loop all y's get incremented by 1
while (true)
UpdateAllColumns(width, height, y);
}
private static void UpdateAllColumns(int width, int height, int[] y)
{
int x;
// draws 3 characters in each x column each time...
// a dark green, light green, and a space
// y is the position on the screen
// y[x] increments 1 each time so each loop does the same thing but down 1 y value
for (x = 0; x < width; ++x)
{
// the bright green character
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(x, y[x]);
Console.Write(AsciiCharacter);
// the dark green character - 2 positions above the bright green character
Console.ForegroundColor = ConsoleColor.DarkGreen;
int temp = y[x] - 2;
Console.SetCursorPosition(x, inScreenYPosition(temp, height));
Console.Write(AsciiCharacter);
// the 'space' - 20 positions above the bright green character
int temp1 = y[x] - 20;
Console.SetCursorPosition(x, inScreenYPosition(temp1, height));
Console.Write(' ');
// increment y
y[x] = inScreenYPosition(y[x] + 1, height);
}
// F5 to reset, F11 to pause and unpause
if (Console.KeyAvailable)
{
if (Console.ReadKey().Key == ConsoleKey.F5)
Initialize(out width, out height, out y);
if (Console.ReadKey().Key == ConsoleKey.F11)
System.Threading.Thread.Sleep(1);
}
}
// Deals with what happens when y position is off screen
public static int inScreenYPosition(int yPosition, int height)
{
if (yPosition < 0)
return yPosition + height;
else if (yPosition < height)
return yPosition;
else
return 0;
}
// only called once at the start
private static void Initialize(out int width, out int height, out int[] y)
{
height = Console.WindowHeight;
width = Console.WindowWidth - 1;
// 209 for me.. starting y positions of bright green characters
y = new int[width];
Console.Clear();
// loops 209 times for me
for (int x = 0; x < width; ++x)
{
// gets random number between 0 and 81
y[x] = rand.Next(height);
}
}
}
}
Thanks for watching!