Add Parameters for Dispersal and Amount of Cells

This commit is contained in:
Marty Oehme 2018-07-07 20:47:23 +02:00
parent 9816778d4b
commit 4b35dbe5fc

View file

@ -25,7 +25,7 @@ class Grid {
print("Grid creation finished"); print("Grid creation finished");
} }
void startingPattern({Pattern pattern, int x, int y}) { void startingPattern({Pattern pattern, int x, int y, int amount, int dispersal}) {
math.Random rng = new math.Random(); math.Random rng = new math.Random();
int cx = x ?? rng.nextInt(w~/3) + (w~/3); int cx = x ?? rng.nextInt(w~/3) + (w~/3);
int cy = y ?? rng.nextInt(h~/3) + (h~/3); int cy = y ?? rng.nextInt(h~/3) + (h~/3);
@ -56,8 +56,8 @@ class Grid {
setCellState(0 + cx, 2 + cy, true); setCellState(0 + cx, 2 + cy, true);
break; break;
default: default:
for (var i = 0; i < rng.nextInt(20); i++) { for (var i = 0; i < amount ?? rng.nextInt(20); i++) {
setCellState(cx + rng.nextInt(10), cy + rng.nextInt(10), true); setCellState(cx + dispersal ?? rng.nextInt(10), cy + dispersal ?? rng.nextInt(10), true);
} }
break; break;
} }