mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
CIELab and CIELch colour util
Former-commit-id: f8b0413223c2c968e4627e7c251220d32e2c6bf5 Former-commit-id: 2bce3479a8ad95ac06fbbd6c35cf73967a49568d
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user