Calculate a ratio from part of a range. I'm building a smartphone javascript application but my question today is really only math related. To give you a quick idea of what I'm doing, my code checks the smartphone's gyroscope to determine how much it is rotated. Based on that rotation, it's supposed to pan a background image around. So in the image below, the red box is stationary, while the photo is supposed to pan around in the background as you rotate your device.

Anyway, here's the math problem (focusing only on moving the X axis):


*

*The gyroscope gives a reading of 0 to 360

*The photo in the background gets moved from the top left, so its max and min values are 0 to -100

*Therefore the formula for how much to move the image based on the device rotation would be a simple ratio: (Gyroscope Reading * -100)/360

*However, I don't want people to need to turn their device all the way over to achieve the full animation, so I'm only interested in the gyroscope readings of about 140 to 220. 

*So, what formula would achieve 140 = 0 and 220 = -100? The formula should maintain the ratio for all points in between. 


You want a line that goes through $(140,0)$ and $(220,-100)$.  The two point form says it is $y-0=\frac {-100-0}{220-140}(x-140)$.  $x$ is the gyro, $y$ the output.  I left the constants so you could match them up with the equation in case you want to change them in the future.
