Pick random tile in floodsearch to elevate

This commit is contained in:
Tangent Wantwight 2024-01-12 22:39:23 -05:00
parent 5e87ba9380
commit 3b701019cc

View file

@ -1,9 +1,9 @@
import { canvas2d } from "./lib/html";
import { Prng, mulberry32 } from "./lib/prng";
const BLOWUP = 4;
const WIDTH = 240;
const HEIGHT = 135;
const BLOWUP = 4 * 5;
const WIDTH = 240 / 5;
const HEIGHT = 135 / 5;
type Lookup2d = (x: number, y: number) => number;
function dim(width: number, height: number): Lookup2d {
@ -104,12 +104,14 @@ export function IslandApplet() {
const islands = new IslandGrid(WIDTH, HEIGHT, 128);
function tick() {
const pos = islands.rng() % islands.data.length;
const basePos = islands.data.length >> 1;
islands
.floodSearch(pos, (tile) => tile > 0)
.forEach((pos) => islands.data[pos]++);
function tick() {
const islandTiles = islands.floodSearch(basePos, (tile) => tile > 0);
const pos = islandTiles[islands.rng() % islandTiles.length];
islands.data[pos]++;
renderIslands(islands, cx);
}