//import processing.opengl.*; //Conway Game of Life //This version by Robert Carlsen, 8-2008 /* 1. Any live cell with fewer than two live neighbours dies, as if by loneliness. 2. Any live cell with more than three live neighbours dies, as if by overcrowding. 3. Any live cell with two or three live neighbours lives, unchanged, to the next generation. 4. Any dead cell with exactly three live neighbours comes to life. //looking to move into 3d */ //some globals //array for the pixels int[][] world; //going to use a one-dimentional array sx*sy*sz long int sx,sy,sz; float density = 0.5; //ranges for rules of life int low = 3; int high = 6; int[][] matrix = {{-1,-1,0},{0,-1,0},{1,-1,0},{-1,0,0},{1,0,0},{-1,1,0},{0,1,0},{1,1,0}, {-1,-1,-1},{0,-1,-1},{1,-1,-1},{-1,0,-1},{1,0,-1},{-1,1,-1},{0,1,-1},{1,1,-1},{0,0,-1}, {-1,-1,1},{0,-1,1},{1,-1,1},{-1,0,1},{1,0,1},{-1,1,1},{0,1,1},{1,1,1},{0,0,1} }; void setup() { size(500,500,P3D); //smooth(); //frameRate(15); sx = 30; sy = 30; sz = 30; world = new int[sx*sy*sz][2]; //populate the world // Set random cells to 'on' for (int i = 0; i < sx * sy * sz * density; i++) { world[(int)random(sx*sy*sz)][1] = 1; } noStroke(); } void draw() { background(0); lights(); fill(200,200); //draw the array for(int i=0;ihigh) world[j][1] = 0; //2 or 3 remain unchanged } else { //exactly three will spawn life if(count==high) world[j][1] = 1; } } } int coordsToIndex(int x, int y, int z){ //convert from coordinates to the array index //use the plane first (z), then the row (y), then the column (x) return z*sx*sy+y*sx+x; } int[] indexToCoords(int index) { //convert the index to x,y,z values int z = index/(sx*sy); int y = (index%(sx*sy))/sx; int x = (index%(sx*sy))%sx; int[] coords = {x,y,z}; return coords; } void keyPressed(){ if (key==CODED){ switch(keyCode){ case UP: if(low < high) low++; break; case DOWN: if(low>0) low--; break; case RIGHT: high++; break; case LEFT: if(high>1 && high>low) high--; break; } println("low: "+low+", high: "+high); } } int startX,startY; float rotY,rotX,sRotX,sRotY; void mousePressed() { startX = mouseX; startY = mouseY; sRotX = rotX; sRotY = rotY; } void mouseDragged() { rotY = map(mouseX-startX,0,width,sRotY,sRotY+TWO_PI); rotX = map(startY-mouseY,0,height,sRotX,sRotX+TWO_PI); }