/* * CELL CLASS * desc: handles all cell properties * */ class Cell { int xPos, yPos, zPos; // position of the center of the cell int xIndex, yIndex, zIndex; // index of the cell, related to the grid int xDir, yDir, zDir; // orientation of the module float cellSize; boolean cellStructure; // if cell is part of the structure boolean cellActive; // if cell is filled wih a module boolean cellVoid; // if the cell is a void boolean cellBreeding; // if cell is not yet activated Cell(int x, int y, int z, int xInd, int yInd, int zInd, float cellSize, boolean cellStructure, boolean cellActive) { this.xPos = x; this.yPos = y; this.zPos = z; this.xIndex = xInd; this.yIndex = yInd; this.zIndex = zInd; this.cellSize = cellSize; this.cellStructure = cellStructure; this.cellActive = cellActive; this.cellBreeding = false; // breeding is used after grow cycles this.cellVoid = false; // start every cell as a solid //allow all directions here; nonsense will be corrected in the 1st round if (int(random(2)) == 0) { xDir = 1; } // random direction x else { xDir = -1; } if (int(random(2)) == 0) { yDir = 1; } // random direction y else { yDir = -1; } if (int(random(2)) == 0) { zDir = 1; } // random direction z else { zDir = -1; } } void drawMe(boolean boxOutline) { //noStroke(); noFill(); stroke(200,200,200,50); pushMatrix(); translate(xPos, yPos, zPos); if (boxOutline) box(cellSize, cellSize, cellSize); drawModule(0, 0, 0, cellSize*xDir, cellSize*yDir, cellSize*zDir, cellActive, boxOutline); popMatrix(); } //:: drawModule // draws the base Module with the passed orientation void drawModule(float x, float y, float z, float xL, float yL, float zL, boolean isActive, boolean boxOutline) { float thickness = 3; stroke(255,0,0); noStroke(); if (cellVoid && cellActive) { this.setActive(false); } if (cellActive) { fill(cActive); pushMatrix(); // X (red) // translating by difference of cellWidth - thickness/2; box() draws from center translate(0, yL/abs(yL)*(abs(yL/2)-thickness/2), zL/abs(zL)*(abs(zL/2)-thickness/2)); box(abs(xL), thickness, thickness); popMatrix(); stroke(0,255,0); noStroke(); pushMatrix(); // Y (green) translate(xL/abs(xL)*(abs(xL/2)-thickness/2), 0, zL/abs(zL)*(abs(zL/2)-thickness/2)); box(thickness, abs(yL), thickness); popMatrix(); stroke(0,0,255); noStroke(); pushMatrix(); // Y (blue) translate(xL/abs(xL)*(abs(xL/2)-thickness/2), yL/abs(yL)*(abs(yL/2)-thickness/2), 0); box(thickness, thickness, abs(zL)); popMatrix(); } if (cellVoid && boxOutline) { fill(cVoid); box(cellSize, cellSize, cellSize); } } boolean isStructure() { return cellStructure; } boolean isActive() { return cellActive; } void setActive(boolean state) { if (cellBreeding) cellBreeding = false; cellActive = state; } void setVoid(boolean state) { cellVoid = state; } boolean isVoid() { return cellVoid; } void setBreeding() { cellBreeding = true; } boolean isBreeding() { return cellBreeding; } int getXind() { return this.xIndex; } int getYind() { return this.yIndex; } int getZind() { return this.zIndex; } }