[orx-color] Match new LuminosityColor

This commit is contained in:
Edwin Jakobs
2023-12-10 23:03:41 +01:00
parent 7413bcacc3
commit 096cb2367a
9 changed files with 66 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ data class ColorHPLUVa(val h: Double, val s: Double, val l: Double, override val
HueShiftableColor<ColorHPLUVa>,
SaturatableColor<ColorHPLUVa>,
ShadableColor<ColorHPLUVa>,
LuminosityColor<ColorHPLUVa>,
AlgebraicColor<ColorHPLUVa> {
fun toLCHUVa(): ColorLCHUVa {
val l1 = l
@@ -26,13 +27,15 @@ data class ColorHPLUVa(val h: Double, val s: Double, val l: Double, override val
return ColorLCHUVa(l100, c100, h)
}
override val hue: Double = h
override val hue: Double
get() = h
override fun withHue(hue: Double) = copy(h = hue)
override fun shade(factor: Double): ColorHPLUVa = copy(l = l * factor)
override val saturation: Double = s
override val saturation: Double
get() = s
override fun withSaturation(saturation: Double): ColorHPLUVa = copy(s = saturation)
@@ -49,6 +52,10 @@ data class ColorHPLUVa(val h: Double, val s: Double, val l: Double, override val
override fun mix(other: ColorHPLUVa, factor: Double) = mix(this, other, factor)
override fun toVector4(): Vector4 = Vector4(h, s, l, alpha)
override val luminosity: Double
get() = l
override fun withLuminosity(luminosity: Double): ColorHPLUVa = copy(l = luminosity)
}
fun mix(left: ColorHPLUVa, right: ColorHPLUVa, x: Double): ColorHPLUVa {

View File

@@ -86,6 +86,7 @@ data class ColorHSLUVa(val h: Double, val s: Double, val l: Double, override val
HueShiftableColor<ColorHSLUVa>,
SaturatableColor<ColorHSLUVa>,
ShadableColor<ColorHSLUVa>,
LuminosityColor<ColorHSLUVa>,
AlgebraicColor<ColorHSLUVa> {
@Deprecated("Legacy alpha parameter name", ReplaceWith("alpha"))
@@ -114,11 +115,14 @@ data class ColorHSLUVa(val h: Double, val s: Double, val l: Double, override val
return ColorXSLUVa(hueToX(h), s, l, alpha)
}
override val hue: Double =h
override val hue: Double
get() = h
override fun withHue(hue: Double): ColorHSLUVa = copy(h = hue)
override fun shade(factor: Double) = copy(l = l * factor)
override val saturation: Double = s
override val saturation: Double
get() = s
override fun withSaturation(saturation: Double): ColorHSLUVa = copy(s = saturation)
override fun toRGBa(): ColorRGBa {
@@ -136,6 +140,10 @@ data class ColorHSLUVa(val h: Double, val s: Double, val l: Double, override val
override fun mix(other: ColorHSLUVa, factor: Double) = mix(this, other, factor)
override fun toVector4(): Vector4 = Vector4(h, s, l, alpha)
override val luminosity: Double
get() = l
override fun withLuminosity(luminosity: Double): ColorHSLUVa = copy(l = luminosity)
}

View File

@@ -95,12 +95,14 @@ data class ColorOKHSLa(val h: Double, val s: Double, val l: Double, override val
).toRGBa().toSRGB()
}
override val hue: Double = h
override val hue: Double
get() = h
override fun withHue(hue: Double): ColorOKHSLa = copy(h = hue)
override fun opacify(factor: Double): ColorOKHSLa = copy(alpha = alpha * factor)
override val saturation: Double = s
override val saturation: Double
get() = s
override fun withSaturation(saturation: Double): ColorOKHSLa = copy(s = saturation)

View File

@@ -102,12 +102,14 @@ data class ColorOKHSVa(val h: Double, val s: Double, val v: Double, override val
).toRGBa().toSRGB()
}
override val hue: Double = h
override val hue: Double
get() = h
override fun withHue(hue: Double): ColorOKHSVa = copy(h = hue)
override fun opacify(factor: Double): ColorOKHSVa = copy(alpha = alpha * factor)
override val saturation: Double = s
override val saturation: Double
get() = s
override fun withSaturation(saturation: Double): ColorOKHSVa = copy(s = saturation)
override fun shade(factor: Double): ColorOKHSVa = copy(v = v * factor)

View File

@@ -16,6 +16,7 @@ import kotlin.math.pow
data class ColorOKLABa(val l: Double, val a: Double, val b: Double, override val alpha: Double = 1.0) :
ColorModel<ColorOKLABa>,
ShadableColor<ColorOKLABa>,
LuminosityColor<ColorOKLABa>,
AlgebraicColor<ColorOKLABa> {
companion object {
@@ -66,6 +67,10 @@ data class ColorOKLABa(val l: Double, val a: Double, val b: Double, override val
override fun times(scale: Double) = ColorOKLABa(l * scale, a * scale, b * scale, alpha * scale)
override fun toVector4() = Vector4(l, a, b, alpha)
override val luminosity: Double
get() = l
override fun withLuminosity(luminosity: Double): ColorOKLABa = copy(l = luminosity)
}
fun ColorRGBa.toOKLABa() = ColorOKLABa.fromRGBa(this)

View File

@@ -14,6 +14,7 @@ data class ColorOKLCHa(val l: Double, val c: Double, val h: Double, override val
ShadableColor<ColorOKLCHa>,
ChromaColor<ColorOKLCHa>,
HueShiftableColor<ColorOKLCHa>,
LuminosityColor<ColorOKLCHa>,
AlgebraicColor<ColorOKLCHa> {
companion object {
@@ -49,11 +50,17 @@ data class ColorOKLCHa(val l: Double, val c: Double, val h: Double, override val
override fun toRGBa(): ColorRGBa = toOKLABa().toRGBa()
override fun toVector4(): Vector4 = Vector4(l, c, h, alpha)
override val chroma: Double = c
override val chroma: Double
get() = c
override fun withChroma(chroma: Double): ColorOKLCHa = copy(c = chroma)
override val hue: Double = h
override val hue: Double
get() = h
override fun withHue(hue: Double): ColorOKLCHa = copy(h = hue)
override val luminosity: Double
get() = l
override fun withLuminosity(luminosity: Double): ColorOKLCHa = copy(l = luminosity)
}
fun mix(left: ColorOKLCHa, right: ColorOKLCHa, x: Double): ColorOKLCHa {

View File

@@ -16,11 +16,13 @@ data class ColorXSLUVa(val x: Double, val s: Double, val l: Double, override val
@Deprecated("Legacy alpha parameter name", ReplaceWith("alpha"))
val a = alpha
override val hue: Double = x
override val hue: Double
get() = x
override fun withHue(hue: Double): ColorXSLUVa = copy(x = hue)
override fun shade(factor: Double) = copy(l = l * factor)
override val saturation: Double = s
override val saturation: Double
get() = s
override fun withSaturation(saturation: Double): ColorXSLUVa = copy(s = saturation)

View File

@@ -57,6 +57,25 @@ inline fun <reified T : ColorModel<T>> ColorRGBa.convertTo(): T {
return converted as T
}
inline fun <reified T> ColorRGBa.withLuminosity(luminosity: Double): ColorRGBa
where T : LuminosityColor<T>,
T : ColorModel<T>,
T : ConvertibleToColorRGBa = convertTo<T>().withLuminosity(luminosity).toRGBa().matchLinearity(this)
inline fun <reified T> ColorRGBa.mixLuminosity(luminosity: Double, factor: Double): ColorRGBa
where T : LuminosityColor<T>,
T : ColorModel<T>,
T : ConvertibleToColorRGBa =
convertTo<T>().mixLuminosity(luminosity, factor).toRGBa().matchLinearity(this)
inline fun <reified T> ColorRGBa.shadeLuminosity(factor: Double): ColorRGBa
where T : LuminosityColor<T>,
T : ColorModel<T>,
T : ConvertibleToColorRGBa =
convertTo<T>().shadeLuminosity(factor).toRGBa().matchLinearity(this)
inline fun <reified T> ColorRGBa.mixHue(hue: Double, factor: Double): ColorRGBa
where T : HueShiftableColor<T>,
T : ColorModel<T>,

View File

@@ -2,6 +2,7 @@ import org.openrndr.application
import org.openrndr.extra.color.palettes.analogous
import org.openrndr.extra.color.spaces.HSLuv
import org.openrndr.extra.color.spaces.RGB
import org.openrndr.extra.color.tools.shadeLuminosity
/**
* By default, generated palettes contain colors of varying hue
@@ -13,7 +14,7 @@ fun main() = application {
program {
val count = 8
val palette = RGB.PINK.analogous<HSLuv>(360.0, count).mapIndexed { i, c ->
c.shade((i + 1.0) / count)
c.shadeLuminosity<HSLuv>((i + 1.0) / count)
}.reversed()
extend {
drawer.stroke = null