CIELab and CIELch colour util

Former-commit-id: f8b0413223c2c968e4627e7c251220d32e2c6bf5
Former-commit-id: 2bce3479a8ad95ac06fbbd6c35cf73967a49568d
This commit is contained in:
Song Minjae
2016-09-01 21:36:44 +09:00
parent 6e51b0c751
commit b735335a99
10 changed files with 228 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
package net.torvald.colourutil
import com.jme3.math.FastMath
import org.newdawn.slick.Color
/**
@@ -7,4 +8,16 @@ import org.newdawn.slick.Color
*/
object ColourUtil {
fun toSlickColor(r: Int, g: Int, b: Int) = Color(r.shl(16) or g.shl(8) or b)
/**
* Use CIELabUtil.getGradient for natural-looking colour
*/
fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color {
val r = FastMath.interpolateLinear(scale, fromCol.r, toCol.r)
val g = FastMath.interpolateLinear(scale, fromCol.g, toCol.g)
val b = FastMath.interpolateLinear(scale, fromCol.b, toCol.b)
val a = FastMath.interpolateLinear(scale, fromCol.a, toCol.a)
return Color(r, g, b, a)
}
}