Randomly plot a tile

This commit is contained in:
Tangent Wantwight 2024-01-12 21:36:45 -05:00
parent ad89545326
commit 92917be9f7

View file

@ -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];