Created
June 29, 2021 21:57
-
-
Save joshskeen/0b7d6f16e8b747682c1f24cfd8e82be4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
data class Colors( | |
val color: Int, | |
val complimentary: Int, | |
val analogous: List<Int>, | |
val tetradic: List<Int> | |
) { | |
val colorNames = mapOf( | |
0 to "yellow", 1 to "cad-yellow", 2 to "orange", | |
3 to "cad-red", 4 to "red", 5 to "acra-violet", | |
6 to "violet", 7 to "ultramarine-blue", 8 to "blue", | |
9 to "pthalo-blue", 10 to "green", 11 to "hansa-yellow", | |
) | |
fun asColorNames(): String { | |
return buildString { | |
appendLine("color:" + colorNames[color]) | |
appendLine("complimentary: " + colorNames[complimentary]) | |
appendLine("analogous: " + analogous.map { colorNames[it] }.joinToString(",")) | |
appendLine("tetradic: " + tetradic.map { colorNames[it] }.joinToString(",")) | |
} | |
} | |
} | |
fun List<Int>.wrapping(index: Int) = this[(if (index < 0) index + size else index) % size] | |
val colorCodes = (0..11).toList() | |
val randomColor = colorCodes.shuffled().first() | |
println( | |
Colors( | |
color = randomColor, | |
complimentary = colorCodes.wrapping(randomColor + 6), | |
analogous = listOf( | |
colorCodes.wrapping(randomColor - 1), | |
randomColor, | |
colorCodes.wrapping(randomColor + 1), | |
), | |
tetradic = listOf( | |
colorCodes.wrapping(randomColor + 2), | |
colorCodes.wrapping(randomColor + 4), | |
colorCodes.wrapping(randomColor + 8), | |
colorCodes.wrapping(randomColor + 10), | |
) | |
).asColorNames() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
color:green
complimentary: red
analogous: pthalo-blue,green,hansa-yellow
tetradic: yellow,orange,violet,blue