been to an art museum and wondered how such a seemingly ordinary piece of art can get so famous or be sold at such a high price? Or how artwork that seems so easy to make with such basic techniques may be so revered and attract a big crowd of bidders? Such is the case with Hirst’s spot paintings.
Damien Hirst is an English artist famous for his contemporary art on life, death, and beauty. His famous spot paintings include filled circles of different colors arranged in a grid form with a light colored background. These paintings, although so plain and simple, have been sold at auctions for up to a million dollars!
In this article, we will use Python’s colorgram and turtle module to create spot paintings, inspiration from Hirst’s color palette and techniques. This is a beginner-friendly Python tutorial but requires a basic knowledge of Python fundamentals, as well as creating objects and using methods, and importing and using Python modules. Through this fun and interesting Python tutorial, we will learn to implement the concept of OOP in programming as well as learn how we can get our purpose fulfilled using modules and just a few lines of code.
Let’s awaken the artist within us while we learn Python coding!
Hirst’s spot paintings include small spots of various colors aligned in a grid form. The paintings are unique in their number of dots, as well as the color palette used in these paintings. We will use Python’s colorgram module in order to extract the color palette from these so revered paintings, and then use Python’s turtle module to draw these spots in the form of a grid. We can specify the number of dots on our canvas, as well as the distance between them, and the color scheme used.
For reference, consider checking these paintings through this link.
The first thing is to extract a color palette from one of Hirst’s paintings. We will download the painting into the same directory as the Python file in which we are writing our program. But first, let us install the colorgram module by writing the following command lines into the terminal:
pip install colorgram.py
Next, we will import the colorgram module into our code and use the extract function, while specifying the image file and the number of colors we want to extract from the reference image as arguments to the extract function. Here is the image file I have downloaded as “ref.jpg” and used to define the color palette of my Python-generated spot painting.
import colorgram
colors = colorgram.extract("ref.jpg",20)
print(colors)
When we run the above lines of code, it will print out 20 colors that are present in the reference image:

Colors Extracted from the Reference Image (Image by Author)
Notice that the colors extracted above are in a different format than is compatible with the turtle module. We will now turn these colors into turtle-compatible colors.
First, we will create an empty list and append the extracted colors one by one after proper formatting into RGB format. We will tap into each of the r, g, and b values of the extracted colors and store them in our created list with appropriate formatting. For this purpose, we will use the for loop:
rgb_colors = []
for color in colors:
r = color.rgb.r
g = color.rgb.g
b = color.rgb.b
new_color = (r, g, b)
rgb_colors.append(new_color)
print(rgb_colors)

Colors in RGB Format (Image by Author)
As can be seen from the above image, the RGB colors have been properly formatted and can now be utilized ahead in randomly selecting the dot colors.
Now, we will import the Python turtle module to create our artwork. We will define the basic settings of our turtle. The first is the colormode(), which will decide how we will use the colors in our code ahead, either between 0 and 1, or between 0 and 255. Check out more about the function through this link.
import turtle
turtle.colormode(255)
tim = Turtle()
tim.shape("turtle")
tim.color("coral")
As we are using the RGB colors in their 0-255 format, we have added 255 as an argument. Moreover, we have also created the turtle object from the Turtle class in the Python turtle module and called it tim, as well as customized its shapes and color. We will be using this turtle ahead as our drawing tool.
Now that we have created the turtle object, let us visualize with the help of the screen object.
from turtle import Screen
screen = Screen()
screen.exitonclick()

Turtle Object Customized (Image by Author)
As can be seen from the image above, the turtle is positioned in the middle of the screen. We need the turtle to be on one corner so that it starts creating the dots in a line. We can choose the lower left corner as the starting point, with the turtle moving from left to right and then upwards while drawing the dots.
We can achieve this with the turtle function setheading() that takes an angle as a parameter to set the direction of the turtle, and after some hit and trial, we know this can be done by setting the angle at 225. We will then move forward by a particular distance, say 300. Here is how our turtle is now at the bottom left:

Turtle Positioned (Image by Author)
We will again set the direction the turtle is heading to 0, so we may start with our dot drawing.

Turtle Direction Set (Image by Author)
Now, since our turtle’s direction is set, we will start drawing the dots. We will use the turtle’s dot method, which takes the size of the dot and the color to be filled. We will achieve this dot drawing through the for loop, keeping in mind the total number of dots we want. If we want a 10 by 10 grid of dots, the total number of dots will be 100. After every 10th dot, the turtle has to go up by a line and continue drawing the dots. We will use the modulo operation for this purpose. Moreover, we will import and use the random module to randomly choose a color for each dot.
We will use the forward and setheading methods in the for loop to create the dots moving forward, and then up:
import random
number_of_dots = 100
for dot_count in range(1, number_of_dots + 1):
tim.dot(20, random.choice(rgb_colors))
tim.forward(50)
if dot_count % 10 == 0:
tim.setheading(90)
tim.forward(50)
tim.setheading(180)
tim.forward(500)
tim.setheading(0)

Turtle Creating the Dots (Image by Author)
Once our dots are created, we need to hide the turtle and the lines. We can easily do this with the hideturtle() and penup() methods.
tim.penup()
tim.hideturtle()
This is what the final output will look like once we execute the above lines of code:

Python Turtle Artwork (Image by Author)
As can be seen above, we have successfully created a beautiful artwork following Hirst’s dot technique. Python’s colorgram module allowed us to extract a beautiful color palette, and the turtle module helped us in creating the artwork using that palette. This is just a basic example of how such beautiful pieces can be created using code, and what happens when art and programming coincide.