mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
His note: "because the sand changes colors its a bit distracting from the bottom 4 lines. Could we a) make all the sand one same color? b) can we add more sand below... so it doesnt clash with the waves and legibility suffers". Both, but only where it earns it. Flattening the whole beach would throw away the depth the wet sand carries; the problem was never the beach, it was that the swell reached into the rows the text is written on. So the bottom WriteRows are held out of the water entirely -- the waterline is clamped above them, foam and grain stop at their edge -- and painted one flat tone. The tone is full void, and that was swept rather than picked. 0.72 / 0.85 / 0.92 / 1.00 against the contrast each of the four lines gets from the background it is actually painted on: before, noon: 53 / 69 / 120 / 204 (oldest -> newest) after, ANY hour: 98 / 133 / 168 / 204 Full wins on every line at every hour, and wins the same amount at every hour. The newest line -- which the locked sand fade exists to protect -- keeps its 204 exactly, and the oldest nearly doubles. It also keeps the reason the fade was locked at full: a true black bottom merges with the agent's own black background rather than leaving a seam. Tests: the band is exactly one tone, it does not change between frames, and the waterline never reaches it at any activity level from 0 to 1.
104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/donlucasx/xscapes/internal/canvas"
|
|
"github.com/donlucasx/xscapes/internal/companion"
|
|
"github.com/donlucasx/xscapes/internal/reduce"
|
|
"github.com/donlucasx/xscapes/internal/scape"
|
|
)
|
|
|
|
// The writing in the sand has to stay readable at every hour, and an older
|
|
// line must never out-shout a newer one.
|
|
//
|
|
// This replaces a test in internal/scape that MIRRORED drawSand's ink rule
|
|
// instead of running it: it recomputed the ink from the palette's nominal sand
|
|
// and asserted against that. The moment the beach could fade toward black,
|
|
// nominal and painted stopped being the same colour, and the mirror kept
|
|
// passing while the real thing lost contrast. A test that reimplements the
|
|
// code it is checking can only prove the copy agrees with itself.
|
|
//
|
|
// So this renders a real frame and reads the pixels back: the glyph colour the
|
|
// renderer chose, against the background it actually painted underneath.
|
|
func roundAll(v []float64) []int {
|
|
out := make([]int, len(v))
|
|
for i, x := range v {
|
|
out[i] = int(x + 0.5)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func TestSandWritingStaysReadable(t *testing.T) {
|
|
const w, h = 92, 40
|
|
work := []string{
|
|
"read internal/auth/handler.go 142 lines",
|
|
"edit internal/auth/handler.go +18 -2",
|
|
"shell go test ./... 4.1s",
|
|
"read README.md 61 lines",
|
|
}
|
|
|
|
for _, tod := range []float64{0.0, 0.25, 0.5, 0.75, 0.888} {
|
|
lines := make([]reduce.Line, 0, len(work))
|
|
for i, s := range work {
|
|
lines = append(lines, reduce.Line{Text: s, Age: 1 - float64(i+1)/float64(len(work))})
|
|
}
|
|
|
|
c := canvas.New(w, h, canvas.AlphaFar, canvas.AlphaMid, canvas.AlphaNear)
|
|
sh := scape.NewShore(7, false)
|
|
sh.MoonX = 0.28
|
|
for i := 0; i < 12; i++ {
|
|
sh.Update(c, 2+float64(i)/20, scape.Activity{
|
|
Working: true, Level: 0.6, TimeOfDay: tod, ContextUsed: 0.3})
|
|
}
|
|
cat := companion.NewCat()
|
|
cat.FaceLeft(true)
|
|
ccw, chh := cat.Size()
|
|
lay := compose(w, ccw, true)
|
|
drawScene(c, sh, cat, lay,
|
|
reduce.State{Pose: companion.Working, Tail: lines}, 3.1, 7, c.H-2-chh)
|
|
|
|
// Contrast per row, oldest first: the tail is painted newest-lowest.
|
|
near := c.Near()
|
|
var got []float64
|
|
for y := 0; y < c.H; y++ {
|
|
var sum float64
|
|
var n int
|
|
for x := lay.SandFrom; x < lay.SandTo && x < c.W; x++ {
|
|
cell := near.Cells[y*c.W+x]
|
|
if !cell.Set || cell.R == ' ' {
|
|
continue
|
|
}
|
|
sum += math.Abs(luma(cell.FG) - luma(c.BG[y*c.W+x]))
|
|
n++
|
|
}
|
|
if n >= 10 {
|
|
got = append(got, sum/float64(n))
|
|
}
|
|
}
|
|
if len(got) < len(work) {
|
|
t.Fatalf("tod %.3f: found %d written rows, want %d", tod, len(got), len(work))
|
|
}
|
|
got = got[len(got)-len(work):]
|
|
|
|
t.Logf("tod %.3f: contrast oldest->newest = %v", tod, roundAll(got))
|
|
|
|
// got runs top to bottom, which is oldest to NEWEST: the tail is
|
|
// painted newest-lowest, nearest the companion and last in the
|
|
// reading order. So contrast must climb as it goes down.
|
|
prev := 0.0
|
|
for i, contrast := range got {
|
|
if contrast < 18 {
|
|
t.Errorf("tod %.3f line %d: only %.1f luma from the beach it is written on -- unreadable",
|
|
tod, i, contrast)
|
|
}
|
|
if contrast < prev-1e-6 {
|
|
t.Errorf("tod %.3f line %d: contrast %.1f is below the older line's %.1f -- age must dim, not brighten",
|
|
tod, i, contrast, prev)
|
|
}
|
|
prev = contrast
|
|
}
|
|
}
|
|
}
|