We have a heatmap we want to display. The numbers that will make up the values being displayed are unknown (except that they will be positive integers). The range of numbers
Going off of the picture provided by Chris H, you can model the rgb values as:
r = min(max(0, 1.5-abs(1-4*(val-0.5))),1); g = min(max(0, 1.5-abs(1-4*(val-0.25))),1); b = min(max(0, 1.5-abs(1-4*val)),1);