I want to make a Damien Hirst type painting using python turtle, the one with the colourful dots spread out neatly on a canvas. So I'm using the turtle.dot function and have gotten my own colours using an external package.
However, the code is telling me that my colour sequence is wrong, "bad colour sequence".
I have asked ai to tell me what is wrong but it can't solve the problem and the course I'm following is showing a completely different route to solve the problem.
Here below is the code I put in PyCharm:
#create a hirst art piece
#download the colorgram art package
import os #import files on os comp
import colorgram #import package
from turtle import *
import turtle as t
import random
tim = t.Turtle()
"""
# Find the desktop path
desktop_path = os.path.expanduser("~/Desktop")
# Construct the full file path
image_path = os.path.join(desktop_path, "download.jpg")
# Extract colors from the image
colours = colorgram.extract(image_path, 12)
# Convert to RGB format
#rgb_colors = [(color.rgb.r, color.rgb.g, color.rgb.b) for color in colours] #
#rgb = proportion of each colour of light(red blue and green) in a given colour
print(rgb_colors)
#alternative:
rgb_colors = [] #create empty loop for colours
for color in colours:
rgb_colors.append((color.rgb.r, color.rgb.g, color.rgb.b)) #add the colour
#will print 12 values because we asked it to print 12 colours
print(rgb_colors)
"""
#colour list final
#use the things obtained via colorgram
#omit colours with rgb near 255(= white)
finalColourList = [(240, 232, 52), (225, 153, 66), (195, 12, 37), (189, 67, 29), (239, 44, 127), (37, 84, 178), (48, 214, 62), (233, 230, 4)]
for i in range(1, 100):
colourChoice = random.choice(finalColourList)
tim.penup()
tim.pencolor(colourChoice)
tim.dot(50) # Set the size
tim.forward(20) # Move the turtle forward
screen = Screen()
screen.exitonclick()
Here below is the error message on the console:
/Users/k/PycharmProjects/TurtleGraphics/venv/bin/python /Users/k/PycharmProjects/TurtleGraphics/art.piece.py
Traceback (most recent call last):
File "/Users/k/PycharmProjects/TurtleGraphics/art.piece.py", line 49, in <module>
tim.pencolor(colourChoice)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/turtle.py", line 2253, in pencolor
color = self._colorstr(args)
^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/turtle.py", line 2697, in _colorstr
return self.screen._colorstr(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/turtle.py", line 1167, in _colorstr
raise TurtleGraphicsError("bad color sequence: %s" % str(color))
turtle.TurtleGraphicsError: bad color sequence: (189, 67, 29)
Process finished with exit code 1