diff --git a/res/config.ini b/res/config.ini index b568697..3ff7bb3 100644 --- a/res/config.ini +++ b/res/config.ini @@ -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 diff --git a/src/animations/Matrix.zig b/src/animations/Matrix.zig index 3576245..18636fc 100644 --- a/src/animations/Matrix.zig +++ b/src/animations/Matrix.zig @@ -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) { diff --git a/src/config/Config.zig b/src/config/Config.zig index 5b8de0f..ec5bd9e 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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, diff --git a/src/main.zig b/src/main.zig index 16a1e39..69830c0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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 {