Skip to content

Commit

Permalink
Tweak color hashing a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamii committed Aug 31, 2021
1 parent a63e079 commit 1874940
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/focus/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ pub const Color = packed struct {

pub fn hsl(h: f64, s: f64, l: f64) Color {
assert(h >= 0 and h < 360);
assert(s >= 0 and s < 1);
assert(l >= 0 and l < 1);
const ch = (1 - @fabs((2 * l) - 1)) * s;
const x = ch * (1 - @fabs(@mod(h / 60, 2) - 1));
const m = l - (ch / 2);
Expand Down
12 changes: 3 additions & 9 deletions lib/focus/style.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ pub const multi_cursor_color = Color{ .r = 0x7a, .g = 0xa6, .b = 0xda, .a = 255
pub const paren_match_color = Color{ .r = 0x7a, .g = 0xa6, .b = 0xda, .a = 100 };

pub fn highlightColor(ident: []const u8) Color {
const hash = focus.meta.deepHash(ident);
const hash = focus.meta.deepHash(.{ @intCast(u64, 7919), ident });
const saturation = [3]f64{ 0.4, 0.6, 0.8 };
return Color.hsl(
@intToFloat(f64, hash % 360),
0.8,
//0.5 + (@intToFloat(f64, (hash >> 8) % 256) / 512),
saturation[@divTrunc(hash, 360) % 3],
0.8,
);
//return .{
// .r = @intCast(u8, 192 + ((hash >> 0) % 64)),
// .g = @intCast(u8, 192 + ((hash >> 8) % 64)),
// .b = @intCast(u8, 192 + ((hash >> 16) % 64)),
// .a = 255,
//};
}

0 comments on commit 1874940

Please sign in to comment.