tick-based iteration
This commit is contained in:
parent
6bf157bd32
commit
5e87ba9380
1 changed files with 12 additions and 7 deletions
13
island.ts
13
island.ts
|
@ -103,15 +103,20 @@ export function IslandApplet() {
|
||||||
cx.scale(BLOWUP, BLOWUP);
|
cx.scale(BLOWUP, BLOWUP);
|
||||||
|
|
||||||
const islands = new IslandGrid(WIDTH, HEIGHT, 128);
|
const islands = new IslandGrid(WIDTH, HEIGHT, 128);
|
||||||
const x = islands.rng();
|
|
||||||
const y = islands.rng();
|
|
||||||
|
|
||||||
islands.set(x, y, 1);
|
function tick() {
|
||||||
|
const pos = islands.rng() % islands.data.length;
|
||||||
|
|
||||||
islands
|
islands
|
||||||
.floodSearch(islands.xy(x, y), (tile) => tile > 0)
|
.floodSearch(pos, (tile) => tile > 0)
|
||||||
.forEach((pos) => islands.data[pos]++);
|
.forEach((pos) => islands.data[pos]++);
|
||||||
|
|
||||||
renderIslands(islands, cx);
|
renderIslands(islands, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
tick();
|
||||||
|
|
||||||
|
setInterval(tick, 1000 / 10);
|
||||||
|
|
||||||
return [canvas];
|
return [canvas];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue