Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Grid {
- int w = 8;
- int columns, rows;
- int water = 60;
- float c;
- float[][] room;
- Square[] boxes = {
- //x, y,(where) w, h, (size). Append because "box" only contains 3 variables, need 4.
- new Square(0,1,5,80),
- new Square(25,64,8,4),
- new Square(5,1,4,17),
- new Square(25,68,21,13),
- new Square(9,1,12,12),
- new Square(5,55,3,26),
- new Square(21,1,5,8),
- new Square(27,62,3,2),
- new Square(39,1,42,28),
- new Square(26,56,2,6),
- new Square(44,12,37,28),
- new Square(27,54,2,2),
- new Square(36,15,3,13),
- new Square(26,1,3,3),
- new Square(71,1,10,80),
- new Square(42,36,3,4),
- new Square(68,54,3,7),
- new Square(46,78,25,3),
- new Square(65,64,6,5),
- new Square(68,69,3,4),
- new Square(64,73,7,5),
- new Square(51,70,4,2),
- new Square(35,37,3,3),
- new Square(46,63,10,7),
- new Square(35,40,18,7),
- new Square(43,59,3,9),
- new Square(53,40,6,4),
- new Square(41,53,7,6),
- new Square(32,47,14,6),
- new Square(29,51,3,3)
- };
- Grid() {
- columns = width/w;
- rows = height/w;
- room = new float[columns][rows];
- init();
- }
- //this maps out the placement of watercells
- void init() {
- for (int i =0; i < columns; i++) {
- for (int j =0; j < rows; j++) {
- room[i][j] = 0;
- }
- }
- }
- void initBoundary() {
- for (int i =0; i < columns; i++) {
- room[i][0]=1.0;
- }
- for (int i = 0; i < boxes.length; i++) {
- for (int j =boxes[i].x; j < boxes[i].w+boxes[i].x; j++) {
- for (int k =boxes[i].y; k < boxes[i].h+boxes[i].y; k++){
- room[j][k] = 1;
- }
- }
- }
- }
- void generate() {
- float[][] next = new float[columns][rows];
- for (int x = 1; x < columns-1; x++) {
- for (int y = 1; y < rows-1; y++) {
- float neighbors = 0;
- for (int i = -1; i <= 1; i++) {
- for (int j = -1; j <= 1; j++) {
- neighbors += room[x+i][y+j];
- next[x][y] = neighbors/9.0;
- }
- }
- }
- }
- room = next;
- initBoundary();
- }
- void display() {
- for ( int i = 0; i < columns; i++) {
- for ( int j = 0; j < rows; j++) {
- c = map(room[i][j],0, 2, 0, 255); //sets the color of cells from their values
- fill(0 , water, c);
- rect(i*w, j*w, w, w);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement