I'm working on a program that displays a bunch of thumbnails on the bottom of the screen and I'm using the mouse's position to slide the images from side to side.
The center of the screen is 0 on a number line. Every frame, the mouse's X position is either added or subtracted from the x position of each thumbnail. (So if the mouse is at -15, each thumbnail will move -15 pixels.)
The images should stop moving if they are too far from the center. "Too far" means that they are off the screen to a particular side, or if there are more images than fits on the screen, the image should stop sliding when there is enough room for the last image to appear on the opposite side.
I guess you could say that the x position of each thumbnail is a function of the mouse position, what number thumbnail it is and the the number of thumbnails. The screen width is 800 here (or -400 to 400)
What would be the mathematical formula for the above scenario?
EDIT, a (perhaps) clearer explanation of what I want:
I want the images to scroll horizontally. If the mouse is on the right, they should move towards the left, and if the mouse is on the left, the images should scroll towards the right.
The images should stop scrolling so that they never completely scroll offscreen. (If there are more images than the screen can show, allow images to scroll off just enough to show the other images.)
The speed of the scrolling depends on the distence of the mouse cursor from the center.