Modern Apps git

← Modern-Apps.git

pipes: reorder palette; letter pipes in colour-blind mode (#ux-audit)

Commit
43168a53d2e030dcc085258503f9dd7fd4deae1c
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:26 UTC (23 days ago)
Parents
6e6c74b
Symptom: big boards use up to 17 colours, and several of them were
hard to tell apart (Blue vs Light Blue, Green vs Lime, Cyan vs Bright
Cyan all land on the same 13x13/14x14 boards). Colour-blind mode only
lettered the dots, so along a pipe there was nothing but colour to go
on.

Root cause: PIPE_COLORS was ordered roughly by hue family, so the
first 17 entries (the only ones any level uses; colour index = list
position) contained the near-duplicate pairs. drawColorLabel was only
called for endpoint cells.

Fix:
- PipeColors.kt keeps the same 24 colours but reorders them: classic
  red, green, blue, yellow first (so small boards look unchanged),
  then greedy farthest-first by CIEDE2000, also keeping away from the
  dark cell background. Closest pair within the first 17 goes from
  7.6 dE00 (Blue/Light Blue) to about 12 (Bright Teal/Cyan); by
  redmean RGB distance, from 54 to 72.
- In colour-blind mode GameBoard also letters every other inner cell
  of each pipe, at 0.32 of the cell (inside the half-cell-wide pipe),
  drawn above bridge humps and below the dots. New pipeLabelAnchor puts
  the letter on the arc's centre line for corner segments, which do not
  pass through the cell centre; straight runs and hex cells use the
  centre. drawColorLabel gains optional center/textScale parameters.

Product note: colour-blind mode stays off by default to keep the
current look for existing players; the reordered palette is the
default-on improvement. Turning the mode on by default is a one-line
change if wanted.

User-visible effect: colours on large boards are visibly more
distinct (levels' colours shift accordingly), and colour-blind mode
shows the line's letter along its length.

Verification: PipeRendererTest gains pipeLabelAnchorsLandOnThePipe
(anchor pixel is painted for all four corners and sits on the arc's
centre line), smallLabelDrawsAtAGivenAnchor, and
theColoursLevelsUseAreClearlyApart (every pair among the first 17 has
redmean distance >= 70; the first four are unchanged). Store
screenshots are not regenerated here, per the integration plan.

Diff

games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.ktindex fae58ad2b4..c624403254 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/GameBoard.kt@@ -11,6 +11,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalDensity@@ -19,6 +20,9 @@ import com.vayunmathur.games.pipes.data.CellPos import com.vayunmathur.games.pipes.data.LevelData import com.vayunmathur.games.pipes.platform.PipesGameState +/** Letter size on pipe segments, as a fraction of the cell: fits inside the half-cell-wide pipe. */+private const val PIPE_LABEL_SCALE = 0.32f+ /** Test tag of the drawing surface, for gesture tests. */ internal const val GAME_BOARD_TAG = "pipes_game_board" @@ -106,6 +110,9 @@ fun GameBoard(         val displayPaths = if (activeColor != null) gameState.paths + (activeColor to activePath) else gameState.paths          val jumpExits = mutableListOf<Triple<CellPos, Direction, androidx.compose.ui.graphics.Color>>()+        // Colour-blind mode letters every other inner cell of each pipe, not just the dots,+        // so two similar colours can be told apart anywhere along their lines.+        val pipeLabels = mutableListOf<Triple<Rect, Offset, Int>>()          for ((colorIndex, path) in displayPaths) {             if (path.isEmpty()) continue@@ -120,12 +127,18 @@ fun GameBoard(                         if (i < path.lastIndex) hexDirOrNull(cellRects, cell, path[i + 1])?.let { add(it) }                     }                     drawHexPipeSegment(rect.center, cellSizePx * 0.5f, connections, color)+                    if (colorblind && i % 2 == 1 && i < path.lastIndex) {+                        pipeLabels += Triple(rect, rect.center, colorIndex)+                    }                 } else {                     val connections = buildSet {                         if (i > 0) stepOrJump(levelData, cell, path[i - 1], color, jumpExits)?.let { add(it) }                         if (i < path.lastIndex) stepOrJump(levelData, cell, path[i + 1], color, jumpExits)?.let { add(it) }                     }                     drawPipeSegment(rect, connections, color)+                    if (colorblind && i % 2 == 1 && i < path.lastIndex) {+                        pipeLabels += Triple(rect, pipeLabelAnchor(rect, connections), colorIndex)+                    }                 }             }         }@@ -150,6 +163,10 @@ fun GameBoard(             }         } +        for ((rect, anchor, colorIndex) in pipeLabels) {+            drawColorLabel(rect, colorIndex, labelPaint, center = anchor, textScale = PIPE_LABEL_SCALE)+        }+         for (ep in levelData.endpoints) {             val color = PIPE_COLORS[ep.colorIndex % PIPE_COLORS.size]             for (cell in ep.cells) {
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeColors.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeColors.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeColors.ktindex 19a15dfb1d..3d9e66c2c7 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeColors.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeColors.kt@@ -2,29 +2,36 @@ package com.vayunmathur.games.pipes.ui  import androidx.compose.ui.graphics.Color +/**+ * Flow colours by colour index. Levels use up to 17 colours, so the order matters: after+ * the classic red, green, blue, yellow, each next colour is the one farthest (CIEDE2000)+ * from all colours before it and from the dark cell background. The closest pair within+ * the first 17 is now about 12 dE00 apart (Bright Teal/Cyan); the previous order put+ * Blue/Light Blue (7.6) and Green/Lime (10) in the same board.+ */ val PIPE_COLORS = listOf(     Color(0xFFE53935),   // Red     Color(0xFF43A047),   // Green     Color(0xFF1E88E5),   // Blue     Color(0xFFFDD835),   // Yellow+    Color(0xFF00E5FF),   // Bright Cyan     Color(0xFFFF8F00),   // Orange-    Color(0xFF00ACC1),   // Cyan     Color(0xFFAB47BC),   // Magenta-    Color(0xFF8D6E63),   // Maroon-    Color(0xFF7CB342),   // Lime-    Color(0xFF00897B),   // Teal+    Color(0xFF26A69A),   // Bright Teal+    Color(0xFF9E9D24),   // Olive     Color(0xFFEC407A),   // Pink-    Color(0xFF5E35B1),   // Deep Purple     Color(0xFF3949AB),   // Indigo-    Color(0xFFF4511E),   // Deep Orange-    Color(0xFF039BE5),   // Light Blue-    Color(0xFF9E9D24),   // Olive-    Color(0xFF6D4C41),   // Brown-    Color(0xFF00E5FF),   // Bright Cyan-    Color(0xFFC0CA33),   // Chartreuse-    Color(0xFFD81B60),   // Raspberry+    Color(0xFF8D6E63),   // Maroon     Color(0xFF546E7A),   // Blue Grey     Color(0xFFFFB300),   // Amber+    Color(0xFFC0CA33),   // Chartreuse+    Color(0xFF00ACC1),   // Cyan+    Color(0xFF6D4C41),   // Brown+    Color(0xFFF4511E),   // Deep Orange+    Color(0xFF7CB342),   // Lime+    Color(0xFF00897B),   // Teal     Color(0xFF8E24AA),   // Purple-    Color(0xFF26A69A),   // Bright Teal+    Color(0xFF5E35B1),   // Deep Purple+    Color(0xFFD81B60),   // Raspberry+    Color(0xFF039BE5),   // Light Blue )
games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeRenderer.kt
diff --git a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeRenderer.kt b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeRenderer.ktindex 0646f2b120..79f68ff292 100644--- a/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeRenderer.kt+++ b/games/pipes/src/main/java/com/vayunmathur/games/pipes/ui/PipeRenderer.kt@@ -156,11 +156,16 @@ class ColorLabelPaint {     } } -/** Colorblind aid: draw the flow's identifying letter centered in the cell. */+/**+ * Colorblind aid: draw the flow's identifying letter, centred on [center] (the cell centre+ * by default) at [textScale] of the cell size.+ */ fun DrawScope.drawColorLabel(     cellRect: Rect,     colorIndex: Int,     labelPaint: ColorLabelPaint = ColorLabelPaint(),+    center: Offset = cellRect.center,+    textScale: Float = 0.5f, ) {     val letter = ('A' + (colorIndex % 26)).toString()     val onColor = PIPE_COLORS[colorIndex % PIPE_COLORS.size]@@ -169,12 +174,28 @@ fun DrawScope.drawColorLabel(     val textColor = if (luminance > 0.6f) android.graphics.Color.BLACK else android.graphics.Color.WHITE     val paint = labelPaint.paint     paint.color = textColor-    paint.textSize = cellRect.width * 0.5f-    val cx = cellRect.center.x-    val cy = cellRect.center.y - (paint.descent() + paint.ascent()) / 2f+    paint.textSize = cellRect.width * textScale+    val cx = center.x+    val cy = center.y - (paint.descent() + paint.ascent()) / 2f     drawContext.canvas.nativeCanvas.drawText(letter, cx, cy, paint) } +/**+ * Where a letter sits on a square pipe segment so that it lands in the middle of the+ * pipe: the cell centre for straight runs and ends, and the middle of the arc for a+ * corner, whose quarter circle (radius half a cell, centred on the cell corner) only+ * grazes the cell centre with its outer edge.+ */+fun pipeLabelAnchor(cellRect: Rect, connections: Set<Direction>): Offset {+    if (connections.size != 2) return cellRect.center+    val dirs = connections.toList()+    if (areOpposite(dirs[0], dirs[1])) return cellRect.center+    val inset = cellRect.width * 0.5f / kotlin.math.sqrt(2f)+    val x = if (Direction.RIGHT in connections) cellRect.right - inset else cellRect.left + inset+    val y = if (Direction.DOWN in connections) cellRect.bottom - inset else cellRect.top + inset+    return Offset(x, y)+}+ private fun areOpposite(a: Direction, b: Direction): Boolean =     (a == Direction.UP && b == Direction.DOWN) || (a == Direction.DOWN && b == Direction.UP) ||     (a == Direction.LEFT && b == Direction.RIGHT) || (a == Direction.RIGHT && b == Direction.LEFT)
games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipeRendererTest.kt
diff --git a/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipeRendererTest.kt b/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipeRendererTest.ktindex 00aaddb475..46391f403a 100644--- a/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipeRendererTest.kt+++ b/games/pipes/src/test/java/com/vayunmathur/games/pipes/ui/PipeRendererTest.kt@@ -116,4 +116,51 @@ class PipeRendererTest {         assertEquals(24, PIPE_COLORS.size)         assertEquals(PIPE_COLORS.size, PIPE_COLORS.toSet().size)     }++    @Test fun pipeLabelAnchorsLandOnThePipe() {+        val rect = Rect(Offset(10f, 10f), Size(100f, 100f))+        assertEquals(rect.center, pipeLabelAnchor(rect, setOf(Direction.LEFT, Direction.RIGHT)))+        assertEquals(rect.center, pipeLabelAnchor(rect, setOf(Direction.UP)))+        for (corner in listOf(+            setOf(Direction.UP, Direction.RIGHT), setOf(Direction.UP, Direction.LEFT),+            setOf(Direction.DOWN, Direction.RIGHT), setOf(Direction.DOWN, Direction.LEFT),+        )) {+            val a = pipeLabelAnchor(rect, corner)+            val bmp = bitmapDraw { drawPipeSegment(rect, corner, Color.Red) }+            assertEquals(android.graphics.Color.RED, bmp.getPixel(a.x.toInt(), a.y.toInt()), "corner=$corner anchor=$a")+            // Mid-stroke: half a cell from the arc's corner, i.e. on the arc's centre line.+            val corner0 = Offset(+                if (Direction.RIGHT in corner) rect.right else rect.left,+                if (Direction.DOWN in corner) rect.bottom else rect.top,+            )+            assertEquals(50f, (a - corner0).getDistance(), 0.01f)+        }+    }++    @Test fun smallLabelDrawsAtAGivenAnchor() {+        val rect = Rect(Offset(10f, 10f), Size(100f, 100f))+        val bmp = bitmapDraw { drawColorLabel(rect, 1, ColorLabelPaint(), center = Offset(85f, 35f), textScale = 0.32f) }+        var ink = 0; var stray = 0+        for (x in 10 until 110) for (y in 10 until 110) {+            if (bmp.getPixel(x, y) == android.graphics.Color.TRANSPARENT) continue+            if (x in 65..105 && y in 15..55) ink++ else stray+++        }+        assertTrue(ink > 10, "ink=$ink"); assertEquals(0, stray)+    }++    @Test fun theColoursLevelsUseAreClearlyApart() {+        // Levels use up to 17 colours. "Redmean" RGB distance: the old order had Blue and+        // Light Blue at 54 among the first 17; the reordered palette keeps every pair >= 70.+        fun dist(a: Color, b: Color): Double {+            val r1 = a.red * 255; val r2 = b.red * 255; val rm = (r1 + r2) / 2+            val dr = r1 - r2; val dg = (a.green - b.green) * 255; val db = (a.blue - b.blue) * 255+            return kotlin.math.sqrt(((2 + rm / 256) * dr * dr + 4 * dg * dg + (2 + (255 - rm) / 256) * db * db).toDouble())+        }+        val used = PIPE_COLORS.take(17)+        for (i in used.indices) for (j in i + 1 until used.size) {+            assertTrue(dist(used[i], used[j]) >= 70.0, "colours $i and $j are too close")+        }+        // The classic first four stay put so small boards keep their familiar colours.+        assertEquals(listOf(Color(0xFFE53935), Color(0xFF43A047), Color(0xFF1E88E5), Color(0xFFFDD835)), PIPE_COLORS.take(4))+    } }