Return 0 to 1 to 0 based on range?

I’ve run into a situation where I need to return a value based on x’s position in a range of y.

  • 0 of y return 0,
  • y/2 of y returns 1,
  • y of y returns 0

and all possibilities between, does anyone know some solutions to a problem like this?


if (value < y/2){
ret = value/(y/2);
ret = (y-value)/(y/2);