def _cal_color(self, value, color_index):
range_min_p = self._domain[color_index]<EOL>range_p = self._domain[color_index + <NUM_LIT:1>] - range_min_p<EOL>try:<EOL><INDENT>factor = (value - range_min_p) / range_p<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>factor = <NUM_LIT:0><EOL><DEDENT>min_color = self.colors[color_index]<EOL>max_color = self.colors[color_index + <NUM_LIT:1>]<EOL>red = round(factor * (max_color.r - min_color.r) + min_color.r)<EOL>green = round(factor * (max_color.g - min_color.g) + min_color.g)<EOL>blue = round(factor * (max_color.b - min_color.b) + min_color.b)<EOL>return Color(red, green, blue)<EOL>
Blend between two colors based on input value.