Computer generated contemporary art


Just a quick selection of images randomly-generated by the following 10 lines or so of Python.

import sys
import numpy as np
from PIL import Image

    filename = sys.argv[1]
except IndexError:
    filename = 'img.png'

rshift = 3
width, height = 600, 450
arr = np.ones((height, width, 3)) * 128

for y in range(1,height):
    arr[y,0] = arr[y-1,0] + np.random.randint(-rshift, rshift+1, size=3)

for x in range(1, width):
    for y in range(1,height-1):
        arr[y,x] = ((arr[y-1, x-1] + arr[y,x-1] + arr[y+1,x-1])/3 +
                            np.random.randint(-rshift, rshift+1, size=3))

im = Image.fromarray(arr.astype(np.uint8)).convert('RGBA')

Computer-generated art image 1

Computer-generated art image 2

Computer-generated art image 3

Computer-generated art image 4

Computer-generated art image 5

Computer-generated art image 6

Current rating: 4.5


Comments are pre-moderated. Please be patient and your comment will appear soon.

Joseph C. Slater 7 years, 1 month ago

Dr. Hill,
I'm working through your book, playing with examples, and this one drew my attention. However, I cannot figure out where the Image module is (with a capital "I"). There is an image package on pypi, but it's clearly not the same. Would you please clarify where this module can be found?

As an aside: my compliments on the text. I used to think I knew Python. I have two packages on pypi. I now realize that I have much more to learn. Thank you for such a wonderful text.

Link | Reply
Currently unrated

christian 7 years, 1 month ago

Hi Joseph,
Thanks for your kind comments: I'm constantly finding new things to learn about Python.
To answer your question, the most popular recent imaging library for Python is Pillow (, a fork of the older PIL library, and this contains the Image module.
I've updated the code above to do the import properly with this library: you can install it with pip or conda if you don't have it already.

Link | Reply
Current rating: 5

Peter 5 years, 2 months ago

Hi Christian

Thank you for this post ! Really great this "simple" generator - a loneley example that deserves the name ART generator ! It has motivated me to eliminate the two outer for-loops. This resulted in a speed gain of factor 12 (code:

And the mystery curves are inspiring too (

Thank you, Peter

Link | Reply
Currently unrated

New Comment


required (not published)