The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
turtle.color()
This method is used to change the color of the turtle. The default color is black.
Syntax:
turtle.color(*args)
Parameters:
Format | Arguments | Description |
---|---|---|
turtle.color( colorstring ) | colorstring | A string of color name like “red”, “green”, etc. |
turtle.color( (r, g, b) ) | (r, g, b) | A tuple of three values r, g, and b using rgb color code |
turtle.color( r, g, b ) | r, g, b | Three values r, g, and b using rgb color code |
Below is the implementation of the above method with some examples :
Example 1 :
Python3
# importing package import turtle # use forward by 50 (default = black) turtle.forward( 50 ) # change the color of turtle turtle.color( "red" ) # use forward by 50 (color = red) turtle.forward( 50 ) |
Output :
Example 2:
Python3
# importing package import turtle # use forward by 100 (default = black) turtle.forward( 100 ) # change the color of turtle turtle.color( "red" ) # use forward by 100 in 90 degrees # right (color = red) turtle.right( 90 ) turtle.forward( 100 ) # change the color of turtle turtle.color(( 41 , 41 , 253 )) # use forward by 100 in 90 degrees # right (color = blue) turtle.right( 90 ) turtle.forward( 100 ) # change the color of turtle turtle.color( 41 , 253 , 41 ) # use forward by 100 in 90 degrees # right (color = green) turtle.right( 90 ) turtle.forward( 100 ) |
Output :