been to an artwork museum and questioned how such a seemingly peculiar piece of artwork can get so well-known or be offered at such a excessive value? Or how art work that appears really easy to make with such fundamental methods could also be so revered and appeal to a giant crowd of bidders? Such is the case with Hirst’s spot work.
Damien Hirst is an English artist well-known for his modern artwork on life, loss of life, and sweetness. His well-known spot work embrace 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 offered at auctions for as much as a million dollars!
On this article, we are going to use Python’s colorgram and turtle module to create spot work, inspiration from Hirst’s coloration palette and methods. 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. Via this enjoyable and attention-grabbing Python tutorial, we are going to be taught to implement the idea of OOP in programming in addition to find out how we will get our goal fulfilled utilizing modules and just some strains of code.
Let’s awaken the artist inside us whereas we be taught Python coding!
Spot Work
Hirst’s spot work embrace small spots of assorted 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 so as 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 gap between them, and the colour scheme used.
For reference, contemplate checking these work by this link.
Extracting Colours
The very first thing is to extract a coloration palette from one among Hirst’s work. We are going to obtain the portray into the identical listing because the Python file through which we’re writing our program. However first, allow us to set up the colorgram module by writing the next command strains into the terminal:
pip set up colorgram.py
Subsequent, we are going to 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)
Once we run the above strains of code, it should print out 20 colours which can be current within the reference picture:
Discover that the colours extracted above are in a special format than is appropriate with the turtle module. We are going to now flip these colours into turtle-compatible colours.
Creating the Colour Checklist
First, we are going to create an empty record 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 record with applicable formatting. For this goal, we are going to use the for loop:
rgb_colors = []
for coloration in colours:
r = coloration.rgb.r
g = coloration.rgb.g
b = coloration.rgb.b
new_color = (r, g, b)
rgb_colors.append(new_color)
print(rgb_colors)

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

As might be seen from the picture above, the turtle is positioned in the course of the display screen. 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 achieved by setting the angle at 225. We are going to then transfer ahead by a selected 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 might begin with our dot drawing.

Drawing the Dots
Now, since our turtle’s path is ready, we are going to 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 by 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 might 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 are going to import and use the random module to randomly select a coloration 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.alternative(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 Strains
As soon as our dots are created, we have to conceal the turtle and the strains. We are able to simply do that with the hideturtle() and penup() strategies.
tim.penup()
tim.hideturtle()
That is what the ultimate output will seem like as soon as we execute the above strains of code:

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

