(colours)
return final_mix
Convert text into a colour map.
    It could probably do with a rewrite to make it more efficient,
    as it was first written to only use capitals.

    Mixed Colour:
        Combine multiple colours.
        Examples: BlueRed, BlackYellowGreen
    Hexadecimal Colours:
        As well as typing in words, you may also use hex.
        All the same effects can apply to these.
        Supported formats are #RGB, #RGBA, #RRGGBB, #RRGGBBAA.
    Modified Colour:
        Apply a modification to a colour.
        If multiple ones are applied, they will work in reverse order.
        Light and dark are not opposites so will not cancel each other out.
        Examples: LightBlue, DarkLightYellow
    Transition:
        This ends the current colour mix and starts a new one.
        Examples: BlackToWhite, RedToGreenToBlue
    Duplicate:
        Avoid having to type out multiple versions of the same word.
        Be careful as it has different effects based on its position.
        It basically multiplies the next word, see below for usage.
        Examples:
            Before colour: DarkDoubleRed = DarkRedDarkRed
            Before modifier: TripleDarkLightRed = DarkDarkDarkLightRed
            Before transition: BlueDoubleToDarkRed = BlueToDarkRedToDarkRed
    Any number of these features can be combined together to create different effects.
        
    As an example, here are the values that would result in the heatmap:
        BlackToDarkBlueToBlueToCyanTripleBlueToCyanBlueTo
        + TripleCyanBlueToTripleCyanYellowToCyanYellowTo
        + CyanTripleYellowToYellowToOrangeToRedOrangeToRed
Convert text into a colour map.
    It could probably do with a rewrite to make it more efficient,
    as it was first written to only use capitals.
Convert text into a colour map . It could probably do with a rewrite to make it more efficient as it was first written to only use capitals .
def parse_colour_text(colours):
    """Convert text into a colour map.
    It could probably do with a rewrite to make it more efficient,
    as it was first written to only use capitals.

    Mixed Colour:
        Combine multiple colours.
        Examples: BlueRed, BlackYellowGreen
    Hexadecimal Colours:
        As well as typing in words, you may also use hex.
        All the same effects can apply to these.
        Supported formats are #RGB, #RGBA, #RRGGBB, #RRGGBBAA.
    Modified Colour:
        Apply a modification to a colour.
        If multiple ones are applied, they will work in reverse order.
        Light and dark are not opposites so will not cancel each other out.
        Examples: LightBlue, DarkLightYellow
    Transition:
        This ends the current colour mix and starts a new one.
        Examples: BlackToWhite, RedToGreenToBlue
    Duplicate:
        Avoid having to type out multiple versions of the same word.
        Be careful as it has different effects based on its position.
        It basically multiplies the next word, see below for usage.
        Examples:
            Before colour: DarkDoubleRed = DarkRedDarkRed
            Before modifier: TripleDarkLightRed = DarkDarkDarkLightRed
            Before transition: BlueDoubleToDarkRed = BlueToDarkRedToDarkRed
    Any number of these features can be combined together to create different effects.
        
    As an example, here are the values that would result in the heatmap:
        BlackToDarkBlueToBlueToCyanTripleBlueToCyanBlueTo
        + TripleCyanBlueToTripleCyanYellowToCyanYellowTo
        + CyanTripleYellowToYellowToOrangeToRedOrangeToRed 
    """
    
    colour_string = format_name(colours, '#')
    colour_data = parse_colour_file()['Colours']

    current_mix = [[]]
    current_colour = {'Mod': [], 'Dup': 1}
    while colour_string:
        edited = False

        #Check for colours
        colour_selection = None
        for colour, data in iteritems(colour_data):
            if colour_string.startswith(colour):
                colour_string = colour_string[len(colour):]
                colour_selection = data['Colour']
                break

        #Check for hex codes
        if colour_string.startswith('#'):
            length, colour_selection = hex_to_colour(colour_string[1:9])
            if colour_selection and length:
                colour_string = colour_string[1 + length:]

        #Process colour with stored modifiers/duplicates
        colour = None
        if colour_selection:
            edited = True
            
            #Apply modifiers in reverse order
            colour = list(colour_selection)
            for modifier in current_colour['Mod']:
                colour_offset = modifier.get('ColourOffset', 0)
                colour_shift = modifier.get('ColourShift', 0)
                alpha_offset = modifier.get('AlphaOffset', 0)
                alpha_shift = modifier.get('AlphaShift', 0)
                colour = [(colour[0] >> colour_shift) + colour_offset,
                          (colour[1] >> colour_shift) + colour_offset,
                          (colour[2] >> colour_shift) + colour_offset,
                          (colour[3] >> alpha_shift) + alpha_offset]
                          
            current_colour['Mod'] = []
            current_mix[-1] += [colour] * current_colour['Dup']
            current_colour['Dup'] = 1
            continue

        #Check for modifiers (dark, light, transparent etc)
        for i in MODIFIERS:
            if colour_string.startswith(i):
                colour_string = colour_string[len(i):]
                edited = True
                current_colour['Mod'] += [MODIFIERS[i]] * current_colour['Dup']
                current_colour['Dup'] = 1
        if edited:
            continue

        #Check for duplicates (double, triple, etc)
        for i in DUPLICATES:
            if colour_string.startswith(i):
                colour_string = colour_string[len(i):]
                edited = True
                current_colour['Dup'] *= DUPLICATES[i]
        if edited:
            continue

        #Start a new groups of colours
        for i in SEPERATORS:
            if colour_string.startswith(i):
                colour_string = colour_string[len(i):]
                edited = True

                #Handle putting a duplicate before 'to'
                new_list = []
                list_len = current_colour['Dup']
                if not current_mix[-1]:
                    new_list = current_mix[-1]
                    list_len -= 1

                #Start the ew list
                current_mix += [new_list] * list_len
                current_colour['Dup'] = 1
                break
        if edited:
            continue

        #Remove the first letter and try again
        colour_string = colour_string[1:]
    
    if not current_mix[0]:
        raise ValueError('invalid colour map: "{}"'.format(colours))

    #Merge colours together
    final_mix = []
    for colours in current_mix:
        
        result = colours[0]
        for colour in colours[1:]:
            result = [i + j for i, j in zip(result, colour)]
            
        num_colours = len(colours)
        final_mix.append(tuple(i / num_colours for i in result))
    return final_mix
def parse_colour_text ( colours ) : colour_string = format_name ( colours , '#' ) colour_data = parse_colour_file ( ) [ 'Colours' ] current_mix = [ [ ] ] current_colour = { 'Mod' : [ ] , 'Dup' : 1 } while colour_string : edited = False #Check for colours colour_selection = None for colour , data in iteritems ( colour_data ) : if colour_string . startswith ( colour ) : colour_string = colour_string [ len ( colour ) : ] colour_selection = data [ 'Colour' ] break #Check for hex codes if colour_string . startswith ( '#' ) : length , colour_selection = hex_to_colour ( colour_string [ 1 : 9 ] ) if colour_selection and length : colour_string = colour_string [ 1 + length : ] #Process colour with stored modifiers/duplicates colour = None if colour_selection : edited = True #Apply modifiers in reverse order colour = list ( colour_selection ) for modifier in current_colour [ 'Mod' ] : colour_offset = modifier . get ( 'ColourOffset' , 0 ) colour_shift = modifier . get ( 'ColourShift' , 0 ) alpha_offset = modifier . get ( 'AlphaOffset' , 0 ) alpha_shift = modifier . get ( 'AlphaShift' , 0 ) colour = [ ( colour [ 0 ] >> colour_shift ) + colour_offset , ( colour [ 1 ] >> colour_shift ) + colour_offset , ( colour [ 2 ] >> colour_shift ) + colour_offset , ( colour [ 3 ] >> alpha_shift ) + alpha_offset ] current_colour [ 'Mod' ] = [ ] current_mix [ - 1 ] += [ colour ] * current_colour [ 'Dup' ] current_colour [ 'Dup' ] = 1 continue #Check for modifiers (dark, light, transparent etc) for i in MODIFIERS : if colour_string . startswith ( i ) : colour_string = colour_string [ len ( i ) : ] edited = True current_colour [ 'Mod' ] += [ MODIFIERS [ i ] ] * current_colour [ 'Dup' ] current_colour [ 'Dup' ] = 1 if edited : continue #Check for duplicates (double, triple, etc) for i in DUPLICATES : if colour_string . startswith ( i ) : colour_string = colour_string [ len ( i ) : ] edited = True current_colour [ 'Dup' ] *= DUPLICATES [ i ] if edited : continue #Start a new groups of colours for i in SEPERATORS : if colour_string . startswith ( i ) : colour_string = colour_string [ len ( i ) : ] edited = True #Handle putting a duplicate before 'to' new_list = [ ] list_len = current_colour [ 'Dup' ] if not current_mix [ - 1 ] : new_list = current_mix [ - 1 ] list_len -= 1 #Start the ew list current_mix += [ new_list ] * list_len current_colour [ 'Dup' ] = 1 break if edited : continue #Remove the first letter and try again colour_string = colour_string [ 1 : ] if not current_mix [ 0 ] : raise ValueError ( 'invalid colour map: "{}"' . format ( colours ) ) #Merge colours together final_mix = [ ] for colours in current_mix : result = colours [ 0 ] for colour in colours [ 1 : ] : result = [ i + j for i , j in zip ( result , colour ) ] num_colours = len ( colours ) final_mix . append ( tuple ( i / num_colours for i in result ) ) return final_mix