been to an artwork museum and puzzled how such a seemingly unusual piece of artwork can get so well-known or be bought at such a excessive worth? Or how paintings that appears really easy to make with such fundamental strategies could also be so revered and entice an enormous crowd of bidders? Such is the case with Hirst’s spot work.
Damien Hirst is an English artist well-known for his up to date artwork on life, demise, and sweetness. His well-known spot work embody stuffed circles of various colours organized in a grid type with a light-weight coloured background. These work, though so plain and easy, have been bought at auctions for as much as a million dollars!
On this article, we’ll use Python’s colorgram and turtle module to create spot work, inspiration from Hirst’s shade palette and strategies. It is a beginner-friendly Python tutorial however requires a fundamental information of Python fundamentals, in addition to creating objects and utilizing strategies, and importing and utilizing Python modules. By this enjoyable and fascinating Python tutorial, we’ll be taught to implement the idea of OOP in programming in addition to find out how we are able to get our goal fulfilled utilizing modules and just some traces of code.
Let’s awaken the artist inside us whereas we be taught Python coding!
Spot Work
Hirst’s spot work embody small spots of varied colours aligned in a grid type. The work are distinctive of their variety of dots, in addition to the colour palette utilized in these work. We are going to use Python’s colorgram module in an effort to extract the colour palette from these so revered work, after which use Python’s turtle module to attract these spots within the type 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, take into account checking these work via this link.
Extracting Colours
The very first thing is to extract a shade palette from considered one of Hirst’s work. We are going to obtain the portray into the identical listing because the Python file by which we’re writing our program. However first, allow us to set up the colorgram module by writing the next command traces into the terminal:
pip set up colorgram.py
Subsequent, we’ll import the colorgram module into our code and use the extract perform, whereas specifying the picture file and the variety of colours we wish to extract from the reference picture as arguments to the extract perform. Here is the picture file I’ve downloaded as “ref.jpg” and used to outline the colour palette of my Python-generated spot portray.
import colorgram
colours = colorgram.extract("ref.jpg",20)
print(colours)
After we run the above traces of code, it would print out 20 colours which are current within the reference picture:
Discover that the colours extracted above are in a distinct format than is suitable with the turtle module. We are going to now flip these colours into turtle-compatible colours.
Creating the Colour Checklist
First, we’ll create an empty listing and append the extracted colours one after the other after correct formatting into RGB format. We are going to faucet into every of the r, g, and b values of the extracted colours and retailer them in our created listing with acceptable formatting. For this goal, we’ll use the for loop:
rgb_colors = []
for shade in colours:
r = shade.rgb.r
g = shade.rgb.g
b = shade.rgb.b
new_color = (r, g, b)
rgb_colors.append(new_color)
print(rgb_colors)

As may be seen from the above picture, the RGB colours have been correctly formatted and might now be utilized forward in randomly deciding on the dot colours.
Importing Turtle and Configuring Fundamental Settings
Now, we’ll import the Python turtle module to create our paintings. We are going to outline the fundamental settings of our turtle. The primary is the colormode(), which is able to determine how we’ll use the colours in our code forward, both between 0 and 1, or between 0 and 255. Try extra concerning the perform via this link.
import turtle
turtle.colormode(255)
tim = Turtle()
tim.form("turtle")
tim.shade("coral")
As we’re utilizing the RGB colours of their 0-255 format, now we have added 255 as an argument. Furthermore, now we have additionally created the turtle object from the Turtle class within the Python turtle module and referred to as it tim, in addition to personalized its shapes and shade. We will likely be utilizing this turtle forward as our drawing software.
Positioning our Turtle
Now that now we have created the turtle object, allow us to visualize with the assistance of the display object.
from turtle import Display
display = Display()
display.exitonclick()

As may be seen from the picture above, the turtle is positioned in the midst of the display. We want the turtle to be on one nook in order that it begins creating the dots in a line. We are able to select the decrease left nook as the place to begin, with the turtle shifting from left to proper after which upwards whereas drawing the dots.
We are able to obtain this with the turtle perform setheading() that takes an angle as a parameter to set the path of the turtle, and after some hit and trial, we all know this may be finished by setting the angle at 225. We are going to then transfer ahead by a specific distance, say 300. Right here is how our turtle is now on the backside left:

We are going to once more set the path the turtle is heading to 0, so we could begin with our dot drawing.

Drawing the Dots
Now, since our turtle’s path is ready, we’ll begin drawing the dots. We are going to use the turtle’s dot method, which takes the scale of the dot and the colour to be stuffed. We are going to obtain this dot drawing via the for loop, conserving in thoughts the whole variety of dots we would like. If we would like a ten by 10 grid of dots, the whole variety of dots will likely be 100. After each tenth dot, the turtle has to go up by a line and proceed drawing the dots. We are going to use the modulo operation for this goal. Furthermore, we’ll import and use the random module to randomly select a shade for every dot.
We are going to use the ahead and setheading strategies within the for loop to create the dots shifting ahead, after which up:
import random
number_of_dots = 100
for dot_count in vary(1, number_of_dots + 1):
tim.dot(20, random.selection(rgb_colors))
tim.ahead(50)
if dot_count % 10 == 0:
tim.setheading(90)
tim.ahead(50)
tim.setheading(180)
tim.ahead(500)
tim.setheading(0)

Hiding the Turtle and the Traces
As soon as our dots are created, we have to disguise the turtle and the traces. We are able to simply do that with the hideturtle() and penup() strategies.
tim.penup()
tim.hideturtle()
That is what the ultimate output will appear like as soon as we execute the above traces of code:

Conclusion
As may be seen above, now we have efficiently created a fantastic paintings following Hirst’s dot method. Python’s colorgram module allowed us to extract a fantastic shade palette, and the turtle module helped us in creating the paintings utilizing that palette. That is only a fundamental instance of how such lovely items may be created utilizing code, and what occurs when artwork and programming coincide.
