I need a differential equation for transitions in progress

I need a math equation that will give me an opacity given that a transition is already in progress.  Usually I use the following method for transitions.


@opacity_target = arg1


@opacity_duration = arg2


Then apply the following code each frame during the transition:


@opacity = (@opacity * (@opacity_duration - 1) + @opacity) / @opacity_duration


That works fine as long as I start the transition while on that map.  But I need to start that kind of a transition while not on that map, then determine the value of the opacity mid way through the transition.  I do not remember all the algebra formulas from high school any more.  I can also store more variables if needed.  What is the formula to do that?


(Mods: please move where most appropriate if needed)
I've moved this thread to Learning Ruby and RGSS. Please be sure to post your threads in the correct forum next time. Thank you.


Tech-Support is for getting the editors to run


Please confirm that this is for RMXP as in your profile, because someof the scripted solutions have differences between the makers
Math formulas apply to all game makers, even non rpg maker things.  What I need is the math formula, but yes, I do need it for XP...

Original thread: https://forums.rpgmakerweb.com/threads/i-need-a-differential-equation-for-transitions-in-progress.66051/