From a5e38e2ce5c830576431700c177707dcab3598ec Mon Sep 17 00:00:00 2001 From: thoxy Date: Tue, 17 Jun 2025 12:35:22 +0200 Subject: [PATCH] Remove color randomization from Game of Life animation --- res/config.ini | 5 ----- src/animations/GameOfLife.zig | 18 +++--------------- src/config/Config.zig | 1 - 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/res/config.ini b/res/config.ini index b405f2f..df6d721 100644 --- a/res/config.ini +++ b/res/config.ini @@ -147,11 +147,6 @@ gameoflife_frame_delay = 6 # 0.7+ -> Dense, chaotic patterns gameoflife_initial_density = 0.4 -# Game of Life randomize colors (true/false) -# false -> Use the fixed gameoflife_fg color -# true -> Generate one random color at startup and use it for the entire session -gameoflife_randomize_colors = false - # Remove main box borders hide_borders = false diff --git a/src/animations/GameOfLife.zig b/src/animations/GameOfLife.zig index 785c236..9cbefaa 100644 --- a/src/animations/GameOfLife.zig +++ b/src/animations/GameOfLife.zig @@ -4,7 +4,6 @@ const Cell = @import("../tui/Cell.zig"); const TerminalBuffer = @import("../tui/TerminalBuffer.zig"); const Allocator = std.mem.Allocator; -const Random = std.Random; const GameOfLife = @This(); @@ -27,12 +26,11 @@ fg_color: u32, entropy_interval: usize, frame_delay: usize, initial_density: f32, -randomize_colors: bool, dead_cell: Cell, width: usize, height: usize, -pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_color: u32, entropy_interval: usize, frame_delay: usize, initial_density: f32, randomize_colors: bool) !GameOfLife { +pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_color: u32, entropy_interval: usize, frame_delay: usize, initial_density: f32) !GameOfLife { const width = terminal_buffer.width; const height = terminal_buffer.height; const grid_size = width * height; @@ -47,11 +45,10 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_color: u3 .next_grid = next_grid, .frame_counter = 0, .generation = 0, - .fg_color = if (randomize_colors) generateRandomColor(terminal_buffer.random) else fg_color, + .fg_color = fg_color, .entropy_interval = entropy_interval, .frame_delay = frame_delay, .initial_density = initial_density, - .randomize_colors = randomize_colors, .dead_cell = .{ .ch = DEAD_CHAR, .fg = @intCast(TerminalBuffer.Color.DEFAULT), .bg = terminal_buffer.bg }, .width = width, .height = height, @@ -103,7 +100,7 @@ fn draw(self: *GameOfLife) void { } } - // Render with the set color (either configured or randomly generated at startup) + // Render with the configured color const alive_cell = Cell{ .ch = ALIVE_CHAR, .fg = self.fg_color, .bg = self.terminal_buffer.bg }; for (0..self.height) |y| { @@ -115,15 +112,6 @@ fn draw(self: *GameOfLife) void { } } -fn generateRandomColor(random: Random) u32 { - // Generate a random RGB color with good visibility - // Avoid very dark colors by using range 64-255 for each component - const r = random.intRangeAtMost(u8, 64, 255); - const g = random.intRangeAtMost(u8, 64, 255); - const b = random.intRangeAtMost(u8, 64, 255); - return (@as(u32, r) << 16) | (@as(u32, g) << 8) | @as(u32, b); -} - fn updateGeneration(self: *GameOfLife) void { // Conway's Game of Life rules with optimized neighbor counting for (0..self.height) |y| { diff --git a/src/config/Config.zig b/src/config/Config.zig index 60dad89..e4030ce 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -40,7 +40,6 @@ gameoflife_fg: u32 = 0x0000FF00, gameoflife_entropy_interval: usize = 10, gameoflife_frame_delay: usize = 6, gameoflife_initial_density: f32 = 0.4, -gameoflife_randomize_colors: bool = false, hide_borders: bool = false, hide_key_hints: bool = false, initial_info_text: ?[]const u8 = null,