Skip to content

Instantly share code, notes, and snippets.

@joshskeen
Created June 29, 2021 21:57
Show Gist options
  • Save joshskeen/0b7d6f16e8b747682c1f24cfd8e82be4 to your computer and use it in GitHub Desktop.
Save joshskeen/0b7d6f16e8b747682c1f24cfd8e82be4 to your computer and use it in GitHub Desktop.
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()
)
}
@joshskeen
Copy link
Author

color:green
complimentary: red
analogous: pthalo-blue,green,hansa-yellow
tetradic: yellow,orange,violet,blue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment