Generative Art - Assignment five

Due: 2014-01-14 10:30a

Objectives

[15 points] Drunken ant

This is an exercise in pure randomness. A very drunken ant has wandered into our paint box and is now roaming around on our canvas. After each step the ant takes, it forgets where it was going and randomly picks a new direction to travel in. Everywhere the ant goes, it leaves a track behind, which creates some curious patterns like these:

Assignment5 Ant 2

Assignment 5 Ant 2

The principle is pretty straightforward. This is very similar to the random line example we did last week, but we will be making use of variance instead of pure randomness. On each iteration of the draw() function, you pick a random number corresponding to the various directions that the “ant” can walk. You then draw a line from the old position to the new position.

To implement this, start by creating a pair of variables outside of the two functions for keeping track of the last position of the ant (I called mine lastX and lastY), and one that will hold the distance the ant will travel after making each decision. In setup(), set these two to some random position on the canvas. In the draw() function, create two new variables to hold the new position of the ant and set these to the values of the old position. Use random() to generate a random integer between 0 and 8. This number corresponds to the direction the ant should travel.

Assignment5 Ant

So, if the random number is 0, the ant will go north and the new y position of the ant will be lastY minus your distance. If the number is 1, the ant will go north east and the y position of the ant will be lastY minus your distance AND the x position will be lastX plus your distance (note that this means that on diagonals the actual distance traveled by the ant is a little longer, but that is okay). The other directions will work similarly.

Once you have created the new position for the ant, draw a line from lastX and lastY to your new position. Then update lastX and lastY to be the new values you calculated. Finally, check to see if lastY or lastX have gone off the canvas and if either one has, wrap it around to appear on the other side of the canvas.

The main controls for getting different looks is to change the coloring and the distance that the ant moves on each iteration. Note that for small values of distance you will have to wait a pretty long time for the ant to travel far enough to make an interesting pattern. You will also notice that the ant will trace over the same paths since it always travels the same distance. If you add in a small amount of randomness to the distance, the resulting path will be a little less regular. If the distance is only 1 or 2, the randomness is unnecessary, however.

Naming your sketch

I would like you to name the sketch using this pattern: username_hw5a.

Take a picture

Play with the distance and the coloring (and anything else that strikes you), and then please use the code I gave you in assignment 2 to take at least one picture of some state of your sketch that you like. Name it using the pattern username_hw5a-####.png.


[15 points] Smoke

The next exercise plays around with noise(). We are going to use it to simulate smoke (or fabric if you prefer). Here is what one of my runs looks like:

Assignment5 Smoke

The principle here is similar to the ant, but we are going to add a bit more control. We will start by doing a random walk from one side of the canvas to the other. I started with an x = 0, and y = height/4, but you are welcome to start wherever you like. I then created a while loop that would repeat until the x value crossed to the other side of the canvas (i.e., > width).

For each iteration of the while loop, I added a little bit of two dimensional noise to y, scaled to be between -1 and 1. For x, I added some one dimensional noise between 0 and 1 (this makes x always keep moving to the right, but not at a constant rate). After I computed the new x and y, I just called point(x,y).

To control the noise, I created two additional variables that I called noiseX and noiseY, which I initialized with some random numbers between 0 and 10. Walking across the screen, I increased noiseX by a small amount (0.008) after I drew each point. I kept noiseY fixed so that the y values were from one single “slice” of the Perlin noise space. For the 1D noise on x, I just passed in the sum of noiseX and noiseY. There are other possibilities, but this seemed to work. If you have this working, you will get a single meandering trace across the screen.

Assignment5 Smoke2

Now, we want to duplicate that a bunch of times to get a field instead of a line. So, put the whole while loop inside of a for loop. I used one that runs 400 times, incrementing the starting value of y by .25 for each iteration. You also want to reset noiseX to the random value you calculated at the start for each iteration of the for loop, and you want to increment noiseY by some similar small value. Think about the 2D noise as being on a plane. The first line drew a single line across the noise plane. The line below it wants to duplicate the path so that it mostly matches the line above it, but we will move some small amount down on the plane, which will introduce some small variations. It is fairly important that you manage the noise variables to traverse this space correctly, or the lines will not be sufficiently similar to create the effect.

[Note, since all of the drawing is being done in a loop and is controlled by random variables, put noLoop in setup() to only draw the image once (at least initially).]

Have some fun

Play with this sketch. Try different random scales. Tinker with the color and transparency. Maybe overlay a second sheet in a different color with different random values. Just tinker and see what happens.

Naming your sketch

I would like you to name the sketch using this pattern: username_hw5b.

Take a picture

Again, take at least one interesting picture from your work and submit it. Name it using the pattern username_hw5b-####.png.

Documentation

For both sketches, you should include the documentation block below at the top of your sketch. Make sure that you specify what you did that was cool and interesting.

/**
Assignment Five

A description of the sketch.

Your name
The date
**/

Turning in your work

I would like this code turned in in the DROPBOX on MiddFiles. You can refer to the reference on the LIS wiki to help you connect to the file server.