Skip to content

Instantly share code, notes, and snippets.

@Fasteroid
Last active July 21, 2026 14:40
Show Gist options
  • Select an option

  • Save Fasteroid/696dc8156eb25d29d369932333340f5d to your computer and use it in GitHub Desktop.

Select an option

Save Fasteroid/696dc8156eb25d29d369932333340f5d to your computer and use it in GitHub Desktop.
let color = 0;
const mins = {x: Infinity, y: Infinity};
const maxs = {x: -Infinity, y: -Infinity};
for( let tile of n.tiles ){
for( let x of tile.pixels.x ) {
mins.x = Math.min(mins.x, tile.x * 1000 + x);
maxs.x = Math.max(maxs.x, tile.x * 1000 + x);
}
for( let y of tile.pixels.y ) {
mins.y = Math.min(mins.y, tile.y * 1000 + y);
maxs.y = Math.max(maxs.y, tile.y * 1000 + y);
}
color = tile.pixels.colors[0];
}
maxs.x += 1;
maxs.y += 1;
const coords = [];
for(let x = mins.x; x < maxs.x; x++){
for(let y = mins.y; y < maxs.y; y++){
coords.push([x, y])
}
}
console.log(coords);
const tiles = new Map();
for( let [x, y] of coords ){
const tx = Math.floor(x * 0.001);
const ty = Math.floor(y * 0.001);
let tile;
if( !tiles.has(`${tx},${ty}`) ){
tile = {
x: tx,
y: ty,
pixels: {
x: [],
y: [],
colors: []
}
};
tiles.set(`${tx},${ty}`, tile);
}
tile ??= tiles.get(`${tx},${ty}`);
tile.pixels.x.push(x % 1000);
tile.pixels.y.push(y % 1000);
tile.pixels.colors.push(color);
}
n.tiles = [...tiles.values()];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment