Advertisement
mattjeanes

Untitled

Jan 6th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. class Grid {
  2.  
  3. int w = 8;
  4. int columns, rows;
  5. int water = 60;
  6. float c;
  7. float[][] room;
  8. Square[] boxes = {
  9. //x, y,(where) w, h, (size). Append because "box" only contains 3 variables, need 4.
  10. new Square(0,1,5,80),
  11. new Square(25,64,8,4),
  12. new Square(5,1,4,17),
  13. new Square(25,68,21,13),
  14. new Square(9,1,12,12),
  15. new Square(5,55,3,26),
  16. new Square(21,1,5,8),
  17. new Square(27,62,3,2),
  18. new Square(39,1,42,28),
  19. new Square(26,56,2,6),
  20. new Square(44,12,37,28),
  21. new Square(27,54,2,2),
  22. new Square(36,15,3,13),
  23. new Square(26,1,3,3),
  24. new Square(71,1,10,80),
  25. new Square(42,36,3,4),
  26. new Square(68,54,3,7),
  27. new Square(46,78,25,3),
  28. new Square(65,64,6,5),
  29. new Square(68,69,3,4),
  30. new Square(64,73,7,5),
  31. new Square(51,70,4,2),
  32. new Square(35,37,3,3),
  33. new Square(46,63,10,7),
  34. new Square(35,40,18,7),
  35. new Square(43,59,3,9),
  36. new Square(53,40,6,4),
  37. new Square(41,53,7,6),
  38. new Square(32,47,14,6),
  39. new Square(29,51,3,3)
  40. };
  41.  
  42. Grid() {
  43. columns = width/w;
  44. rows = height/w;
  45. room = new float[columns][rows];
  46. init();
  47. }
  48. //this maps out the placement of watercells
  49. void init() {
  50. for (int i =0; i < columns; i++) {
  51. for (int j =0; j < rows; j++) {
  52. room[i][j] = 0;
  53. }
  54. }
  55. }
  56.  
  57. void initBoundary() {
  58. for (int i =0; i < columns; i++) {
  59. room[i][0]=1.0;
  60. }
  61.  
  62. for (int i = 0; i < boxes.length; i++) {
  63. for (int j =boxes[i].x; j < boxes[i].w+boxes[i].x; j++) {
  64. for (int k =boxes[i].y; k < boxes[i].h+boxes[i].y; k++){
  65. room[j][k] = 1;
  66. }
  67. }
  68. }
  69. }
  70.  
  71. void generate() {
  72. float[][] next = new float[columns][rows];
  73. for (int x = 1; x < columns-1; x++) {
  74. for (int y = 1; y < rows-1; y++) {
  75. float neighbors = 0;
  76. for (int i = -1; i <= 1; i++) {
  77. for (int j = -1; j <= 1; j++) {
  78. neighbors += room[x+i][y+j];
  79. next[x][y] = neighbors/9.0;
  80. }
  81. }
  82. }
  83. }
  84. room = next;
  85. initBoundary();
  86. }
  87.  
  88. void display() {
  89. for ( int i = 0; i < columns; i++) {
  90. for ( int j = 0; j < rows; j++) {
  91. c = map(room[i][j],0, 2, 0, 255); //sets the color of cells from their values
  92. fill(0 , water, c);
  93. rect(i*w, j*w, w, w);
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement