Creative computing with Clojure

Exploring Clojure as a tool to generate music, visual art, poetry, and dance.

creative_clojure

Clojure is gaining traction and popularity as a programming language. Both enterprises and startups are adopting this functional language because of the simplicity, elegance, and power that it brings to their business. The language originated on the JVM, but has since spread to run on the CLR and Node.js, including web browsers and mobile devices. With this spread of practical innovation, there has been another delightful development: a groundswell of people making art with Clojure.

Getting creative with Clojure

Creative Computing combines the power and engineering of the computer with the artistic inspirations of humans. People are using Clojure as a tool to generate music, visual art, poetry, and even dance. This ability to harness technology for creative purposes is both exciting and important. For it not only touches the heart and inspires existing technologists, but it also transcends all barriers. Art is a gateway to bring new people, young and old, from all walks of life, to the field of programming.

Let’s explore some of the areas of Creative Computing with Clojure, and showcase some inspiring examples from a selection of artist/programmers. We’ll look at projects that touch on music, art, games, writing, and even robots.

The scope of artistic expression is grand, so we’ll only scratch the surface, but we’ll attempt to highlight libraries and tools in each area that will provide a jumping-off point for the inspired.

We’ll start our tour with the realm of music.

Live coding music

Creating music with Clojure is a joy. The Overtone library allows you to not only make music with Clojure. Underneath the covers, the library provides an api to the SuperCollider synthesis engine. It has a rich set of scales, chords, rhythm, as well as a metronome timing system. One of the coolest things about Overtone, is the ability to make music interactively. Using the REPL, (Read-Eval-Print-Loop), a programmer can build up and create music in real-time. A wonderful example of this is a talk by Chris Ford on Functional Composition where he shows off Overtone in action. He starts off with a few simple principles, then builds up music in the REPL bit by bit, culminating in Bach’s Goldberg Variations.

This interactive, and collaborative nature of using Overtone was taken to new levels with Sam Aaron and Jonathan Graham. They combined forces to create a fantastic live coding band called Meta-eX. When performing, the music surrounding the audience is driven by live code. The code is front and center, being projected on a screen. The audience watches as the code is created and modified, driving the beat and the music. You really have to see them live to appreciate the whole experience, but here is a small excerpt from one of their live coding sessions, entitled Machine Run.

For live performances, Meta-eX also combines a visual element as well. Along with displaying the code, they will also show images, colors, and shadows that dance along with the music. Overtone has integration for two visual art libraries, Quil and Shadertone, that we’ll explore next.

Visual art

One of the most well known Clojure art libraries is Quil. It uses Processing to create sophisticated visual structures and artwork like this piece by Danielle Kefford.

hedera_helix_by_quephird-d8chot2

Quil supports both Clojure and ClojureScript. It is also well documented and provides examples of how to do generative art.

Shardertone is another lovely art library. One of the things I love about it is the integration with Overtone. It was designed to mix the Musical Synthesis and OpenGL shaders. Some of the shader examples can be seen in the Shadertoy website. When combined with the music of Overtone in a live-coding environment, the results are mesmerizing as in this video example by the REPL Electric.

People have also been experimenting with Clojure game platforms for visual art. This stunning pieces of visual art by Joseph Parker uses the Arcadia library to integrate Clojure with the Unity 3D game engine.

003

Other people have even been experimenting with combining Overtone and games as art. Joseph Wilk has been harnessing the musical beat in Overtone to generate 3D shapes in minecraft. By embedding a Clojure REPL inside the Minecrafter server, sound creates blocks and structures in this amazing demo.

Finally, Clojure has enabled a cool art project whose aim is to allow anyone to be an artist. The Devart-Codefactory project is an online design tool that empowers people by giving them a tool to create a complex 3d form. There is even the chance of having their art fabricated in 3D and showcased in an art exhibition. The tool, written in Clojure, has many fascinating examples created by its users in the gallery.

codefactory

Creativity is not limited to the visual and musical arts. Let’s explore how Clojure is used to produce poetry.

Poetry in code

Can computers create poetry? With Clojure, the answer is a resounding yes. People have used Clojure to generate haikus. They’ve also used them to generate text using Markov Chains. After this method is trained on a set of text, it then randomly generates new text and phrases with combined inputs.

A fun example of this is a Markov Chain generator that’s trained on the poetry of Edward Lear’s Nonsense Books with a good dose of Functional Programming from Wikipedia thrown in. The program is used by a twitter bot named FunctionalELear, that generates art tweets based off the input texts. The artful combination of such different spheres makes for some amusing text snippets.

16983522639_59a0bd68d0_b

So far we have covered music, visual art, and poetry. Let’s finish with some interpretive dance.

Robot dance party

With Clojure you can control robots. You can control everyday, helpful robots, like the Roomba with the clj-roomba library. You can control fun loving toy robots like the Sphero with the ellipso library. You can even control flying AR Parrot Quadcopter drones using Clojure with either the clj-drone or turboshrimp libraries. Once you can control movement with Clojure, through the interactive REPL, all you need for dance is to add music.

This presentation from O’Reilly Solid Con of a Real Time Robot Dance Party demonstrates the combination of music and robots. Through the power of the Clojure REPL and Overtone, a dance tune from Daft Punk is generated. Then using the signals from the beat, robot dance moves are coordinated all real time.

Hopefully you’ve enjoyed this small selection of creative computing projects using Clojure. The next time artistic inspiration strikes, pick up your text editor and create with Clojure.


Editor’s note: if you’re an experienced programmer looking for a thorough but gentle introduction to Clojure, check out Carin Meier’s Living Clojure.

tags: , , , , , , , , , ,