Allow changing matrix animation min/max codepoints (closes #615)

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2025-03-06 19:48:11 +01:00
parent d12fa27168
commit d80ec8fd1f
No known key found for this signature in database
4 changed files with 19 additions and 9 deletions

View File

@ -77,6 +77,14 @@ clock = null
# CMatrix animation foreground color id
cmatrix_fg = 0x0000FF00
# CMatrix animation minimum codepoint. It uses a 16-bit integer
# For Japanese characters for example, you can use 0x3000 here
cmatrix_min_codepoint = 0x21
# CMatrix animation maximum codepoint. It uses a 16-bit integer
# For Japanese characters for example, you can use 0x30FF here
cmatrix_max_codepoint = 0x7B
# Color mixing animation first color id
colormix_col1 = 0x00FF0000

View File

@ -9,10 +9,6 @@ const termbox = interop.termbox;
pub const FRAME_DELAY: usize = 8;
// Allowed codepoints
pub const MIN_CODEPOINT: u16 = 33;
pub const MAX_CODEPOINT: u16 = 123 - MIN_CODEPOINT;
// Characters change mid-scroll
pub const MID_SCROLL_CHANGE = true;
@ -36,8 +32,10 @@ lines: []Line,
frame: usize,
count: usize,
fg_ini: u32,
min_codepoint: u16,
max_codepoint: u16,
pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_ini: u32) !Matrix {
pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_ini: u32, min_codepoint: u16, max_codepoint: u16) !Matrix {
const dots = try allocator.alloc(Dot, terminal_buffer.width * (terminal_buffer.height + 1));
const lines = try allocator.alloc(Line, terminal_buffer.width);
@ -51,6 +49,8 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_ini: u32)
.frame = 3,
.count = 0,
.fg_ini = fg_ini,
.min_codepoint = min_codepoint,
.max_codepoint = max_codepoint - min_codepoint,
};
}
@ -91,7 +91,7 @@ pub fn draw(self: *Matrix) void {
const randint = self.terminal_buffer.random.int(u16);
const h = self.terminal_buffer.height;
line.length = @mod(randint, h - 3) + 3;
self.dots[x].value = @mod(randint, MAX_CODEPOINT) + MIN_CODEPOINT;
self.dots[x].value = @mod(randint, self.max_codepoint) + self.min_codepoint;
line.space = @mod(randint, h + 1);
}
}
@ -116,7 +116,7 @@ pub fn draw(self: *Matrix) void {
if (MID_SCROLL_CHANGE) {
const randint = self.terminal_buffer.random.int(u16);
if (@mod(randint, 8) == 0) {
dot.value = @mod(randint, MAX_CODEPOINT) + MIN_CODEPOINT;
dot.value = @mod(randint, self.max_codepoint) + self.min_codepoint;
}
}
@ -131,7 +131,7 @@ pub fn draw(self: *Matrix) void {
}
const randint = self.terminal_buffer.random.int(u16);
dot.value = @mod(randint, MAX_CODEPOINT) + MIN_CODEPOINT;
dot.value = @mod(randint, self.max_codepoint) + self.min_codepoint;
dot.is_head = true;
if (seg_len > line.length or !first_col) {

View File

@ -22,6 +22,8 @@ brightness_up_key: ?[]const u8 = "F6",
clear_password: bool = false,
clock: ?[:0]const u8 = null,
cmatrix_fg: u32 = 0x0000FF00,
cmatrix_min_codepoint: u16 = 0x21,
cmatrix_max_codepoint: u16 = 0x7B,
colormix_col1: u32 = 0x00FF0000,
colormix_col2: u32 = 0x000000FF,
colormix_col3: u32 = 0x20000000,

View File

@ -338,7 +338,7 @@ pub fn main() !void {
switch (config.animation) {
.none => {},
.doom => doom = try Doom.init(allocator, &buffer),
.matrix => matrix = try Matrix.init(allocator, &buffer, config.cmatrix_fg),
.matrix => matrix = try Matrix.init(allocator, &buffer, config.cmatrix_fg, config.cmatrix_min_codepoint, config.cmatrix_max_codepoint),
.colormix => color_mix = ColorMix.init(&buffer, config.colormix_col1, config.colormix_col2, config.colormix_col3),
}
defer {