libnoise

0.2.1 • Public • Published

Libnoise

This is a haxe port of libnoise, the coherent noise library. The port is almost complete, only the gradient and noise2D utilities are missing.

Examples usages in the test folder, require the format library to generate images.

JS Example

var ctx = document
    .querySelector('#c')
    .getContext('2d');
 
//enums are a bit weird in js, so you have to use the actual reference, instead of an int.
var quality = libnoise.QualityMode.MEDIUM;
var noise = new libnoise.generator.Perlin(.01, 2.0, 0.5, 8, 42, quality);
 
var size = 512;
var img = ctx.createImageData(size, size);
 
function getColor(val) {
    var color = (128 * ((val + 1)));
    return color > 255 ? 255 : color < 0 ? 0 : color;
}
 
var z = 0;
 
for (var i = 0; i < size * size * 4; i += 4) {
 
    var x = (/ 4) % size; //Math.floor(i / width);
    var y = Math.floor((/ 4) / size); //i % height;:w
 
    var val = noise.getValue(x, y, z);
 
    var color = getColor(val);
 
    //console.log('pixel at: ', x ,y, val, color);
    //r
    img.data[i] = color;
    //g
    img.data[+ 1] = color;
    //b
    img.data[+ 2] = color;
    //a
    img.data[+ 3] = 255;
}
 
ctx.putImageData(img, 0, 0);

License

This port is released under the LGPL licence, see LICENSE and LICENSE.lesser for details.

About

Libnoise was originaly created by Jason Bevins. The library was later ported to Xna by Marc André Ueberall, and moved to Unity by Tim Speltz. This haxe version was mainly ported with Libnoise.unity as reference.

Package Sidebar

Install

npm i libnoise

Weekly Downloads

0

Version

0.2.1

License

none

Last publish

Collaborators

  • vantreeseba