Code as a Liberal Art, Spring 2021

Unit 1, Exercise 4 homework & unit 1 presentations

Due for peer code review: Tuesday, February 16, 8pm;
and for in-class presentation: Wednesday, February 17

Create an algorithmically-generated concept collage

  1. Review the class notes for this week.
  2. Start with a concept keyword or phrase — for example: tree, anger, peace, work, blue, New York City. Gather some images of this concept. You should have at least 5 images, but could have many more. Working with more images will most likely not make the below steps any more difficult to follow. You can cull these from your own original photography or find them online. Create a new directory with your concept as its name and put all the images into it.

    Create a program that takes one command line argument. Assume this argument is the name of a directory. Get the list of files in that directory, and use random() to randomly select 4 to 5 images from that — let's call these your "working images."

    Use some of the pattern generation techniques from last week, but instead of setting pixel colors into a new, empty image, use your patterns to add some transparency to your working images. Remember that if you may be starting with an image like a JPG that does not have any alpha, you can first convert it into an image object that does:

    new_img = original_img.convert("RGBA")
    

    Then, create a new empty image, and collage your working images into it (see alpha_composite()). Save this new image as a file.

  3. Once you have this functioning, run it at least three times to create different visual representations of this concept.

  4. Create a second directory full of images for a second concept, and run your program a few times again specifying this directory on the command line.

Create a new folder in your student folder called "Unit 1, Exercise 4". Inside that, put your code file, your image directories, and your output images. Your output images should be clearly named to correlate with the directory of images that they're drawn from. (For example, if your concept and directory were called new-york-city/, your files might be new-york-city-1.png, new-york-city-2.png, etc.

Help

I received some questions about how to use a command line argument to specify a random photo from within a directory. I wanted to share my answer with everyone, so I created a code snippet and some explanation in a Github Gist. Have a look at that and let me know if you're still confused.

Presentation plan

Have all of your material uploaded to your Google folder by Tuesday, February 16, 8pm.

I have assigned each of you a classmate whose work you need to have a look at before class on Wednesday morning. The idea of code review is an important one in software development. Many organizations that develop software require any new code to go through a process of peer code review before that code is published live. Have a quick look at this article that offers a guide to doing code reviews. What we are doing here is not precisely a code review, but it's inspired by that idea. Find your code review assignment here.

Since we only have 100 minutes for 21 students, we are going to do very fast "lightning presentations". (For subsequent units we will have two days of presentations so you'll each get more time to share.) You will show us your image directories and your output images, then open up your code file. It will be the job of your peer reviewer to offer a quick comment about your work. The comment can be about concept, formal qualities, aesthetics, or other choices, but I would like the reviewer to say at least one specific thing about one part of the code while it is up on the screen. For example, "on line 25, this really interesting for loop is responsible for the square pattern." This is an exercise in reading code, but also talking about it — feel free to contact your reviewee via email or with a Github Gist if you have a question about their work.