CS 261 Lab H - Random Art

Due Wed Nov 05 at 3:00pm

Overview

In this lab you will practice working with recursively defined classes, using such recursive definitions to construct complex data structures out of simple components. Specifically, you will be creating classes that recursively model mathematical expressions. You'll be using this recursive definition of a mathematical expression to generate arbitrarily complex random expressions.

Why generate random mathematical expressions? Consider if you have an expression that uses some variables and that you are sure will evaluate to be between some specific bounds (say, between -1 and 1). For example, cos(𝜋 *x) of a number will always be between -1 and 1, as well avg(x,y) if the inputs are also within bounds.

Now take this expression and apply it to every pixel in an image (with the x and y being scaled down from the image width and height). Take the result of that expression and scale it a grayscale value of 0 - 255; in effect, you're creating a 3-dimensional graph of the function z = f(x,y), where the z value is represented by the "brightness" of the color. With a sufficiently complicated function, you can produce images such as the one below:

cos(𝜋 * cos(𝜋 * sin(𝜋 * cos(𝜋 * cos(𝜋 * x)) * cos(𝜋 * avg(sin(𝜋 * x), cos(𝜋 * avg(sin(𝜋 * sin(𝜋 * sin(𝜋 * x))) * sin(𝜋 * sin(𝜋 * cos(𝜋 * y))), cos(𝜋 * sin(𝜋 * avg(cos(𝜋 * cos(𝜋 * cos(𝜋 * avg(x, x) * avg(x, y)))), cos(𝜋 * avg(avg(sin(𝜋 * y), avg(x, x)) * avg(sin(𝜋 * 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:

This lab will let you use your recursive data structure for a mathematical expression to generate and evaluate random expressions in order to produce random artwork.

This lab will be completed in pairs. Partner assignments for this lab can be found on Moodle

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:

Assignment Details

Extensions

You might consider creating other Expressions to add to your data structure. Any mathematical function that, when given input(s) between -1 and 1 produces a value between -1 and 1 would work. For example the absolute value function would be an option, though will cut off the "dark" end of your picture. Consider making discontinuous functions, or functions that involve 3 or more expressions!

Submitting

Make sure your name is in a class comment at the top of your all (yes, all) of your classes, and upload the entire src folder to the LabH submission folder on vhedwig. 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.

After you have submitted your solution, log onto Moodle and submit the Lab H Partner Evaluation. Both partners need to submit evaluations.

Grading

This assignment will be graded out of 16 points: