Skip to content

Commit

Permalink
feat: implement dimmed columns
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Oct 21, 2024
1 parent e9d3c63 commit 213ccde
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const Char = struct {

const Column = struct {
active: bool = false,
dimmed: bool = false,
cooldown: u32 = 0,
chars: std.ArrayList(?Char),

Expand Down Expand Up @@ -125,16 +126,25 @@ const Column = struct {
core: *Core,
rand: std.rand.Random,
) !void {
const char = core.newChar(rand);
const char = core.newChar(self.dimmed, rand);
try self.chars.insert(0, char);
}

fn addNull(self: *Column) !void {
try self.chars.insert(0, null);
}

fn activate(self: *Column, core: *Core) void {
fn activate(
self: *Column,
core: *Core,
rand: std.rand.Random,
) void {
if (self.cooldown == 0) {
self.dimmed = if ((std.mem.count(
Accent,
core.accents.?,
&[_]Accent{Accent.dim},
)) > 0) rand.boolean() else false;
self.active = true;
core.active_columns += 1;
}
Expand Down Expand Up @@ -315,15 +325,23 @@ const Core = struct {
}
}

fn newChar(self: *Core, rand: std.rand.Random) Char {
fn newChar(
self: *Core,
dimmed: bool,
rand: std.rand.Random,
) Char {
const rand_int = switch (self.mode) {
.binary => rand.int(u1),
.decimal => rand.uintLessThan(u4, 10),
.hexadecimal => rand.int(u4),
.textual => rand.uintLessThan(u8, 73),
};

var color = @intFromEnum(self.color);
var color = if (dimmed)
@intFromEnum(self.color) | tb.TB_DIM
else
@intFromEnum(self.color);

var bg = self.bg;

if (self.accents) |accents| {
Expand Down Expand Up @@ -475,7 +493,7 @@ fn printCells(
}
}

const char = core.newChar(rand);
const char = core.newChar(false, rand);
const out = try fmtChar(char.i, core.mode);

core.setCell(w, h, char.color, char.bg, out);
Expand All @@ -496,7 +514,7 @@ fn printCells(
try core.columns.?.items[w].?.addChar(core, rand);
}

if (!core.debug) core.columns.?.items[w].?.activate(core);
if (!core.debug) core.columns.?.items[w].?.activate(core, rand);
}
}

Expand All @@ -514,7 +532,7 @@ fn printCells(
u32,
core.width,
)
].?.activate(core);
].?.activate(core, rand);
}

for (0..core.width) |w| {
Expand Down Expand Up @@ -694,7 +712,7 @@ fn intro(
continue :char;
}

const char = core.newChar(rand);
const char = core.newChar(false, rand);
const out = try fmtChar(char.i, core.mode);

core.setCell(
Expand Down

0 comments on commit 213ccde

Please sign in to comment.