Return or set the pencolor and fillcolor. Arguments: Several input formats are allowed. They use 0 to 3 arguments as follows: - color() Return the current pencolor and the current fillcolor as a pair of color specification strings or tuples
(self, *args)
| 2242 | self.pen(speed=speed) |
| 2243 | |
| 2244 | def color(self, *args): |
| 2245 | """Return or set the pencolor and fillcolor. |
| 2246 | |
| 2247 | Arguments: |
| 2248 | Several input formats are allowed. |
| 2249 | They use 0 to 3 arguments as follows: |
| 2250 | - color() |
| 2251 | Return the current pencolor and the current fillcolor as |
| 2252 | a pair of color specification strings or tuples as returned |
| 2253 | by pencolor() and fillcolor(). |
| 2254 | - color(colorstring), color((r,g,b)), color(r,g,b) |
| 2255 | Inputs as in pencolor(), set both, fillcolor and pencolor, |
| 2256 | to the given value. |
| 2257 | - color(colorstring1, colorstring2), color((r1,g1,b1), (r2,g2,b2)) |
| 2258 | Equivalent to pencolor(colorstring1) and fillcolor(colorstring2) |
| 2259 | and analogously if the other input format is used. |
| 2260 | |
| 2261 | If turtleshape is a polygon, outline and interior of that polygon |
| 2262 | is drawn with the newly set colors. |
| 2263 | For more info see: pencolor, fillcolor |
| 2264 | |
| 2265 | Example (for a Turtle instance named turtle): |
| 2266 | >>> turtle.color('red', 'green') |
| 2267 | >>> turtle.color() |
| 2268 | ('red', 'green') |
| 2269 | >>> colormode(255) |
| 2270 | >>> color(('#285078', '#a0c8f0')) |
| 2271 | >>> color() |
| 2272 | ((40.0, 80.0, 120.0), (160.0, 200.0, 240.0)) |
| 2273 | """ |
| 2274 | if args: |
| 2275 | l = len(args) |
| 2276 | if l == 1: |
| 2277 | pcolor = fcolor = args[0] |
| 2278 | elif l == 2: |
| 2279 | pcolor, fcolor = args |
| 2280 | elif l == 3: |
| 2281 | pcolor = fcolor = args |
| 2282 | pcolor = self._colorstr(pcolor) |
| 2283 | fcolor = self._colorstr(fcolor) |
| 2284 | self.pen(pencolor=pcolor, fillcolor=fcolor) |
| 2285 | else: |
| 2286 | return self._color(self._pencolor), self._color(self._fillcolor) |
| 2287 | |
| 2288 | def pencolor(self, *args): |
| 2289 | """ Return or set the pencolor. |