mirror of
https://github.com/irmen/prog8.git
synced 2025-12-19 20:17:17 +00:00
added floats.interpolate(), math.interpolate(), and LERP example
This commit is contained in:
@@ -662,4 +662,12 @@ log2_tab
|
||||
cx16.r0++
|
||||
return v0 + cx16.r0
|
||||
}
|
||||
|
||||
sub interpolate(ubyte v, ubyte inputMin, ubyte inputMax, ubyte outputMin, ubyte outputMax) -> ubyte {
|
||||
; Interpolate a value v in interval [inputMin, inputMax] to output interval [outputMin, outputMax]
|
||||
; There is no version for words because of lack of precision in the fixed point calculation there.
|
||||
cx16.r0 = ((v-inputMin)*256+inputMax) / (inputMax-inputMin)
|
||||
cx16.r0 *= (outputMax-outputMin)
|
||||
return cx16.r0H + outputMin
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user