Hey! I recently discovered that lua lacks a pre-wrote function for Linear interpolation. So I decided to write my own!
function lerp(pos1, pos2, perc)
return (1-perc)*pos1 + perc*pos2 -- Linear Interpolation
end
This could be used in so many ways! From animations, to just trying to get that sweet spot on the screen. This is sure to come in handy!
EX:
-- Linear Interpolation
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
t=1
end
function lerp(pos1, pos2, perc)
return (1-perc)*pos1 + perc*pos2 -- Linear Interpolation
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
fontSize(50)
strokeWidth(5)
background(255, 0, 221, 255)
if t > 1 then t=0 end
t = t + 0.01
-- This sets the line thickness
text("Purple rain", lerp(0, WIDTH, t), lerp(0, HEIGHT, t))
fill(255, 255, 255, 255)
-- Do your drawing here
end