Added seed

This commit is contained in:
klangner 2020-10-15 22:24:14 +02:00
parent 4b8bb89110
commit bd7b12e57d
2 changed files with 14 additions and 6 deletions

View File

@ -42,6 +42,7 @@
<a class="dropdown-item" id="random-option">Random Generator</a>
</div>
</li>
<input class="form-control mr-sm-2" id="seed" type="search" placeholder="Seed" aria-label="Seed">
</ul>
</div>
</nav>

View File

@ -19,34 +19,41 @@ canvas.width = (CELL_SIZE + 1) * width + 1;
const ctx = canvas.getContext('2d');
function get_seed() {
var seed_text = document.getElementById("seed").value;
if( seed_text.length > 0) {
return Number(seed_text);
}
return Date.now();
}
// Map generators
function newCellularAutomata() {
var seed = Date.now();
world = World.new_cellular_automata(width, height, seed);
world = World.new_cellular_automata(width, height, get_seed());
requestAnimationFrame(renderLoop);
}
function newSimpleRooms() {
var seed = Date.now();
world = World.new_simple_rooms(width, height, seed);
world = World.new_simple_rooms(width, height, get_seed());
requestAnimationFrame(renderLoop);
}
function newBspInterior() {
var seed = Date.now();
world = World.new_bsp_interior(width, height, seed);
world = World.new_bsp_interior(width, height, get_seed());
requestAnimationFrame(renderLoop);
}
function newDrunkard() {
var seed = Date.now();
world = World.new_drunkard(width, height, seed);
world = World.new_drunkard(width, height, get_seed());
requestAnimationFrame(renderLoop);
}
function newRandomGen() {
var seed = Date.now();
world = World.new_random(width, height, seed);
world = World.new_random(width, height, get_seed());
requestAnimationFrame(renderLoop);
}