I've been stuck on a Uint8Array for the last 24h, full disclosure I also happen to be high as a kite for just as long
I went to sleep last night, thinking about my array
function generateHeight( width, height ) {
let seed = Math.PI / 4;
window.Math.random = function () {
const x = Math.sin( seed ++ ) * 10000;
return x - Math.floor( x );
};
const size = width * height, data = new Uint8Array( size );
const perlin = new ImprovedNoise(), z = Math.random() * 100;
let quality = 1;
for ( let j = 0; j < 4; j ++ ) {
for ( let i = 0; i < size; i ++ ) {
let x = i % width, y = ~ ~ ( i / width );
data[ i ] += Math.abs( perlin.noise( x / quality, y / quality, z ) * quality * 1.75 )
}
quality *= 5
}
return data;
}
It generates a heightmap, and I want a seemless loop of it, like I don't have to rotate and scaleXY/mirror clones of the original map to be able to stack them side by side, for an infinite traveling loop effect in every possible direction
So the idea is to copy the upper part of the map, tile by tile, and reverse paste it, in place of the bottom part of the map, so it produces a vertical simmetry/mirror effect, and then do the same with the left side of the map/array
...
I thought of that evidently
for ( let j = 0; j < 4; j ++ ) {
for ( let i = 0; i < size; i ++ ) {
data[ i ] = data[ size - i ]
}
}
But nope, it would have been too easy... So it's going to be mind game fun now
(post is archived)