turtle.color() method in Python
Last Updated :
30 Jun, 2021
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
import turtle
turtle.forward( 50 )
turtle.color( "red" )
turtle.forward( 50 )
|
Output :
Example 2:
Python3
import turtle
turtle.forward( 100 )
turtle.color( "red" )
turtle.right( 90 )
turtle.forward( 100 )
turtle.color(( 41 , 41 , 253 ))
turtle.right( 90 )
turtle.forward( 100 )
turtle.color( 41 , 253 , 41 )
turtle.right( 90 )
turtle.forward( 100 )
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...