class Citizen { int x, y; float xPos, yPos; color c, tempC; boolean [] linkArray = new boolean[numCitizens]; // records links with all other citizens int linkCount; Citizen (int _x, int _y, color _c) { x = _x; y = _y; c = _c; xPos = 150 + ((x % squareEdge) * squareSize) + (squareSize/2); yPos = 50 + ((y % squareEdge) * squareSize) + (squareSize/2); tempC = 255; for (int i = 0; i < numCitizens; i++) { linkArray[i] = false; linkCount = 0; } } void drawCitizen() { stroke(0); strokeWeight(1); fill(c); ellipse(xPos, yPos, circleSize, circleSize); } void moveCitizen() { int r = int(random(3)); if (r == 0) { if (x >= squareEdge-1) { x = 0; } else { x = x + 1; } } else if (r == 1) { if (y >= squareEdge-1) { y = 0; } else { y = y + 1; } } else if (r == 2) { if (x <= 0) { x = squareEdge-1; } else { x = x - 1; } } else if (r == 3) { if (y <= 0) { y = squareEdge-1; } else { y = y - 1; } } xPos = 150 + ((x % squareEdge) * squareSize) + (squareSize/2); yPos = 50 + ((y % squareEdge) * squareSize) + (squareSize/2); } // void changeColor() { // float r = red(c); // float g = green(c); // float b = blue(c); // for (int i = 0; i < squareEdge; i++) { // for (int j = 0; j < squareEdge; j++) { // if (gridSquares[i][j].x == x && gridSquares[i][j].y == y) { // if (red(gridSquares[i][j].c) > red(c)) { // r = red(gridSquares[i][j].c); // } // if (green(gridSquares[i][j].c) > green(c)) { // g = green(gridSquares[i][j].c); // } // if (blue(gridSquares[i][j].c) > blue(c)) { // b = blue(gridSquares[i][j].c); // } // c = color(r, g, b); // } // } // } // } // void changeColor() { // for (int i = 0; i < squareEdge; i++) { // for (int j = 0; j < squareEdge; j++) { // if (gridSquares[i][j].x == x && gridSquares[i][j].y == y) { // if (gridSquares[i][j].c == 255) { // c = color(0); // } // else { // c = color(255); // } // } // } // } // } void switchColor() { tempC = c; c = gridSquares[x][y].c; gridSquares[x][y].c = tempC; tempC = 255; } void setColor() { for (int i = 0; i < squareEdge; i++) { for (int j = 0; j < squareEdge; j++) { if (gridSquares[i][j].x == x && gridSquares[i][j].y == y) { tempC = gridSquares[i][j].c; } } } } void changeColor() { c = tempC; } void forgeLink() { for (int i = 0; i < numCitizens; i++) { if (x == citizens[i].x+1 && y == citizens[i].y) { linkArray[i] = true; } else if (y == citizens[i].y+1 && x == citizens[i].x) { linkArray[i] = true; } else if (x == citizens[i].x-1 && y == citizens[i].y) { linkArray[i] = true; } else if (y == citizens[i].y-1 && x == citizens[i].x) { linkArray[i] = true; } } } void drawLink() { stroke(0); strokeWeight(1); for (int i = 0; i < numCitizens; i++) { if (linkArray[i]) { line(xPos, yPos, citizens[i].xPos, citizens[i].yPos); } } } void countLinks() { linkCount = 0; for (int i = 0; i < numCitizens; i++) { if (linkArray[i]) { linkCount++; } } } }