Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/MatrixScreenSaver/NativeMatrixRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1293,12 +1293,16 @@ final class NativeMatrixRenderer {
}

if minimum + 1 < levels {
// The xterm cube quantizes each channel to 6 steps (0, 95, 135,
// 175, 215, 255). A 0.95 cap still rounds back up to 255, so the
// highlight must stay below 0.9 to avoid pure white.
let highlightCap = 0.89
for level in (minimum + 1)..<levels {
let remaining = Double(levels - 1 - level)
let denominator = Double(levels - 1 - minimum)
let r = 1.0 - (1.0 - Double(red) / edge) * (remaining / denominator)
let r = highlightCap - (highlightCap - Double(red) / edge) * (remaining / denominator)
let g = 1.0 - (1.0 - Double(green) / edge) * (remaining / denominator)
let b = 1.0 - (1.0 - Double(blue) / edge) * (remaining / denominator)
let b = highlightCap - (highlightCap - Double(blue) / edge) * (remaining / denominator)
indices.append(color2index(r, g, b, levels: levels))
}
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/MatrixScreenSaverTests/NativeMatrixRendererTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ func nativeMatrixRendererTests() {
ok(NativeMatrixRenderer().seedOffset == 0,
"NativeMatrixRenderer: seedOffset defaults to 0")

let palette = NativeMatrixRenderer().levelColors
let hasNoPureWhite = !palette.contains { color in
color.red == 255 && color.green == 255 && color.blue == 255
}
ok(hasNoPureWhite,
"NativeMatrixRenderer: palette avoids pure white highlight")

let hasMaxGreenHighlight = palette.contains { color in
color.green == 255
}
ok(hasMaxGreenHighlight,
"NativeMatrixRenderer: palette keeps max-green highlight")

let r1: NativeMatrixRenderer = .init()
let r2: NativeMatrixRenderer = .init()
r1.seedOffset = 0
Expand Down
Loading