Hello!
I would like to get the progress for an interpolation, but I don't know how to do it.
I would like to make a rectangle green when an indicator going through it, so when the indicator is not at the rectangle I would like it to change color to red, and when it's getting closer to the rectangle then make it green. My only problem is that the rectangle is being on the middle and the indicator is going from left to right and then backwards, right to left. Here's what I would like to achieve, I created a gif for this, so it is easier to understand.
I would like to reach this, but can't seem to find a solution. Here's what I currently have:
local sx, sy = guiGetScreenSize()
local sizeX, sizeY = 230, 30
local centerX, centerY = sx / 2 - sizeX / 2, sy / 2 - sizeY / 2
local posX, posY = centerX, centerY
local barRange = 30
local barLeftSide, barRightSide = posX + sizeX/2 - barRange/2, posX + sizeX/2
local barMiddle = (barLeftSide + barRightSide)/2
local indicatorSize = 20
local indicatorX = posX - indicatorSize
local indicatorState = true
local colorProgress = 0
-- inside the render function
if indicatorState then
indicatorX = indicatorX + 5
else
indicatorX = indicatorX - 5
end
if indicatorX >= posX + sizeX then
indicatorState = false
end
if indicatorX <= posX - indicatorSize then
indicatorState = true
end
-- colorProgress = ?
local colorR, colorG, colorB = interpolateBetween(125, 20, 20, 20, 125, 20, colorProgress, "Linear")
dxDrawRectangle(posX + 2, posY + 2, sizeX - 4, sizeY - 4, tocolor(0, 0, 0, 150))
dxDrawRectangle(barLeftSide, posY + 2, barRange, sizeY - 4, tocolor(colorR, colorG, colorB, 255))
dxDrawImage(indicatorX, posY - indicatorSize, indicatorSize, indicatorSize, "files/indicator.png", 180)
So, how can I get the colorProgress to get the same effect as on the gif?