Skip to content

Instantly share code, notes, and snippets.

@hughsk
Last active December 21, 2015 00:09
Show Gist options
  • Save hughsk/6218503 to your computer and use it in GitHub Desktop.
Save hughsk/6218503 to your computer and use it in GitHub Desktop.
var perlin = require('perlin').noise.perlin3
var fill = require('ndarray-fill')
var zeros = require('zeros')
var scale = 0.075
var threshold = 0.125
// Untested in 3D, but "theoretically" this should
// work. Using the equivalent 2d getter with the
// continuous-box2d demo works well.
var field = require('ndarray-continuous')({
shape: [32, 32, 32],
getter: function(position, done) {
var shape = this.shape
var array = zeros(shape)
fill(array, function(x, y, z) {
return perlin(
(position[0] * shape[0] + x) * scale
, (position[1] * shape[1] + y) * scale
, (position[2] * shape[2] + z) * scale
) > threshold ? 0 : 1
})
return done(null, array)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment