def fracToRainbowColour(frac):
    """
        frac is a number from 0 to 1. Map to
            a 3-tuple representing a rainbow colour.
        1 -> (0, 1, 0) #green
        0.75 -> (1, 0, 1) #yellow
        0.5 -> (1, 0, 0) #red
        0.25 -> (1, 1, 0) #violet
        0 -> (0, 0, 1) #blue
    """
    unscaledTuple = (min(1, 2 * frac) - max(0, (frac - 0.5) * 2),
                     max(0, 1 - (2 * frac)), max(0, 2 * (frac - 0.5)))
    # scale so max is 1
    theMax = max(unscaledTuple)
    scaledTuple = [x / float(theMax) for x in unscaledTuple]
    return scaledTuple