MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / cloud

Function cloud

data/scripts/examples/Heightmap.js:43–79  ·  view source on GitHub ↗
(X, Y, W, H, seed)

Source from the content-addressed store, hash-verified

41}
42
43function cloud(X, Y, W, H, seed) {
44 seed = seed|0;
45 let data = noise(X, Y, W, H, seed);
46 X = (X ^ seed) * W | 0;
47 Y = (Y ^ seed) * H | 0;
48 for (let l = 1; l < 8; ++l) {
49 let L = 1 << l;
50 for (let y = 0; y < H; y += L) {
51 for (let x = 0; x < W; x += L) {
52 let A = rng(x, y) * L;
53 let B = rng(x + L, y) * L;
54 let C = rng(x, y + L) * L;
55 let D = rng(x + L, y + L) * L;
56 for (let iy = 0; iy < L; ++iy) {
57 let w = iy / L;
58 let AC = A * (1 - w) + C * w;
59 let BD = B * (1 - w) + D * w;
60 for (let ix = 0; ix < L; ++ix) {
61 w = ix / L;
62 let ACBD = AC * (1 - w) + BD * w;
63 data[(y + iy) * W + (x + ix)] += ACBD;
64 }
65 }
66
67 }
68 }
69 }
70
71 for (let l = 0; l < W*H; ++l)
72 data[l] /= 255;
73
74 return data;
75
76 function rng(x, y) {
77 return (((((X + x) * 1991 ^ (Y + y) * 2731) * seed) >>> 0) & 0xFFFF) / 0xFFFF;
78 }
79}
80
81function rain(heightmap, W, H, seed, cycles) {
82 seed = seed|0;

Callers 1

terrainFunction · 0.85

Calls 2

noiseFunction · 0.85
rngFunction · 0.85

Tested by

no test coverage detected