I am writing a game, and I have a period (a repeating cycle) which is mapped to the scrolling of a background. I want to change this period, so that the scrolling is faster or slower--- but if I just change the period, the background's x position will JUMP to wherever it would be had it been moving at the rate of the new period. To compensate for this, I need to on a frame-by-frame basis, be gradually changing the period from the old and the new.
This is where my problem lies: I know the difference between the old and new period-- It's just not apparent to me how to figure out the formula for finding how many steps to break up this transition over time. Any help would be greatly appreciated.
What you're looking for is something called a tweener. A lot of information about tweeners can be found here.
The overview is that you'll need to somehow create an interval over which to change the period, and then call the tweener function to find out what the value at the current time should be. For example if we want to change the period from $2 \to 3$ over $1$ second then we would need to somehow call a function ever so often (depending on the platform you can use different things, in JS you can use
requestAnimationFrameorsetInterval, on Mac you can sync up with the display rate with theCVDisplayLink, on iOSCADisplayLinkand so on). Now lets calltimeElapsedthe amount of time elapsed since the animation has started. It's clear if you want the period to change linearly that the period at a giventimeElapsedshould be2 + timeElapsed. The article above describes how to abstract this into a general change from one number to another, over a general duration.