Hopefully this is a simple one, I just can't get my mind around the formula and there might even be some builtin function for it. I want to create a sort of 1D gradient in the code: A dictionary of value maps which translate the value of a variable into a blend of linearly interpolated ranges. If anyone's curious it's for the density of my chunk terrain generator to allow defining how sharp the noise should be at different height values, like say between a position.y of -50 and +50 I want a density transition from 0.25 to 0.75.
For example: Let's say I have the following dictionary of maps:
density = {
"-20" = "1"
"-10" = "0.5"
"0" = "0"
"10" = "1"
"20" = "0.5"
}
When the value of x is translated, the result will be whatever in-between of its value lies in that dictionary. For instance: If x is 5 result is 0.5, if x is 15 result is 0.75, if x is -15 result is 0.75. What's the best way to calculate this translation?