@@ -1068,6 +1068,15 @@ func OkLabToXyz(l, a, b float64) (x, y, z float64) {
1068
1068
return
1069
1069
}
1070
1070
1071
+ // BlendOkLab blends two colors in the OkLab color-space, which should result in a better blend (even compared to BlendLab).
1072
+ func (c1 Color ) BlendOkLab (c2 Color , t float64 ) Color {
1073
+ l1 , a1 , b1 := c1 .OkLab ()
1074
+ l2 , a2 , b2 := c2 .OkLab ()
1075
+ return OkLab (l1 + t * (l2 - l1 ),
1076
+ a1 + t * (a2 - a1 ),
1077
+ b1 + t * (b2 - b1 ))
1078
+ }
1079
+
1071
1080
/// OkLch ///
1072
1081
///////////
1073
1082
@@ -1105,3 +1114,20 @@ func OkLchToOkLab(l, c, h float64) (float64, float64, float64) {
1105
1114
b := c * math .Sin (h )
1106
1115
return l , a , b
1107
1116
}
1117
+
1118
+ // BlendOkLch blends two colors in the OkLch color-space, which should result in a better blend (even compared to BlendHcl).
1119
+ func (col1 Color ) BlendOkLch (col2 Color , t float64 ) Color {
1120
+ l1 , c1 , h1 := col1 .OkLch ()
1121
+ l2 , c2 , h2 := col2 .OkLch ()
1122
+
1123
+ // https://github.com/lucasb-eyer/go-colorful/pull/60
1124
+ if c1 <= 0.00015 && c2 >= 0.00015 {
1125
+ h1 = h2
1126
+ } else if c2 <= 0.00015 && c1 >= 0.00015 {
1127
+ h2 = h1
1128
+ }
1129
+
1130
+ // We know that h are both in [0..360]
1131
+ return OkLch (l1 + t * (l2 - l1 ), c1 + t * (c2 - c1 ), interp_angle (h1 , h2 , t )).Clamped ()
1132
+ }
1133
+
0 commit comments