Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
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
up vote 1 down vote accepted

You're probably looking for something like a logit or an expit or even a sine function with the right parameters put in. On a more practical level though, it might be easier to program in a piecewise-linear relationship b/w your mouse position and the strip movement based on where the strip is.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.