Posts: 3
Threads: 1
Joined: Jul 2020
Hi, I am new to Python, and was wondering if it was possible to change the color automatically in the program. In fact, it would be to change the color in a loop. Could you enlighten me?
PS: Responses in French are also welcome.
Posts: 4,787
Threads: 76
Joined: Jan 2018
You want to change the color of what?
Posts: 3
Threads: 1
Joined: Jul 2020
The color of the pen, in the turtle.
Posts: 4,787
Threads: 76
Joined: Jan 2018
The official documentation of the turtle module starts with a colorful example. In python 3.8, there is also a turtledemo module with several examples that you can run.
Posts: 2,168
Threads: 35
Joined: Sep 2016
https://docs.python.org/3/library/turtle...e.pencolor Wrote:turtle.pencolor(*args)
Return or set the pencolor.
Four input formats are allowed:
pencolor()
Return the current pencolor as color specification string or as a tuple (see example). May be used as input to another color/pencolor/fillcolor call.
pencolor(colorstring)
Set pencolor to colorstring, which is a Tk color specification string, such as "red", "yellow", or "#33cc8c".
pencolor((r, g, b))
Set pencolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()).
pencolor(r, g, b)
Set pencolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0..colormode.
If turtleshape is a polygon, the outline of that polygon is drawn with the newly set pencolor.
>>> colormode()
1.0
>>> turtle.pencolor()
'red'
>>> turtle.pencolor("brown")
>>> turtle.pencolor()
'brown'
>>> tup = (0.2, 0.8, 0.55)
>>> turtle.pencolor(tup)
>>> turtle.pencolor()
(0.2, 0.8, 0.5490196078431373)
>>> colormode(255)
>>> turtle.pencolor()
(51.0, 204.0, 140.0)
>>> turtle.pencolor('#32c18f')
>>> turtle.pencolor()
(50.0, 193.0, 143.0)
Posts: 3
Threads: 1
Joined: Jul 2020
|