Generative Art With Haskell: A Start


These notes are nothing more than a work-through of the beautiful example of generative art by Benjamin Kovach — and a warm-up for future work. If you are interested in this kind of art, I highly recommend his post. Below is one piece produced by Kovach’s program. It uses a random seed, so each time you run the program, you will get a different result.

Random squares 1562245114949-20.png

The program is written in Haskell, with which I have little experience — Elm is the FP language that I work with the most. In case there are other Haskell newbies out there who want to try their hand at generative art, I’ve posted the code on GitHub. Look in at Main.hs in the ./app folder. Some comments on installing it below.

I heard Kovach speak at Strangeloop in St. Louis last year. His talk was a fine balance of history, esthetics, and code. The Cairo library which he uses to render his art is very fast (written in C).

Installing the program

I’ll have better instructions soon when I install this on a clean machine. The biggest stumbling block for me was in dealing with the various dependencies. For the most part, they are listed in package.yaml. A few packages required a new entry in the extra-deps section of stack.yaml. Consult the GitHub repo for details.

The algorithm I used to set up the dependencies was (a) run stack build; (b) scratch head while studying the error messages; (c) search (Google, Hackage) for the package name; (d) make a guess and add to package.yaml. (e) Go to (a) unless done.

Once the build process ran without error, I ran ./app/Main. The output appears in ./images/example_sketch.


A good piece of art is usually still a pretty good piece of art when it is desaturated so as to give a grayscale image. Then one sees only a pattern of light and dark values. Strong compositions generally are almost always ones that are still strong when viewed this way.

Random squares 1562245114949-20-desat.png