Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Cell[][] _cellArray;
  2. int _cellSize = 10;
  3. int _numX, _numY;
  4. float state;
  5. void setup() {
  6. size(500, 300);
  7. _numX = floor(width/_cellSize);
  8. _numY = floor(height/_cellSize);
  9. restart();
  10. }
  11. void restart() {
  12.  
  13.  
  14. }
  15. void draw() {
  16.  
  17. background(200);
  18.  
  19. state=random(2);
  20. _cellArray = new Cell[_numX][_numY];
  21. for (int x=0; x<_numX;x++){
  22. for(int y=0; y<_numY;y++){
  23. Cell newCell = new Cell(x,y,state);
  24. _cellArray[x][y]=newCell;
  25. }
  26. }
  27. translate(_cellSize/2, _cellSize/2);
  28. for (int x=0; x<_numX;x++){
  29. for (int y=0; y<_numY; y++){
  30. _cellArray[x][y].drawMe();
  31. }
  32. }
  33. }
  34. void mousePressed(){
  35. restart();
  36. }
  37. class Cell{
  38. float x, y;
  39. boolean state;
  40. boolean nextState;
  41. Cell(float ex, float why, float s) {
  42. x = ex * _cellSize;
  43. y = why * _cellSize;
  44. if(s>1){
  45. nextState = true;
  46.  
  47. } else {
  48. nextState = false;
  49. }
  50. state = nextState;
  51. }
  52.  
  53. void drawMe() {
  54. state = nextState;
  55. stroke(0);
  56. if (state == true) {
  57. fill(0);
  58. } else {
  59. fill(255);
  60. }
  61. ellipse(x, y, _cellSize, _cellSize);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement