This might seem a bit of an odd question, but have you ever been to an art museum and looked at the
exhibition and thought to yourself, "I think I could probably do this, and I don't really understand why
it's considered art."
Well, this is a piece of art by Goldschmied and Chiari called, "Where Should We Go Dancing Tonight?"
And it's meant to be a piece of concept art,
but when the museum cleaners came here at the end of the day and looked at this mess of cigarette butts
and shoes and random bottles, they thought it was rubbish, and they promptly cleaned everything up.
So this is what the exhibition looked like after the cleaners were done the next day.
So to the museum's horror, their star exhibition gets cleared up and mistaken for rubbish.
So I was talking to a friend and I said, well, you know, a lot of these modern art pieces, I could
probably do it, right?
We could probably get together, put some bottles on the floor, make a mess, call it art.
And he told me, "Actually, no, you can't.
And you should read this book called, the $12 million Stuffed Shark."
And it talks all about the Economics of Contemporary Art.
And it's a fascinating read.
I've learned so much more about how contemporary art is priced, and why they're priced the way they are,
but it also led me to discover some pretty big, shocking discoveries.
Like, for example, the art piece that's referred to on the cover of the page is this shark.
It's a shark that was fished off of the coast of Australia, and then it was preserved in formaldehyde,
but it was preserved really badly, like they didn't use enough chemicals,
and the shark started going a bit green and a bit of gray in other places, and it also started molding,
but this moldy, green shark was bought for $12 million.
And this is not even the craziest piece.
So, for example, this diamond encrusted skull was reportedly sold for $50 million.
And these butterfly wings, which have been dissected and stuck to a canvas, was sold for 8.5 million.
So who exactly is this crazy man who's creating all of these pieces of art that's fetching these insane
valuations?
Well, it's a guy called Damien Hirst, and I think out of all his paintings, the craziest ones are
the spot paintings, because it's literally spots of color that are organized randomly on a page.
And check this out,
this particular piece was sold for a whopping £1.275 million, so maybe like $1.5 million.
It's insane for a painting of dots.
But what I thought was even crazier is if you look at this painting, at least it's got quite a few
dots, right?
You're getting your money's worth of dots,
but look at this one.
This is the same artist, Damien Hirst,
and this painting I counted only has 25 spots, and this sold for £0.5 million.
It's not even about the number of spots, so I personally still, as you can see, can't really work
out contemporary art.
But what I can work out is how to get Python code to crack Damien Hirst's colour palette, and use those
colours to generate a random canvas of spot paintings that look equally, if not more appealing, than
some of the original Damien Hirst's.
So this is what we're going to be making as our project.
And we're going to be using that Package, colorgram to get hold of the color palette,
and then we're going to use those colors to create our own spot painting that's going to look like this.
Firstly, we're going to be using a package called colorgram, and colorgram is a library of code written
in Python that lets you extract colors from images.
So for example, if you take a look at this picture, once it was run through color gram and ten of
the most common colors extracted, you end up with a palette that pretty much looks the same as the
colors in the image.
This is the example of how you would use this colorgram package, and in this case, they're extracting
six colors from an image.
So it basically takes two inputs an image, and the number of colors.
If we go into Google image search and we search for a Hirst spot painting, you can see that there's
a lot of spot paintings that this guy created.
I want you to pick a painting with a color palette that you like.
Maybe something like this, or maybe a bit brighter, like this one.
But essentially, pick one of these images and then go ahead and download it.
So save image, and then you're going to save that image as image.jpeg.
So jpg, and then go ahead and hit Save.
Now go ahead and create a new PyCharm project I've called mine hirst-painting.
You can call yours whatever you want.
Now we're going to drag our newly downloaded image, image.jpg into this project folder, hirst-painting.
And it's going to ask you whether, if you want to move the file from, in my case, the downloads folder
to my hirst-painting project.
So then we're going to agree and click Refactor.
So now this painting is inside my hirst-painting project,
and I'm ready to go ahead and create a new file called main.py, which is what I'm going to use to extract
the colors from this image.
Here's a challenge for you.
See if you can figure out how to use this package, colorgram, using their project description here and
using the example code.
What you're aiming for is to be able to print out a list of all the colors extracted from the image,
and each item in the list to be a tuple that you create.
So remember previously we saw how the turtle module likes to work with color tuples, which are created
with an amount of red, the amount of green, and the amount of blue, all contained inside a tuple.
This is the format that you're going to try and get your data into.
It might take a little bit of wrangling and a little bit of thought.
Pause the video and complete this challenge.
All right.
So we know that in order to use external packages, ones that weren't installed with the Python standard
library, we have to first install the package.
To install a package, we go to our Preferences and then we select our project,
and then we go to our Project Interpreter.
Now we click the plus button and we search for colorgram.
And there it is.
Now let's go ahead and install the package.
And once that's installed successfully, then we can close all of this and click Okay.
Now that we've got our package we can actually import it.
So we'll import colorgram.
And we can use the method that's described here called color gram.extract() in order to get hold of
six colors.
Now, if we want more colors, for example, in this image there's probably a good 30 colors,
so let's go ahead and extract 30 colors from this image,
but of course our image is not called, sweet_pic.jpg,
ours is actually called image.jpg.
So let's go ahead and rename this image so that it matches with our file.
And remember that your image has to be at the same level as your main.py for this kind of code to work.
So make sure that you've got it inside the hirst-painting project folder on the same indentation level
as main.
Now let's go ahead and print out our colors that are generated.
And remember that when you hit Run, this process might take a little while.
And the author of the library says that for a 512 * 512 image, it takes about 0.66 of
a second.
Obviously, if the image is larger, it'll probably take a bit longer.
Let's go ahead and hit Run and see what we get.
Once the process is finished, you can see it's created some colors and these colors are in a list.
And it's got some different formats for the color.
To understand that we have to go back to our documentation.
You can see that the color that's extracted can either be a RGB color, which is what we're interested
in, or a HSL color, which is not quite what we want.
So let's go ahead and write a for loop that taps into each of those colors.
So 'for color in colors:' let's go ahead and create a new list called rgb_colors,
and we'll just leave it as an empty list.
And then for each of these colors, we're going to add to our rgb_colors by appending.
And the thing we're going to append() is each of these individual color objects,
and then we're going to get the rgb value.
And once this process is done then let's go ahead and print our rgb_colors.
So now you can see we've got a whole bunch of rgb_colors with r equals what, g equals what, and b equals
what,
but this is not quite the format that we need it.
In order to use it inside the turtle, we actually have to go one step further,
we have to create an r, which is from the color.rgb.r.
And then we repeat this process for green.
and blue.
And then we create our tuple by creating our new_color, which is going to be equal to a tuple with
a parentheses.
And then r, g, and b.
Finally, we're going to add to our rgb colors by appending this new_color.
Now let's print our rgb colors,
and you can see we've finally got it in the format that we need, a tuple with the r value, g value,
and b value that we can use in our project.
Now we've managed to get the first part of the problem solved, so we can go ahead and copy this entire
list, and paste it into our main.py.
I recommend actually testing out these colors using the W3 schools, RGB tool.
Go ahead and paste your color to replace this current tuple here.
Make sure that you've still got that word rgb there, and then hit Enter and it will insert each of
these values into the r, g, and b.
So you can see the first color we got is actually a shade of white.
So it probably one of the backgrounds.
So we can go ahead and delete that one,
because we're not going to be painting the background in our dot,
it's just going to be white.
Now let's check the next one.
As you can see, the closer the numbers are to 255, the more likely it is that it's a shade of white.
So this one is probably one of the other background colors in this image.
So we can delete that one as well.
And finally, this last one is probably going to be also quite whitish,
and we can probably delete that one too.
This one because of the blue that's 109,
I'm going to be pretty sure that this is actually a real color,
and there we go.
We get this kind of sand color, which looks very similar to some of these colors that we see on here.
So we can presume that the rest of these, because they're sampled by the frequency of occurrence,
are probably going to be real colors that we can put into our painting.
Let's save this list as our color_list.
And we can comment out the rest of this code, because we don't need to run this computation every single
time,
we just want to extract the colors,
and then you can delete or comment out the colorgram-related code.
In the next lesson, we're going to be using this color_list to create our hirst-painting.
So for all of that and more, I'll see you there.