CS 261 Lab H - Random Art

Due Wed Mar 27 at 9:00am

Overview

Formal grammars can let us quickly construct random phrases in a context-free language. In this lab, you will be implementing a specific grammar that to generate phrases in the language of mathematics: specifically, random mathematical expressions. While this is moderately interesting in its own right, if we're careful about the definition of our mathematical language, we can do even cooler things with the result. For example, if we have a function f(x,y) that we are sure will evaluate to be between specific bounds (say, between -1 and 1), we can apply the expression to the coordinates of every pixel in an image and scale the result to a grayscale value of 0 - 255, to effectively plot this function on the image grid (with the f(x,y) represented by the brightness of the color). With a sufficiently complicated function, we can produce images such as the one below:

cos(pi * cos(pi * sin(pi * cos(pi * cos(pi * x)) * cos(pi * avg(sin(pi * x), cos(pi * avg(sin(pi * sin(pi * sin(pi * x))) * sin(pi * sin(pi * cos(pi * y))), cos(pi * sin(pi * avg(cos(pi * cos(pi * cos(pi * avg(x, x) * avg(x, y)))), cos(pi * avg(avg(sin(pi * y), avg(x, x)) * avg(sin(pi * x), avg(y, y)), y))))))))))))

By applying different random expressions to each color channel (red, green, and blue), we can produce even more interesting effects:

In this lab, you will be writing a program to recursively generate, print, and evaluate random mathematical expressions (based on a specific grammar) in order to produce random artwork.

This lab will be completed in pairs. Review the pair programming guidelines!

Objectives

Necessary Files

You will need to download the copy of the RandomArtLab.zip file. This file contains two classes you will need to import into Eclipse:

Details

  • Once you have your RandomExpression working, you should be able to to run the RandomArtFrame class and begin to look at beautiful random artwork!
    • Depending on the complexity of your expression, producing a piece of artwork can take a few seconds (even a minute or two)--you may need to use a smaller frame, a less complex expression, or just be patient.
    • Note that not every image will look cool--if you get a lemon, just try again.
    • I've included a "Save" button so you can save any images you produce to disk! Feel free to submit your favorite images along with your assignment.
  • Submitting

    Submit all of your classes to the LabH submission folder on hedwig. Make sure you upload your work to the correct folder! The lab is due at the start of class on the day after the lab.

    Remember to fill out your lab partner evaluation!

    Grading

    This assignment will be graded based on approximately the following criteria: