MCPcopy Index your code
hub / github.com/python/cpython / _colorstr

Method _colorstr

Lib/turtle.py:1134–1159  ·  view source on GitHub ↗

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.

(self, color)

Source from the content-addressed store, hash-verified

1132 self._shapes[name] = shape
1133
1134 def _colorstr(self, color):
1135 """Return color string corresponding to args.
1136
1137 Argument may be a string or a tuple of three
1138 numbers corresponding to actual colormode,
1139 i.e. in the range 0<=n<=colormode.
1140
1141 If the argument doesn&#x27;t represent a color,
1142 an error is raised.
1143 """
1144 if len(color) == 1:
1145 color = color[0]
1146 if isinstance(color, str):
1147 if self._iscolorstring(color) or color == "":
1148 return color
1149 else:
1150 raise TurtleGraphicsError("bad color string: %s" % str(color))
1151 try:
1152 r, g, b = color
1153 except (TypeError, ValueError):
1154 raise TurtleGraphicsError("bad color arguments: %s" % str(color))
1155 if self._colormode == 1.0:
1156 r, g, b = [round(255.0*x) for x in (r, g, b)]
1157 if not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255)):
1158 raise TurtleGraphicsError("bad color sequence: %s" % str(color))
1159 return "#%02x%02x%02x" % (r, g, b)
1160
1161 def _color(self, cstr):
1162 if not cstr.startswith("#"):

Callers 1

bgcolorMethod · 0.95

Calls 3

TurtleGraphicsErrorClass · 0.85
strFunction · 0.85
_iscolorstringMethod · 0.80

Tested by

no test coverage detected