been to an art museum and wondered how such a seemingly bizarre piece of art can get so famous or be sold at such a high price? Or how artwork that seems really easy to make with such basic techniques could also be so revered and attract a giant 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 wonder. His famous spot paintings include filled circles of various colours arranged in a grid form with a lightweight coloured background. These paintings, although so plain and straightforward, have been sold at auctions for as much as 1,000,000 dollars!
In this text, we’ll use Python’s colorgram and turtle module to create spot paintings, inspiration from Hirst’s color palette and techniques. It is a beginner-friendly Python tutorial but requires a basic knowledge of Python fundamentals, in addition to creating objects and using methods, and importing and using Python modules. Through this fun and interesting Python tutorial, we’ll learn to implement the concept of OOP in programming in addition to find out how we are able to get our purpose fulfilled using modules and just just a few lines of code.
Let’s awaken the artist inside us while we learn Python coding!
Spot Paintings
Hirst’s spot paintings include small spots of varied colours aligned in a grid form. The paintings are unique of their variety of dots, in addition to the colour palette utilized in these paintings. We’ll use Python’s colorgram module to be able to extract the colour palette from these so revered paintings, after which use Python’s turtle module to attract these spots in the shape of a grid. We are able to specify the variety of dots on our canvas, in addition to the space between them, and the colour scheme used.
For reference, consider checking these paintings through this link.
Extracting Colours
The very first thing is to extract a color palette from considered one of Hirst’s paintings. We’ll download the painting into the identical directory because the Python file wherein we’re writing our program. But first, allow us to install the colorgram module by writing the next command lines into the terminal:
pip install colorgram.py
Next, we’ll import the colorgram module into our code and use the extract function, while specifying the image file and the variety of colours we would like to extract from the reference image as arguments to the extract function. Here is the image file I actually have downloaded as “ref.jpg” and used to define the colour palette of my Python-generated spot painting.
import colorgram
colours = colorgram.extract("ref.jpg",20)
print(colours)
After we run the above lines of code, it is going to print out 20 colours which can be present within the reference image:
Notice that the colours extracted above are in a distinct format than is compatible with the turtle module. We’ll now turn these colours into turtle-compatible colours.
Creating the Color List
First, we’ll create an empty list and append the extracted colours one after the other after proper formatting into RGB format. We’ll tap into each of the r, g, and b values of the extracted colours and store them in our created list with appropriate formatting. For this purpose, we’ll use the for loop:
rgb_colors = []
for color in colours:
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)

As might be seen from the above image, the RGB colours have been properly formatted and may now be utilized ahead in randomly choosing the dot colours.
Importing Turtle and Configuring Basic Settings
Now, we’ll import the Python turtle module to create our artwork. We’ll define the essential settings of our turtle. The primary is the colormode(), which is able to resolve how we’ll use the colours in our code ahead, either between 0 and 1, or between 0 and 255. Take a look at more in regards to the function through this link.
import turtle
turtle.colormode(255)
tim = Turtle()
tim.shape("turtle")
tim.color("coral")
As we’re using the RGB colours of their 0-255 format, we’ve added 255 as an argument. Furthermore, we’ve also created the turtle object from the Turtle class within the Python turtle module and called it tim, in addition to customized its shapes and color. We might be using this turtle ahead as our drawing tool.
Positioning our Turtle
Now that we’ve created the turtle object, allow us to visualize with the assistance of the screen object.
from turtle import Screen
screen = Screen()
screen.exitonclick()

As might be seen from the image above, the turtle is positioned in the midst of the screen. We want the turtle to be on one corner in order that it starts creating the dots in a line. We are able to select the lower left corner as the place to begin, with the turtle moving from left to right after which upwards while drawing the dots.
We are able to 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 all know this might be done by setting the angle at 225. We’ll then move forward by a specific distance, say 300. Here is how our turtle is now at the underside left:

We’ll again set the direction the turtle is heading to 0, so we may start with our dot drawing.

Drawing the Dots
Now, since our turtle’s direction is about, we’ll start drawing the dots. We’ll use the turtle’s dot method, which takes the scale of the dot and the colour to be filled. We’ll achieve this dot drawing through the for loop, keeping in mind the entire variety of dots we would like. If we would like a ten by 10 grid of dots, the entire variety of dots might be 100. After every tenth dot, the turtle has to go up by a line and proceed drawing the dots. We’ll use the modulo operation for this purpose. Furthermore, we’ll import and use the random module to randomly select a color for every dot.
We’ll use the forward and setheading methods within the for loop to create the dots moving forward, after which up:
import random
number_of_dots = 100
for dot_count in range(1, number_of_dots + 1):
tim.dot(20, random.selection(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)

Hiding the Turtle and the Lines
Once our dots are created, we want to cover the turtle and the lines. We are able to easily do that with the hideturtle() and penup() methods.
tim.penup()
tim.hideturtle()
That is what the ultimate output will appear like once we execute the above lines of code:

Conclusion
As might be seen above, we’ve successfully created a wonderful artwork following Hirst’s dot technique. Python’s colorgram module allowed us to extract a wonderful color palette, and the turtle module helped us in creating the artwork using that palette. That is only a basic example of how such beautiful pieces might be created using code, and what happens when art and programming coincide.
