Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including node-image-terrain-array with all npm packages installed. Try it out:

var nodeImageTerrainArray = require("node-image-terrain-array")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

node-image-terrain-array v1.0.6

Generates a HSV array from a Buffer of a PNG image

Node Image to Terrain Array by Box It Off

Input - png buffer, number of columns

Output - array of average hsv values for each hexagon, array of centre points of hexagons, hexagon radius, number of rows


This is a module for a bigger project. It is self contained and will output to a file in the output folder. On its own it is not very useful but watch this space :)


Turn this -

An image of part of the world

Into this -

[{ h: 91, s: 55, v: 21 }, {....}, .....], [[ 9.804061174918171, 16.9811320754717 ], [ ....... ], ......], 11.320754716981131


getTerrain(imageFile, cols, rows)

Further Development

  • output code for rendering map
  • command line inputs
  • Browser gui


  • [x] get image width and height
  • [x] get hex radius
  • [x] get center point of each hex
  • [x] get pixel sample (array->rgba values) function
  • [x] get average colour(array->rgb) of each sample
  • [x] get hsv(array) values from rgb averages
  • [x] return array of hsv values, array of hex centre points, hex radius
  • [x] clean up code :)
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free