I'm trying to set up Wolfram Code for the first time. I have a "manual" setup for the rules right now which I am not too happy about. What would be a more flexible way to set this up so that I can just use an integer for the rule I want? For example, I would like to be able to set:
- int theRule = 30;
To trigger the same conditions I wrote out in the code below:
- boolean[] alive;
- void setup() {
- size(801, 400, P2D);
- alive = new boolean[width*height];
- alive[width/2] = true;
- }
- void draw() {
- loadPixels();
- for (int i = width; i < width*height; i++) {
- // Get top 3 slots
- boolean topLeft = alive[(i-width-1+width*height)%(width*height)];
- boolean topMid = alive[i-width];
- boolean topRight = alive[(i-width+1+width*height)%(width*height)];
- // Rule 30
- if (topLeft && topMid == false && topRight == false) alive[i] = true;
- if (topLeft == false && topMid && topRight) alive[i] = true;
- if (topLeft == false && topMid && topRight == false) alive[i] = true;
- if (topLeft == false && topMid == false && topRight) alive[i] = true;
- // Display
- if (alive[i]) pixels[i] = 0;
- else pixels[i] = 0xffffff;
- }
- updatePixels();
- noLoop();
- }
1