Discord
Login
Community
DARK THEME

lerp not fully functional

trying to make an effect where A goes from 0 to B (100000) with linear interpolation but it stops at about 49 behind B (99951) instead of reaching B can someone tell me why this is?

code:

init = function()
  number = 0
end

lerp = function(a,b,t)
  return a + (b - a) * t
end

update = function()
  number = round(lerp(number,100000,0.01))
end

draw = function()
  screen.clear()
  screen.drawText(number,0,0,50,"#FFF")
end
update = function()
  local value = round(lerp(number,100000,0.01))
  local step = value - number
  number = value
  print( number + " step = " + step )
end

you calculate 1% of the current distance between numbers (points).

Initially, the step value equals 1000.

Then it gradually decreases.

You always take 1% of the current length of the segment.

When the value of 1% of the segment is less than 0.5, it will be rounded to 0.0 (zero) and the length of the segment will not change any further.

Either give up rounding, or change the value of the variable t from 0.0 to 1.0 with a step of 1% (Then the value of the beginning and end does not change) .

Thanks.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community