diff --git a/orx-color/src/commonMain/kotlin/statistics/DeltaE.kt b/orx-color/src/commonMain/kotlin/statistics/DeltaE.kt new file mode 100644 index 00000000..90488cdd --- /dev/null +++ b/orx-color/src/commonMain/kotlin/statistics/DeltaE.kt @@ -0,0 +1,20 @@ +package org.openrndr.extra.color.statistics + +import org.openrndr.color.ColorLABa +import org.openrndr.color.ConvertibleToColorRGBa +import org.openrndr.math.Vector3 + +/** + * Computes delta E between two colors. + */ +fun T.deltaE76(other: T): Double { + return if (this is ColorLABa && other is ColorLABa) { + val tv = Vector3(l, a, b) + val ov = Vector3(other.l, other.a, other.b) + tv.distanceTo(ov) + } else { + val tLab = if (this is ColorLABa) this else this.toRGBa().toLABa() + val oLab = if (other is ColorLABa) other else other.toRGBa().toLABa() + tLab.deltaE76(oLab) + } +} \ No newline at end of file diff --git a/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt b/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt new file mode 100644 index 00000000..f2bee108 --- /dev/null +++ b/orx-color/src/jvmDemo/kotlin/DemoDeltaE.kt @@ -0,0 +1,39 @@ +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.extra.color.spaces.toOKHSVa +import org.openrndr.extra.color.statistics.deltaE76 +import org.openrndr.math.Polar + +fun main() { + application { + configure { + width = 720 + height = 720 + } + program { + extend { + drawer.clear(ColorRGBa.BLACK) + drawer.fill = null + drawer.stroke = ColorRGBa.WHITE.opacify(0.2) + for (i in 10 until 270 step 10) { + drawer.circle(drawer.bounds.center, i.toDouble()) + } + + drawer.stroke = null + + val startColor = ColorRGBa.RED.toOKHSVa().shiftHue(seconds*36.0).toRGBa() + drawer.circles { + for (j in 99 downTo 0) { + for (i in 0 until 360 step 10) { + val color = startColor.toOKHSVa().shiftHue(i.toDouble()).saturate(j / 99.0).toRGBa() + val distance = color.deltaE76(startColor) + val p = Polar(seconds * 36.0 + i.toDouble(), distance).cartesian + drawer.bounds.center + fill = color + circle(p, 2.0) + } + } + } + } + } + } +} \ No newline at end of file