From 590edcd7419963cfe870eb639538cd6a918dd3cf Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Wed, 8 Jan 2020 17:44:51 -0500 Subject: added rasterization for space -> tile transform --- utils/raster.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 utils/raster.js (limited to 'utils') diff --git a/utils/raster.js b/utils/raster.js new file mode 100644 index 0000000..44f4678 --- /dev/null +++ b/utils/raster.js @@ -0,0 +1,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 = {}; + dim = ms(space).map(coord => vec.dot(coord,[1/8, 1/16])).map(tile => vec.elem(tile, [], a => Math.floor(a))); + 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 +} -- cgit