Fix lerp functions

This commit is contained in:
Sasha Koshka 2024-06-26 10:41:03 -04:00
parent b0108e6e0b
commit c883ec06db

View File

@ -39,7 +39,7 @@ func MultiLerp (fac float64, stages ...[]image.Point) []image.Point {
return result return result
} }
expandedFac := fac * float64(len(stages)) expandedFac := fac * float64(len(stages) - 1)
startIndex := int(expandedFac) startIndex := int(expandedFac)
if startIndex >= len(stages) { startIndex = len(stages) - 1 } if startIndex >= len(stages) { startIndex = len(stages) - 1 }
@ -49,7 +49,6 @@ func MultiLerp (fac float64, stages ...[]image.Point) []image.Point {
start := stages[startIndex] start := stages[startIndex]
end := stages[endIndex] end := stages[endIndex]
partialFac := expandedFac - float64(startIndex) partialFac := expandedFac - float64(startIndex)
println(startIndex, endIndex, int(partialFac * 100))
return Lerp(partialFac, start, end) return Lerp(partialFac, start, end)
} }
@ -82,5 +81,5 @@ func Translate (delta image.Point, path []image.Point) {
} }
func lerp (fac float64, x, y int) int { func lerp (fac float64, x, y int) int {
return int(float64(x) * fac + float64(y) * (1.0 - fac)) return int(float64(x) * (1.0 - fac) + float64(y) * fac)
} }