A limited collection of 64 algorithmically generated artwork in python
3 min read
Machine Psychology: Python Generated Art
A limited collection of 64 algorithmically generated artwork. Each unique piece is then given a title by the OpenAI GPT-3 language model.
This repository contains the code logic to generate the artwork. You can check out the full gallery at https://www.mach-psy.com/ and view the NFTs on OpenSea.
Usage
If you want to use this from the root directory, first make sure ./src is on the PYTHONPATH.
export PYTHONPATH=$PYTHONPATH:"./src"
(Optional) If you want to use OpenAI name generation, you also need to set up the API key otherwise the name generator will just label all pieces Untitled.
And there will be a preview image that combines both things.
Creation Process
Each item is generated by an algorithm. The first step is to pick the primary colors for the artwork. I pick a random HSV value in a range, then a secondary color based off of that.
defgenerate_starting_color():
# Choose starting HSV values.h=random.random()
s=random.choice([0.3, 0.5, 1, 1]) # Favor saturated colors.v=random.choice([0.2, 0.8]) # Either dark or bright.returnColor.hsv_float_to_rgb_int((h, s, v))
I also name the colors (this is important later) using a color-lookup table that picks the closest (Euclidean distance) match on its HSV value.
The color-to-name mapping logic was ported from an open-source JS script by .
The art itself is then generated by drawing a series of connected lines, with variable thickness. The color and thickness changes between each point. These colors, points, and thickness are then serialized into a code like this:
…which is then used to render the image. In this way, the meta-data also contains a redundant back-up of the image itself.
Name Generation
Finally, this is the most interesting part for me. The title of each piece is also generated by machine as well.
The color names (e.g. Rangitoto, Bright Turquoise) are used as part of a prompt to OpenAI GPT-3 language model.
It comes up with some very interesting stories for each image. For example:
VANISHED DREAMS
LET’S BURN THE CROWS
FROZEN OCEAN
Together the names and the images are both machine generated, and evoke some story or emotion (at least to me), which is why I called this collection “Machine Psychology.”
John was the first writer to have joined pythonawesome.com. He has since then inculcated very effective writing and reviewing culture at pythonawesome which rivals have found impossible to imitate.
Previous Post
A django model and form field for normalised phone numbers using python-phonenumbers
Next Post
Small code snippets for you to use in telegram bot projects