Cotton code
55 lines · 2.9 KB · KotlinRaw
package com.cottondb.musicimport androidx.compose.ui.geometry.Offsetimport androidx.compose.ui.graphics.Canvasimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.ImageBitmapimport androidx.compose.ui.graphics.Paintimport com.cottondb.music.faces.FaceTrackPlayimport com.cottondb.music.faces.TrackPlayimport com.cottondb.shell.core.Lines/** What the player faces' specimens share: invented songs, a cover drawn here, the lines they say, the player's word. */object PlayerSpecimens {    val lines = Lines(        mapOf(            "cards.join" to " · ", "media.play" to "Play", "faces.media.play" to "Play", "faces.media.pause" to "Pause",            "faces.turntable.position" to "Position", "faces.turntable.next" to "Next song", "faces.turntable.previous" to "Previous song",            "faces.hifi.position" to "Position", "faces.hifi.next" to "Next song", "faces.hifi.previous" to "Previous song",            "faces.amp.volume" to "VOLUME", "faces.amp.tone" to "TONE",        ),        "Cotton Music",    )    /** An invented song off an invented album, 4:02 long. */    fun harbour(face: String, volume: Boolean = false) =        """{"id":"s1","face":"$face","slots":{"title":"Harbour Lights","artist":"The Low Tide","album":"Night Ferry","duration":242${if (volume) ""","volume":0.7""" else ""}}}"""    /** Another album's song, 3:17 long. */    fun train(face: String) = """{"id":"s2","face":"$face","slots":{"title":"Slow Train","artist":"Mara Vance","album":"Common Ground","duration":197}}"""    /** The longest words. */    fun largest(face: String, duration: Int = 669) =        """{"id":"s3","face":"$face","slots":{"title":"The Slow Train Home Through Sixteen Lanterns","artist":"Mara Vance and The Low Tide","album":"Sixteen Lanterns and the Blue Hour Sessions","duration":$duration}}"""    fun play(playing: Boolean, elapsed: Double, duration: Double) = FaceTrackPlay(TrackPlay(held = true, playing = playing, elapsed = elapsed, duration = duration), {}, {})    /** A cover drawn here, never a real picture: a dusk sky over a sea, a moon and a ferry's lights. */    fun cover(): ImageBitmap {        val image = ImageBitmap(240, 240)        val canvas = Canvas(image)        val paint = Paint()        for (row in 0 until 240 step 8) {            val t = row / 240f            paint.color = if (row < 150) Color(0.16f + 0.5f * t, 0.22f + 0.2f * t, 0.45f - 0.1f * t) else Color(0.05f, 0.12f + 0.1f * (1 - t), 0.25f)            canvas.drawRect(0f, row.toFloat(), 240f, row + 8f, paint)        }        paint.color = Color(0.98f, 0.92f, 0.7f)        canvas.drawCircle(Offset(170f, 60f), 22f, paint)        paint.color = Color(0.1f, 0.08f, 0.08f)        canvas.drawRect(60f, 140f, 150f, 156f, paint)        paint.color = Color(1f, 0.75f, 0.3f)        for (x in 70 until 145 step 14) canvas.drawRect(x.toFloat(), 144f, x + 6f, 150f, paint)        return image    }}