turtle.colormode() function in Python
Last Updated :
28 Jul, 2020
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.colormode()
This function is used to return the color mode or set it to 1.0 or 255. (r, g, b) values of color triples have to be in range 0 to c mode. It requires only one argument as “cmode” one of the values 1.0 or 255.
Syntax :
turtle.colormode(mode=None)
Below is the implementation of the above method with some examples :
Example 1 :
Python3
import turtle
print (turtle.color())
|
Output :
('black', 'black')
Example 2 :
Python3
import turtle
turtle.colormode( 255 )
turtle.color( 0 , 0 , 255 )
for i in range ( 20 ):
turtle.forward( 2 + 2 * i)
turtle.right( 90 )
turtle.colormode( 1.0 )
turtle.color( 1.0 , 0 , 0 )
for i in range ( 20 ):
turtle.forward( 40 + 4 * i)
turtle.right( 90 )
|
Output :
Share your thoughts in the comments
Please Login to comment...