/* * GoLfacade * * Diplomwahlfacharbeit CAAD | ETH Zuerich * Florian Poppele * * 31.01.2008 * * desc: * */ /*///////////////////////////////////////////////////////////// // VARS // /////////////////////////////////////////////////////////////*/ //::: LIB IMPORT import processing.opengl.*; import processing.dxf.*; //::: PROGRAM Grid myGrid; // Grid that holds all cells int growSpeed = 10; // calculate next cell every x frames int fragSpeed = 70; // calculate growing fragmentation every x frames int growFrameCnt = 0; // count the frames int fragFrameCnt = 0; // count the frames //::: START VALUES float cellSize = 40; // size of one cell int cellsX = 50; // number of cells along the axis int cellsY = 20; int cellsZ = 15; int facDepth = 2; // thickness in modules of the facade int numBreederCells = 6; // number of breeding cells int numVoidCells = 15; // number of breeding cells float voidAggresiveness = .8; // probability of vertical void growth float xSize = cellsX * cellSize; // size of structure float ySize = cellsY * cellSize; float zSize = cellsZ * cellSize; //::: EVENTS boolean eExportDxf = false; // export dxf boolean ePaused = true; // ALT the game boolean eShowAxis = true; // show coord axis boolean eShowGrid = true; // show grid boolean ePauseGrow = false; // pause growing process //::: COLORS color cActive = color(0,255,0,80); color cVoid = color(255,0,0,50); color cGrey1 = color(80,80,80,80); color cGrey2 = color(170,170,170,20); ///::: FONTS PFont fTitle16; //::: CAMERA float clipping = 1.5*cellSize*(cellsX+cellsY+cellsZ)/3; float mouseFactor; /*///////////////////////////////////////////////////////////// // SETUP // /////////////////////////////////////////////////////////////*/ void setup() { size(600, 600, OPENGL); fTitle16 = loadFont("04b03-16.vlw"); noStroke(); initGrid(cellsX, cellsY, cellsZ, xSize, ySize, zSize, cellSize, facDepth); } /*///////////////////////////////////////////////////////////// // DRAW // /////////////////////////////////////////////////////////////*/ void draw() { lights(); background(255); //::: CAMERA SETTINGS float mouseFactor = 2*mouseY/float(height); ortho(-clipping*mouseFactor, clipping*mouseFactor, -clipping*mouseFactor, clipping*mouseFactor, -3000, 3000); translate(width/2, height*2/3, 0); rotateX(-PI/10); rotateY(PI/3 + mouseX/float(width) * 2*PI); // rotate y rotateX(PI/2); // correct processing coord system //::: UI 1/2 if (eShowAxis) showAxis(); if (eShowGrid) myGrid.showGrid(); //::: DRAW if (eExportDxf) // write to dxf if key pressed { beginRaw(DXF, "output.dxf"); println("dxf exported"); camera(); // reset cam perspective(); } //::: GROW if ((growFrameCnt == growSpeed) && !ePauseGrow) // grow only every growSpeed-frame { growFrameCnt = 0; myGrid.growCell(); } else // don't grow { growFrameCnt++; } if ((fragFrameCnt == fragSpeed) && !ePauseGrow) // growing fragmentation { fragFrameCnt = 0; myGrid.growVoid(); } else // don't grow fragmentation { fragFrameCnt++; } myGrid.drawMe(eShowGrid); //::: EXPORT, .... if (eExportDxf) // stop writing to dxf { endRaw(); eExportDxf = false; } //::: UI 2/2 progName(); } //::: INIT VALUES void initGrid(int gX, int gY, int gZ, float gsX, float gsY, float gsZ, float gSize, int gDepth) { myGrid = new Grid(gX, gY, gZ, gsX, gsY, gsZ, gSize, gDepth); // size of structure (x,y,z), size of cells, depth } //::: INPUT void keyPressed() { if (key == 'd') eExportDxf = true; // export next viewport frame to dxf else if (key == 'a') // show/hide axis { //println(eShowAxis); if (eShowAxis) eShowAxis = false; else eShowAxis = true; } else if (key == 'g') // show/hide grid { //println(eShowGrid); if (eShowGrid) eShowGrid = false; else eShowGrid = true; } else if (key == ' ') // start/pause growing { //println(ePauseGrow); if (ePauseGrow) { ePauseGrow = false; growFrameCnt = 0; fragFrameCnt = 0; } else ePauseGrow = true; } } //::: UI void showAxis() { stroke(255,0,0,70); line(0, 0, 0, width/2, 0, 0); // positive X (red) stroke(0,255,0,70); line(0, 0, 0, 0, height/2, 0); // positive Y (green) stroke(0,0,255,70); line(0, 0, 0, 0, 0, height/2); // positive Z (blue) } void progName() { textMode(SCREEN); textFont(fTitle16, 16); fill(160); textAlign(LEFT); text("GameOfLifeFacade", 10, height-5); }