Convert an image to use as a map
the Vectorize
constructor takes in an image name like so:
let vec = new Vectorize("my_map.png")
Outputs array like output.png
Vectorize
stores an image in an image instance, draws it to a hidden canvas, gets the rgba values of each pixel, determines black or white, then adds that to an array before converting it to a 2d array to return as the final result.
- create image instance from image name provided
- draw to canvas
- get pixel data from canvas
- sort into black or white array
- collapse pixels into array of 1 (white) or 0 (black)
- build 2D array
- return
The optional draw function takes a number used for scaling. if no argument is provided, 1 will be used.
vec.draw(1)
// is equal to
vec.draw()
s
// draw at 2x
vec.draw(2)