Simple linear interpolation function for Kotlin
$ npm install @datkt/lerp
$ konanc -r node_modules/@datkt/lerp -l lerp index.kt
$ ./program.kexe
import datkt.lerp.*
fun main(args: Array<String>) {
val x = toDouble(0, args, 0.123)
val y = toDouble(1, args, 0.456)
val t = toDouble(2, args, 0.5)
println("lerp(${x}, ${y}, ${t})=${lerp(x, y, t)}")
}
fun toDouble(i: Int, args: Array<String>, default: Double): Double {
val n = if (args.size > i + 1) args[i] else null
if (null != n && n.length > 0) {
return n.toDouble()
}
return default
}
Compute the linear interpolation between two points x
and y
with a
factor of t
.
val z = lerp(1.0, 2.0, 1.0) // z=2.0
MIT