Random Mondrian Art

Author: Ben Stephenson (ben.stephenson@ucalgary.ca)

Description:

This assignment asks students to create random "art" in a Mondrian style using a recursive algorithm.

The actual student handout from spring 2017: PDF Word
The actual student handout from fall 2017, which incorporates lessons learned: PDF Word

Metadata

Summary The Random Mondrian Art assignment has students create pseudo-random "art". While the provided algorithm produces basic art in a Mondrian style, the possibilities to extend the assignment and generate much more interesting art are nearly endless.
Audience I have used this assignment as the first assessment in a third-year programming language paradigms course that introduces students to functional programming for the first time. I also believe that it would work well as a recursion assignment toward the end of CS1, but I haven't yet had an opportunity to use it in that context.
Difficulty Students found this assignment to be moderately difficult, at least in part because it was the first program of significant length that they were ever asked to create on their own using Haskell. I give the students approximately 2 weeks to complete the assignment, both so that they have time to resolve problems they are experiencing because they are new to functional programming, and so they have time to experiment with the open-ended portion of the assignment. Similarly, I'd give students about 2 weeks to complete this assignment near the end of CS1.
Topics Recursion. When implemented in Haskell, lists are also used to manage the random numbers without requiring monads. Lists / arrays are not necessary when implementing in Java or Python.
Strengths The assignment provides nearly unlimited opportunity to express one's artistic style while also being an example of a problem that is easier to solve recursively than iteratively. The artistic aspect of the assignment encourages students to spend time coding, and to experiment with different strategies for generating the shapes and colors. The amount of variation in the submitted assignments is very large, suggesting that students were either interested in the assignment or very motivated by the small grade boost associated with implementing an extension to the provided algorithm.
Weaknesses In Haskell, generating a list of random numbers before calling the student created function to avoid using Monads is a little bit stilted, but it works (and based on the order in which I teach the course material has the beneficial side effect of forcing students to practice working with lists in addition to recursion).

The first time I used this assignment I had some cases where it was difficult to determine if the code the student submitted deviated from the provided algorithm due to inability to implement it, or for artistic reasons. The revised handout has (hopefully) addressed this by requiring students to implement the provided algorithm before modifying it to match their own artistic style.

The grading can be a little bit subjective when it comes to determining whether or not the enhancements implemented by students represent no extension, a modest extension or a substantial extension. As a result, I had more requests to override TA grading than I typically do. Despite this, I think that it is important to attach a small number of marks to the enhancements to encourage students to spent more time experimenting.

Dependencies In Haskell, we had the students generate HTML output to avoid being dependent on a particular graphics library as we are not aware of a good platform independent option for Haskell. A Java or Python implementation could display the output using any graphics library, or like the Haskell version, could output an HTML document that can be viewed in any modern browser.
Variants We left coming up with variants to the students (and motivated them to do so with a small number of marks). They didn't disappoint, as shown at the end of this document.

Starter and Completed Code:

Students were provided with this starter code: mondrian_start.hs.

My Haskell implementation of the basic algorithm can be found here: mondrian_basic.hs.

My extended version that uses additional colors, and uses the position within the image to influence which color is selected can be found here: mondrian_extended.hs.

A Python 3 implementation, which displays the output using TKinter rather than writing an HTML file can be found here: mondrian_basic.py.

Sample Student Images

Some of my favorite student images from the Spring 2017 term are shown below.