What is the usage of pencolor in Python?
In Python, pencolor() is a method in the Turtle Graphics module used to set the color of a turtle’s pen for drawing.
By using the pencolor() method, you can set the color of the pen by passing different parameters. These parameters can be predefined color strings, RGB tuples, or hexadecimal color codes.
Here is an example of how to use the pencolor() method:
- Use predefined color strings:
import turtle
turtle.pencolor("red")
- Utilize RGB tuples:
import turtle
turtle.pencolor((255, 0, 0))
- Use hexadecimal color codes:
import turtle
turtle.pencolor("#FF0000")
Note: The color set by the pencolor() method in the example above only applies to the turtle drawn afterwards. If you wish to change the color of a turtle drawn previously, you will need to use the color() method.