diff --git a/orx-color/src/commonMain/kotlin/palettes/Classics.kt b/orx-color/src/commonMain/kotlin/palettes/Classics.kt new file mode 100644 index 00000000..ba8f2853 --- /dev/null +++ b/orx-color/src/commonMain/kotlin/palettes/Classics.kt @@ -0,0 +1,59 @@ +package org.openrndr.extra.color.palettes + +import org.openrndr.color.ColorModel +import org.openrndr.color.ColorRGBa +import org.openrndr.color.HueShiftableColor +import org.openrndr.extra.color.tools.shiftHue + +/** + * Generate an analogous palette + * @param T the color model to use + */ +inline fun ColorRGBa.analogous(hueShift: Double, steps: Int = 5): List + where T : HueShiftableColor, + T : ColorModel = (0 until steps).map { + shiftHue(hueShift * it / (steps - 1.0)) +} + +/** + * Generate a split complementary palette in which the receiver is the seed color + * @param T the color model to use + * @param splitFactor a value between 0 and 1 that indicates how much the complementary color should be split + * @param double should a double complementary palette be generated + */ +inline fun ColorRGBa.splitComplementary(splitFactor: Double, double: Boolean = false): List + where T : HueShiftableColor, + T : ColorModel { + val c0 = shiftHue(180 - 180.0 * splitFactor) + val c1 = shiftHue(180 + 180.0 * splitFactor) + + if (!double) { + return listOf(this, c0, c1) + } else { + val c2 = shiftHue(180.0 * splitFactor) + val c3 = shiftHue(-180.0 * splitFactor) + return listOf(this, c0, c1, c2, c3) + } +} + +/** + * Generate a triadic palette in which the receiver is the seed color. + * @param T the color model to use + */ +inline fun ColorRGBa.triadic(): List + where T : HueShiftableColor, + T : ColorModel = splitComplementary(1.0 / 3.0) + + +/** + * Generate a tetradic palette in which the receiver is the seed color. + * @param T the color model to use + * @param aspectRatio the aspect ratio between even and odd sides + */ +inline fun ColorRGBa.tetradic(aspectRatio: Double = 1.0): List + where T : HueShiftableColor, + T : ColorModel { + val a0 = 180 / (aspectRatio + 1) + val a1 = 180 - a0 + return listOf(this, shiftHue(a0), shiftHue(a0 + a1), shiftHue(a0 + a1 + a0)) +}