Organic looking random walls using noise start
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user