(self, n, as_int=True)
Calculate colour for given value.
Calculate colour for given value.
Calculate colour for given value .
def calculate_colour(self, n, as_int=True):
        """Calculate colour for given value."""
        offset = (n + self.offset - self.min) / self.amount_diff
        index_f = self._len_m * offset

        #Calculate the indexes of colours to mix
        index_base = int(index_f)
        index_mix = index_base + 1
        if self.loop:
            index_base %= self._len
            index_mix %= self._len
        else:
            index_base = max(min(index_base, self._len_m), 0)
            index_mix = max(min(index_mix, self._len_m), 0)

        #Mix colours
        base_colour = self.colours[index_base]
        mix_colour = self.colours[index_mix]
        mix_ratio = max(min(index_f - index_base, 1), 0)
        mix_ratio_r = 1 - mix_ratio

        #Generate as tuple
        if as_int:
            return tuple(int(i * mix_ratio_r + j * mix_ratio)
                         for i, j in zip(base_colour, mix_colour))
        else:
            return tuple(i * mix_ratio_r + j * mix_ratio for i, j in zip(base_colour, mix_colour))
def calculate_colour ( self , n , as_int = True ) : offset = ( n + self . offset - self . min ) / self . amount_diff index_f = self . _len_m * offset #Calculate the indexes of colours to mix index_base = int ( index_f ) index_mix = index_base + 1 if self . loop : index_base %= self . _len index_mix %= self . _len else : index_base = max ( min ( index_base , self . _len_m ) , 0 ) index_mix = max ( min ( index_mix , self . _len_m ) , 0 ) #Mix colours base_colour = self . colours [ index_base ] mix_colour = self . colours [ index_mix ] mix_ratio = max ( min ( index_f - index_base , 1 ) , 0 ) mix_ratio_r = 1 - mix_ratio #Generate as tuple if as_int : return tuple ( int ( i * mix_ratio_r + j * mix_ratio ) for i , j in zip ( base_colour , mix_colour ) ) else : return tuple ( i * mix_ratio_r + j * mix_ratio for i , j in zip ( base_colour , mix_colour ) )