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 package import turtle # check the default value print (turtle.color()) |
Output :
('black', 'black')
Example 2 :
Python3
# import package import turtle # set the colormode to 255 turtle.colormode( 255 ) # set color turtle.color( 0 , 0 , 255 ) # motion for i in range ( 20 ): turtle.forward( 2 + 2 * i) turtle.right( 90 ) # set the colormode to 1.0 turtle.colormode( 1.0 ) # set color turtle.color( 1.0 , 0 , 0 ) # motion for i in range ( 20 ): turtle.forward( 40 + 4 * i) turtle.right( 90 ) |
Output :