'Return color string corresponding to args.
Argument may be a string or a tuple of three
numbers corresponding to actual colormode,
i.e. in the range 0<=n<=colormode.
If the argument doesn\'t represent a color,
an error is raised.'

def _colorstr(self, color):

    if (len(color) == 1):
        color = color[0]
    if isinstance(color, str):
        if (self._iscolorstring(color) or (color == '')):
            return color
        else:
            raise TurtleGraphicsError(('bad    color    string:    %s' % str(color)))
    try:
        (r, g, b) = color
    except (TypeError, ValueError):
        raise TurtleGraphicsError(('bad    color    arguments:    %s' % str(color)))
    if (self._colormode == 1.0):
        (r, g, b) = [round((255.0 * x)) for x in (r, g, b)]
    if (not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255))):
        raise TurtleGraphicsError(('bad    color    sequence:    %s' % str(color)))
    return ('#%02x%02x%02x' % (r, g, b))
