# Formula for positioning each image in a row of images

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.

-
Rather than just trying to describe what should happen (which is not very clear), why don't you start by telling us the behaviour that you want? Perhaps the name of some software which does this already? – Aryabhata Nov 16 '10 at 22:14
@Moron - See my edit. I hope it clears things up a bit. – Moshe Nov 16 '10 at 22:21
The question is still very imprecise. A lot of formulae will probably do what you want, as stated, but to pick a "nice" one, I suggest you try stackoverflow. – Aryabhata Nov 16 '10 at 22:33