r"""Determine (relative) luminance of a colour.

    Args:
        mycolour(colourettu.Colour): a colour

    Luminance is a measure of how 'bright' a colour is. Values are
    normalized so that the Luminance of White is 1 and the Luminance of
    Black is 0. That is to say:

    .. code:: pycon

        >>> colourettu.luminance("#FFF")    # white
        0.9999999999999999
        >>> colourettu.luminance("#000")    # black
        0.0

    ``luminance()`` can also be called on an already existing colour:

    .. code:: pycon

        >>> c3.luminance()
        0.2641668488934239
        >>> colourettu.luminance(c4)
        0.08007571268096524

    .. note::

        Uses the formula:

        \\[ lum = \\sqrt{0.299 r^2 + 0.587 g^2 + 0.114 b^2} \\]

def luminance(mycolour):
    r"""Determine (relative) luminance of a colour.

    Args:
        mycolour(colourettu.Colour): a colour

    Luminance is a measure of how 'bright' a colour is. Values are
    normalized so that the Luminance of White is 1 and the Luminance of
    Black is 0. That is to say:

    .. code:: pycon

        >>> colourettu.luminance("#FFF")    # white
        0.9999999999999999
        >>> colourettu.luminance("#000")    # black
        0.0

    ``luminance()`` can also be called on an already existing colour:

    .. code:: pycon

        >>> c3.luminance()
        0.2641668488934239
        >>> colourettu.luminance(c4)
        0.08007571268096524

    .. note::

        Uses the formula:

        \\[ lum = \\sqrt{0.299 r^2 + 0.587 g^2 + 0.114 b^2} \\]
    """

    colour_for_type = Colour()
    if type(mycolour) is type(colour_for_type):
        mycolour2 = mycolour
    else:
        try:
            mycolour2 = Colour(mycolour)
        except:
            raise TypeError("Must supply a colourettu.Colour")

    (r1, g1, b1) = mycolour2.normalized_rgb()

    return math.sqrt(0.299*math.pow(r1, 2) +
                     0.587*math.pow(g1, 2) +
                     0.114*math.pow(b1, 2))