Randomly plot a tile
This commit is contained in:
parent
ad89545326
commit
92917be9f7
1 changed files with 10 additions and 7 deletions
17
island.ts
17
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];
|
||||
|
|
Loading…
Add table
Reference in a new issue