aboutsummaryrefslogtreecommitdiff
path: root/utils/raster.js
blob: c1a204be959492bd6fc2bba8eaa041bbecc6c53b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Takes a space object and 'rasterizes' it into an object mapping of 8x16 tiles which may not be filled with empty space

const ms = require('./measurespace');
const vec = require('./vec');

module.exports = function(space){
  // just use .subsection
  let tiles = {};
  let dim = ms(space).map(coord => vec.charToTile(coord));
  for (let y=dim[0][0]; y<=dim[0][1]; y++) for (let x=dim[1][0]; x<=dim[1][1]; x++){
    let tile = tileToChar([y,x]);
    tiles[tile] = space.subsection(tile, vec.add(tile, [8,16]));
  }
  return tiles
}