Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cell[][] _cellArray;
- int _cellSize = 10;
- int _numX, _numY;
- float state;
- void setup() {
- size(500, 300);
- _numX = floor(width/_cellSize);
- _numY = floor(height/_cellSize);
- restart();
- }
- void restart() {
- }
- void draw() {
- background(200);
- state=random(2);
- _cellArray = new Cell[_numX][_numY];
- for (int x=0; x<_numX;x++){
- for(int y=0; y<_numY;y++){
- Cell newCell = new Cell(x,y,state);
- _cellArray[x][y]=newCell;
- }
- }
- translate(_cellSize/2, _cellSize/2);
- for (int x=0; x<_numX;x++){
- for (int y=0; y<_numY; y++){
- _cellArray[x][y].drawMe();
- }
- }
- }
- void mousePressed(){
- restart();
- }
- class Cell{
- float x, y;
- boolean state;
- boolean nextState;
- Cell(float ex, float why, float s) {
- x = ex * _cellSize;
- y = why * _cellSize;
- if(s>1){
- nextState = true;
- } else {
- nextState = false;
- }
- state = nextState;
- }
- void drawMe() {
- state = nextState;
- stroke(0);
- if (state == true) {
- fill(0);
- } else {
- fill(255);
- }
- ellipse(x, y, _cellSize, _cellSize);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement