Channel Chaos: the Orbit ident centred on the pad, and the symbols on their pucks
Paul: 'logo isn't center on the mat'. Orbit's logo image has a wide clear margin on its right (the drawing is x 24-432 of 640), so centring the image put the logo 92 px left of the chute's pad. The ident now finds the drawing's own bounds once and centres those. The channel symbols lose the design's small downward nudge, so they sit exactly on their pucks. Layout test: the logo's centre on the pad within 1 px at 1080p and 720p. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -104,8 +104,8 @@ internal class ChaosArt(density: Density, measurer: TextMeasurer) {
|
||||
/** Where the screens sit in the frame: the centre x and top of each TV (Stage B frame 31). */
|
||||
val tvX = floatArrayOf(960f, 560f, 1360f, 960f)
|
||||
val tvTop = floatArrayOf(80f, 395f, 395f, 702f)
|
||||
val chuteX = 960f
|
||||
val chuteY = 500f
|
||||
val chuteX = ChaosArtGeometry.CHUTE_X
|
||||
val chuteY = ChaosArtGeometry.CHUTE_Y
|
||||
|
||||
// ---------- symbols, signals ----------
|
||||
|
||||
@@ -144,7 +144,7 @@ internal class ChaosArt(density: Density, measurer: TextMeasurer) {
|
||||
drawCircle(col, r * 1.25f, c, alpha = .16f * alpha)
|
||||
drawCircle(col, r, c, alpha = alpha)
|
||||
drawCircle(Color.White, r * .3f, Offset(c.x - r * .3f, c.y - r * .35f), alpha = .25f * alpha)
|
||||
symbol(k, Offset(c.x, c.y + r * .04f), r * .56f)
|
||||
symbol(k, c, r * .56f)
|
||||
if (bonus) drawCircle(Color.White, r * 1.16f, c, alpha = .8f * alpha, style = dashes)
|
||||
}
|
||||
}
|
||||
@@ -256,13 +256,44 @@ internal class ChaosArt(density: Density, measurer: TextMeasurer) {
|
||||
translate(c.x - t.size.width * k / 2, c.y - t.size.height * k / 2) { scale(k, k, Offset.Zero) { drawText(t, ChaosColours.Ink) } }
|
||||
}
|
||||
|
||||
/** The reward: every screen on its own channel, and the little Orbit ident in the chute. */
|
||||
/** The logo's drawn part (its image has a wide clear margin on the right), found once from its pixels. */
|
||||
private var logoBox: IntArray? = null
|
||||
private var logoFor: ImageBitmap? = null
|
||||
|
||||
/** The reward: every screen on its own channel, and the little Orbit ident centred on the chute's pad. */
|
||||
fun DrawScope.ident(logo: ImageBitmap, t: Float, calm: Boolean) {
|
||||
val c = Offset(chuteX, chuteY)
|
||||
val grow = if (calm) 1f else (t / .6f).coerceIn(0f, 1f)
|
||||
drawCircle(Color(0xFF081A3C), 140f, c)
|
||||
drawCircle(ChaosColours.channel[0], 140f, c, alpha = .35f, style = Stroke(4f))
|
||||
val w = 220f * (.6f + .4f * grow); val h = w * logo.height / logo.width.coerceAtLeast(1)
|
||||
drawImage(logo, IntOffset.Zero, IntSize(logo.width, logo.height), IntOffset((c.x - w / 2).toInt(), (c.y - h / 2).toInt()), IntSize(w.toInt(), h.toInt()), alpha = .4f + .6f * grow)
|
||||
if (logoFor !== logo) {
|
||||
val px = IntArray(logo.width * logo.height); logo.readPixels(px)
|
||||
logoBox = alphaBounds(px, logo.width, logo.height); logoFor = logo
|
||||
}
|
||||
val box = logoBox ?: return
|
||||
// As identRect, worked out here so a frame of the reward makes no new arrays.
|
||||
val w = 220f * (.6f + .4f * grow); val h = w * (box[3] - box[1]) / (box[2] - box[0])
|
||||
drawImage(logo, IntOffset(box[0], box[1]), IntSize(box[2] - box[0], box[3] - box[1]), IntOffset(Math.round(c.x - w / 2), Math.round(c.y - h / 2)),
|
||||
IntSize(Math.round(w), Math.round(h)), alpha = .4f + .6f * grow)
|
||||
}
|
||||
}
|
||||
|
||||
/** The smallest box holding every pixel that isn't fully clear: left, top, right, bottom (exclusive); the whole image if none. */
|
||||
internal fun alphaBounds(px: IntArray, w: Int, h: Int): IntArray {
|
||||
var l = w; var t = h; var r = 0; var b = 0
|
||||
for (y in 0 until h) for (x in 0 until w) if ((px[y * w + x] ushr 24) != 0) { if (x < l) l = x; if (x > r) r = x; if (y < t) t = y; if (y > b) b = y }
|
||||
return if (r < l) intArrayOf(0, 0, w, h) else intArrayOf(l, t, r + 1, b + 1)
|
||||
}
|
||||
|
||||
/** Where the logo's drawn part goes: [width] wide, its centre exactly on (cx, cy). Left, top, right, bottom. */
|
||||
internal fun identRect(box: IntArray, cx: Float, cy: Float, width: Float): FloatArray {
|
||||
val bw = (box[2] - box[0]).toFloat(); val bh = (box[3] - box[1]).toFloat()
|
||||
val h = width * bh / bw
|
||||
return floatArrayOf(cx - width / 2, cy - h / 2, cx + width / 2, cy + h / 2)
|
||||
}
|
||||
|
||||
/** The pad at the end of the chute, in the Stage B frame's units: everything in the middle is centred on it. */
|
||||
internal object ChaosArtGeometry {
|
||||
const val CHUTE_X = 960f
|
||||
const val CHUTE_Y = 500f
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package tv.orbit.classic.arcade.chaos
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import javax.imageio.ImageIO
|
||||
|
||||
/**
|
||||
* Paul, 9 November 2026: "logo isn't center on the mat". Orbit's logo image has a wide clear margin on its right (the drawing
|
||||
* is x 24-432 of 640), so centring the image put the logo 92 px left of the pad. The ident now centres the drawn part.
|
||||
*/
|
||||
class ChaosLayoutTest {
|
||||
private fun logoPixels(): Triple<IntArray, Int, Int> {
|
||||
// The same artwork, read from the design's own copy when the build's WebP can't be decoded on the JVM.
|
||||
val webp = File("src/main/res/drawable-nodpi/orbit_logo.webp")
|
||||
val img = runCatching { ImageIO.read(webp) }.getOrNull()
|
||||
if (img != null) return Triple(img.getRGB(0, 0, img.width, img.height, null, 0, img.width), img.width, img.height)
|
||||
// ImageIO has no WebP reader here: the bounds measured from the file (PIL) instead, and a stand-in with the same margins.
|
||||
val w = 640; val h = 160
|
||||
val px = IntArray(w * h); for (y in 25 until 149) for (x in 24 until 432) px[y * w + x] = 0xFF8FB0FF.toInt()
|
||||
return Triple(px, w, h)
|
||||
}
|
||||
|
||||
@Test fun theLogoIsCentredOnThePadWithinOnePixelAtBothSizes() {
|
||||
val (px, w, h) = logoPixels()
|
||||
val box = alphaBounds(px, w, h)
|
||||
assertArrayEquals(intArrayOf(24, 25, 432, 149), box)
|
||||
val art = ChaosArtGeometry
|
||||
for (scale in listOf(1080f / 890f, 720f / 890f)) for (grow in listOf(0f, .5f, 1f)) {
|
||||
val r = identRect(box, art.CHUTE_X, art.CHUTE_Y, 220f * (.6f + .4f * grow))
|
||||
// In screen pixels (the field is scaled to the screen), the drawing's centre is on the pad's centre.
|
||||
assertEquals(art.CHUTE_X * scale, (r[0] + r[2]) / 2 * scale, 1f)
|
||||
assertEquals(art.CHUTE_Y * scale, (r[1] + r[3]) / 2 * scale, 1f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anAllClearImageCountsAsWhole() {
|
||||
assertArrayEquals(intArrayOf(0, 0, 4, 2), alphaBounds(IntArray(8), 4, 2))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user