Monday, April 5, 2010

Cellular Automaton Part II

Well! It kind of worked!

My algorithm actually acted like dandelions! Heh. This is just the start.

I put a limit on how much the dandelions could cluster before I reassigned that grid box as zero (1 <= dandelion < 3). Wonderful!

Images:







PS. I understand there is some kind of function in Mathematica for making CA. By the time I found out, I had already coded most of my CA and didn't want to change so I just went along with my code. Plus, this is a much more enlightening experience than just writing: CellularAutomaton[...].

Thursday, April 1, 2010

Cellular Automaton Part I

I've been working on cellular automata and have been miserably failing.

I'm trying to do what I thought to be a "basic" automaton (I'm going to abbreviate to ca).

The basic ca runs as such:
1. Dandelions live for one step
2. Dandelions spread their seeds in the grid square right above, to the right, to the left, and below. We record this data in a list where each dandelion is any number greater than one. Spreading seeds is modeled by incrementing each "seeded" square's number by one.
3. The dandelion that spread its seeds dies by decrementing one. If there was a "cluster" of dandelions, then the decrement simply decrements the cluster down one.
4. Update and go back up to step one.

This "basic" code turned out to be much more challenging than I had thought.

I actually coded all the statements to randomly seed dandelions with 1/16 probability (get random integer from 0-15 and choose say 1 to indicate presence of dandelion). Then, I used a for loop to evaluate the inner boxes (all the boxes not on the outer edges) to avoid complications and ugly coding I really didn't want to do until I knew my algorithm as a whole worked well (which it, unfortunately, didn't). The body of the for loop was relatively simple: if the grid box it's evaluating at that moment has a value greater than or equal to one, then increment the boxes around it by one. Else, give it a value of zero, and move on.

Well, the result? The dandelions proliferated in far greater numbers than even GM dandelions on steroids would have reproduced... In essence, the grid was completely yellow. Not a speck of green. Why? Well, I didn't put a check on how much the dandelions could cluster before they died. So squares could accumulate massive numbers and no matter how many times it was decremented, it was simply incremented up at chaotic values.



And, well, the complete yellow one is just a waste of space.

<4/5/10: I actually fixed the code. Look one post after, labelled Cellular Automaton Part II>