diff --git a/dist/index.html b/dist/index.html
index 99fba39..d698074 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -35,6 +35,8 @@
+
+
diff --git a/src/Controllers/ControlPanel.js b/src/Controllers/ControlPanel.js
index 5396a9e..fcbe8b3 100644
--- a/src/Controllers/ControlPanel.js
+++ b/src/Controllers/ControlPanel.js
@@ -327,6 +327,9 @@ class ControlPanel {
env.auto_reset = false;
$('#auto-reset').prop('checked', false);;
});
+ $('#random-walls').click( function() {
+ this.env_controller.randomizeWalls();
+ }.bind(this));
$('#auto-reset').change(function() {
env.auto_reset = this.checked;
});
diff --git a/src/Controllers/EnvironmentController.js b/src/Controllers/EnvironmentController.js
index 828fe08..2eeb27c 100644
--- a/src/Controllers/EnvironmentController.js
+++ b/src/Controllers/EnvironmentController.js
@@ -51,6 +51,26 @@ class EnvironmentController extends CanvasController{
this.scale = 1;
}
+ /*
+ Iterate over grid from 0,0 to env.num_cols,env.num_rows and create random walls using perlin noise to create a more organic shape.
+ */
+ randomizeWalls(thickness=1) {
+ var noise_scale = 0.05;
+ var noise_offset = 0.5;
+ var noise_threshold = 0.5;
+ var noise_multiplier = 0.5;
+ var noise_offset_x = this.env.num_cols/2;
+ var noise_offset_y = this.env.num_rows/2;
+ for (var r = 0; r < this.env.num_rows; r++) {
+ for (var c = 0; c < this.env.num_cols; c++) {
+ var noise = noise_multiplier * noise_offset + noise_scale * noise_offset * Math.sin(noise_scale * (c + noise_offset_x) + noise_scale * (r + noise_offset_y));
+ if (noise > noise_threshold && noise < noise_threshold + thickness/10) {
+ this.dropCellType(c, r, CellStates.wall, true);
+ }
+ }
+ }
+ }
+
updateMouseLocation(offsetX, offsetY){
super.updateMouseLocation(offsetX, offsetY);
diff --git a/src/Environments/WorldEnvironment.js b/src/Environments/WorldEnvironment.js
index 1da6c73..039fcad 100644
--- a/src/Environments/WorldEnvironment.js
+++ b/src/Environments/WorldEnvironment.js
@@ -12,9 +12,9 @@ class WorldEnvironment extends Environment{
super();
this.renderer = new Renderer('env-canvas', 'env', cell_size);
this.controller = new EnvironmentController(this, this.renderer.canvas);
- var grid_rows = Math.ceil(this.renderer.height / cell_size);
- var grid_cols = Math.ceil(this.renderer.width / cell_size);
- this.grid_map = new GridMap(grid_cols, grid_rows, cell_size);
+ this.num_rows = Math.ceil(this.renderer.height / cell_size);
+ this.num_cols = Math.ceil(this.renderer.width / cell_size);
+ this.grid_map = new GridMap(num_cols, num_rows, cell_size);
this.organisms = [];
this.walls = [];
this.total_mutability = 0;