Reputation: 634
I was trying to specify the RGB colors to make the program generate random colors. I was trying how to do RGB colors however, it would show an error that it had bad color input, more specifically, "raise TurtleGraphicsError("bad color sequence: %s" % str(color)) turtle.TurtleGraphicsError: bad color sequence: (0, 255, 0)"
from random import randint
myPen = turtle.Turtle()
myPen.ht()
myPen.speed(0)
myPen.pencolor(0,255,0)
myPen.begin_fill()
points = [[-500,-400],[0,500],[500,-400]] #size of triangle
def getMid(p1,p2):
return ( (p1[0]+p2[0]) / 2, (p1[1] + p2[1]) / 2) #find midpoint
def triangle(points,depth):
myPen.up()
myPen.goto(points[0][0],points[0][1])
myPen.down()
myPen.goto(points[1][0],points[1][1])
myPen.goto(points[2][0],points[2][1])
myPen.goto(points[0][0],points[0][1])
if depth>0:
z=(randint(0,255),randint(0,255),randint(0,255))
myPen.fillcolor(z)
triangle([points[0],
getMid(points[0], points[1]),
getMid(points[0], points[2])],
depth-1)
triangle([points[1],
getMid(points[0], points[1]),
getMid(points[1], points[2])],
depth-1)
triangle([points[2],
getMid(points[2], points[1]),
getMid(points[0], points[2])],
depth-1)
triangle(points,7)
Upvotes: 2
Views: 717
Reputation: 41895
Your question, and self answer, imply something that isn't true. Python turtle is RGB by default. What it isn't is integer color values. The default is RGB floating values:
from turtle import Screen
from random import random
color = random(), random(), random()
screen = Screen()
screen.bgcolor(color)
screen.exitonclick()
Using colormode()
, you're switching between floating and integer RGB values.
You can also switch to other color models, like HSB, via loading additional Python libraries and converting those color models into RGB for turtle.
Upvotes: 1
Reputation: 634
I have found that you need a window
(or whatever variable)=turtle.Screen()
. Then you can do window.colormode(255)
Then you can change the color scheme
Upvotes: 2