From 5e87ba9380ffe960a285e10d8423f6b6e993001a Mon Sep 17 00:00:00 2001
From: Tangent Wantwight <tangent128@gmail.com>
Date: Fri, 12 Jan 2024 22:31:48 -0500
Subject: [PATCH] tick-based iteration

---
 island.ts | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/island.ts b/island.ts
index bf03ab1..a15b2bb 100644
--- a/island.ts
+++ b/island.ts
@@ -103,15 +103,20 @@ export function IslandApplet() {
   cx.scale(BLOWUP, BLOWUP);
 
   const islands = new IslandGrid(WIDTH, HEIGHT, 128);
-  const x = islands.rng();
-  const y = islands.rng();
 
-  islands.set(x, y, 1);
-  islands
-    .floodSearch(islands.xy(x, y), (tile) => tile > 0)
-    .forEach((pos) => islands.data[pos]++);
+  function tick() {
+    const pos = islands.rng() % islands.data.length;
 
-  renderIslands(islands, cx);
+    islands
+      .floodSearch(pos, (tile) => tile > 0)
+      .forEach((pos) => islands.data[pos]++);
+
+    renderIslands(islands, cx);
+  }
+
+  tick();
+
+  setInterval(tick, 1000 / 10);
 
   return [canvas];
 }