From 92917be9f7b7fbbc05c5953d95bc9b9be66b9485 Mon Sep 17 00:00:00 2001
From: Tangent Wantwight <tangent128@gmail.com>
Date: Fri, 12 Jan 2024 21:36:45 -0500
Subject: [PATCH] Randomly plot a tile

---
 island.ts | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/island.ts b/island.ts
index 983d394..c140b4b 100644
--- a/island.ts
+++ b/island.ts
@@ -1,4 +1,5 @@
 import { canvas2d } from "./lib/html";
+import { Prng, mulberry32 } from "./lib/prng";
 
 const BLOWUP = 4;
 const WIDTH = 240;
@@ -16,10 +17,13 @@ function dim(width: number, height: number): Lookup2d {
 
 class IslandGrid {
   data: number[];
+  rng: Prng;
+
   xy: Lookup2d;
 
-  constructor(public width: number, public height: number) {
+  constructor(public width: number, public height: number, seed: number) {
     this.data = Array(width * height).fill(0);
+    this.rng = mulberry32(seed);
     this.xy = dim(width, height);
   }
 
@@ -66,13 +70,12 @@ export function IslandApplet() {
   });
   cx.scale(BLOWUP, BLOWUP);
 
-  const islands = new IslandGrid(WIDTH, HEIGHT);
+  const islands = new IslandGrid(WIDTH, HEIGHT, 128);
+  const x = islands.rng();
+  const y = islands.rng();
+
+  islands.set(x, y, 1);
 
-  islands.data[islands.xy(5, 5)] = 1;
-  islands.data[islands.xy(6, 5)] = 2;
-  islands.data[islands.xy(7, 5)] = 3;
-  islands.data[islands.xy(8, 5)] = 4;
-  islands.data[islands.xy(9, 5)] = 5;
   renderIslands(islands, cx);
 
   return [canvas];