def frac_to_rainbow_colour(frac):
    """
        frac is a number from 0 to 1. Map to
            a 3-tuple representing a rainbow colour.
        0 -> (0, 1, 0) #green
        1/6 -> (0, 0.5, 0.5) #cyan
        2/6 -> (0, 0, 1) #blue
        3/6 -> (0.5, 0, 0.5) #magenta 
        4/6 -> (1, 0, 0) #red
        5/6 -> (0.5, 0.5, 0) #yellow
        6/6 -> (0, 1, 0) #green again 
    """
    assert frac >= 0 and frac < 1
    interp = frac - int(frac/(1./6))*(1./6)
    if (frac < 1./6):
        #green to cyan
        to_return = (0, 1 - 0.5*interp, 0.5*interp) 
    elif (frac < 2./6):
        #cyan to blue
        to_return = (0, 0.5 - 0.5*interp, 0.5 + 0.5*interp)
    elif (frac < 3./6):
        #blue to magenta
        to_return = (0.5*interp, 0, 1 - 0.5*interp)
    elif (frac < 4./6):
        #magenta to red
        to_return = (0.5 + 0.5*interp, 0, 0.5 - 0.5*interp)
    elif (frac < 5./6):
        #red to yellow
        to_return = (1 - 0.5*interp, 0.5*interp, 0)
    else:
        #yellow to green
        to_return = (0.5 - 0.5*interp, 0.5 + 0.5*interp, 0)
    return to_return