Reputation: 45
import turtle
turtle.colormode(255)
turtle.color(130, 50, 50)
If I set the color mode to 1: turtle.colormode(1)
, what are the RGB values should I put here? turtle.color(?, ?, ?)
Thanks.
Upvotes: 1
Views: 2201
Reputation: 3021
Your colormode is set to 1.0
, so either the individual color coordinates need to be floats in the range 0.0
to 1.0
. Use float /
division operator.
Therefore, divide the r
, g
, b
values by 255
.
r = 130/255
g = 50/255
b = 50/255
color = (r, g, b)
turtle.color(color)
Upvotes: 0
Reputation: 169184
The docs say:
Return the colormode or set it to 1.0 or 255. Subsequently r, g, b values of color triples have to be in the range 0..cmode.
So, if cmode
is 1
, you'll need decimal RGB values (130 / 255, 50 / 255, 50 / 255 below):
turtle.color(0.51, 0.197, 0.197)
This is particularly useful with the colorsys
module, whose arguments are also in that range:
r, g, b = colorsys.hsv_to_rgb(0.2, 1, 1) # bright orange HSV
turtle.color(r, g, b)
Upvotes: 0
Reputation: 22776
Setting it to 1.0
means the rgb
values should be in the range [0, 1.0]
, which you can get by dividing each component in 255
mode by 255
:
import turtle
turtle.colormode(1.0)
turtle.color(130/255, 50/255, 50/255)
Upvotes: 2