[orx-color] Add deltaE76

This commit is contained in:
Edwin Jakobs
2023-01-25 20:11:14 +01:00
parent 367a227ccd
commit b211a584ce
2 changed files with 59 additions and 0 deletions

View File

@@ -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: ConvertibleToColorRGBa> 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)
}
}

View File

@@ -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)
}
}
}
}
}
}
}