Calculating target speed

i have some code that works out a target speed based on how far right of the screen ur mouse is as follows:


if(this._xmouse > value1 && this._xmouse < value2){
//set targetSpeed depending on how much greater than value1 it is
targetSpeed = this._xmouse-value1;
}

is there an elegant mathematical way to calculate the targetSpeed value so that - it increases as xmouse gets greater, ***until ***xmouse is at the value that is the midpoint of value1 and value2, from when on, targetSpeed ***decreases ***as _xmouse gets closer to value2

is that making sense?

so if value1 = 500, and value2 = 600, then as xmouse goes over 500, targetSpeed will increase 0, 1, 2, 3, 4 - up to 50. then as xmouse goes over 550 targetSpeed will decrease until xmouse is at 600, by then targetSpeed will be back to 0.

i can do it - but i think my ways are messy so im wondering if any maths/AS genius can suggest a simple method.