Generative Art - Assignment seven

Due: 2014-01-16 10:30a

Objectives

[15 points] Balloons

The first part of this assignment is to fill the canvas with circles. In the end, you should have something like this:

Assignment7 Full

We draw this one circle at a time. On each pass through the draw() function, we pick a random spot on the canvas and we create a circle there. If there is already a circle there, we give up and wait for another iteration. If there isn’t a circle there, we iterate through all other circles and adjust the diameter of the circle so that it is as big as it can be without moving and without intersecting any other circles.

Set up the environment

We will be building an agent called Circle. Start, however, by creating an array of Circle objects. This should be declared (Circle circles[];) before setup(), and initialized with room for something like 1000 Circle objects. Do not put any circles in the array, however (i.e., do not put in the for loop that creates the Circle objects at each location in the array). Create a new variable before setup() called numCircles. Initialize this to be 0. This variable will hold the number of circles that we currently have in the array (we can’t use circles.length because we won’t be filling the array immediately). Set the background in setup() as well, because we want to accumulate our drawings.

In the draw() function, write an if statement that checks if numCircles < circles.length. If we have filled the array, we want to stop trying to add circles, so everything will go inside of this if statement. Create a new Circle variable and initialize it with a new Circle object (using new). Write a second if statement that checks if the circle is valid. We consider a circle to be valid if the diameter is at least 2. If the circle is valid, call its paint() method, and then add it into the array at the index numCircles. Finally, increment numCircles.

So, to summarize, in draw(), if you have more room in the array for another circle, you create one, see if it is valid (i.e., it didn’t land on another circle), and if it is, draw it and add it to the array.

Build the agent

Create a new agent called Circle. This should have three float properties: x, y, and diameter.

Start by initializing the variables. Set x and y to random locations on the canvas, and set the diameter to 200, which will be our largest diameter.

Before we finish with the constructor, write the paint() method. This should just draw an ellipse at the x, y, coordinates with the appropriate diameter. Run the code. If it works, it should be a bit like the triangle flurry, with random circles appearing all over the canvas.

Assignment7 Step1

Once that is working, go back to the constructor and add some conditional statement to shrink the diameter so that no part of the circle is outside of the bounds of the canvas.

Assignment7 Step2

Once that is working, you are ready for the hard part. We want to look at all of the other circles and a) make sure that the center of this circle is not inside of them, and b) shrink the diameter so that there is no overlap with other circles. Write a for loop that iterates through all of the circles. For each circle, calculate the distance between the center of the current circle and the one you are testing. You can use the dist function to do this. If you subtract half of the other circle’s diameter (i.e., the radius) from the distance, this tells you how close you are to the outside of the other circle. Set the diameter of your circle to be the minimum of 2 times this number and your current diameter. You can use the min function for this. If your diameter goes negative, then you are inside one of the other circles. You don’t have to do anything special if this happens, however, it will be caught in the draw() function you already wrote.

Having fun

I always encourage you to play with your sketches a bit, but this time I won’t require it. Many of you will find the bare functionality sufficiently challenging to understand (but I do still encourage it). Color is certainly one place you can play here. You could also do things like draw lines to the centers of the circles you intersect with, or indicate the misses somehow (make the color dependent on how many times it is “hit”?). Color could be dependent on how many circles you touch or how old the circle is, or how big it is. You could help the random process out a bit and allow the viewer to click to add circles using the mouse.

Naming your sketch

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

Take a picture

Play with he 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_hw7-####.png. If you want a really full image, you may have to wait a bit – the random algorithm is not terribly speedy about filling the last few gaps.

[+10 points] Bonus: Playing with particles

I showed you a basic particle system with an attractor. As a bonus, make something interesting using these building blocks.

Start by changing the functionality so that when you click on the canvas, you “drop” an Attractor at that point. You can draw something at that point or just let the pattern of the particles show you where it is. What happens as you have a number of different attractors in the field and you shoot particles through them?

You could also build repulsers. These are just the inverse of attractors (just flip the signs to the amount they add to the particle’s velocity). Maybe you could drop repulsers with a right-click.

Experiment with different speeds, sizes, coloring, and lifetimes of the particles. What happens if you don’t call background in the draw function? There are a lot of cool things you can do with particle systems. See if you can figure some of them out.

Naming your sketch

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

Take a picture

If you do this part, I would like a picture to go with it as well. Name it using the pattern username_hw7b-####.png.

Documentation

Don’t forget the documentation block below at the top of your sketch. Make sure that you specify what you did that was cool and interesting.

/**
Assignment Seven

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.