Skip to content

Instantly share code, notes, and snippets.

@zz85
Created November 26, 2011 07:13
Show Gist options
  • Save zz85/1395215 to your computer and use it in GitHub Desktop.
Save zz85/1395215 to your computer and use it in GitHub Desktop.
Testing Creation of Simplex Noise Textures
function createNoiseTexture(width, height) {
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var context = canvas.getContext('2d');
var image = context.createImageData( width, height );
var imageData = image.data;
var simplex = new SimplexNoise();
var now = Date.now();
var w,h, n;
var octaves = 3;
for ( var i = 0, j = 0, l = imageData.length; i < l; i += 4, j ++ ) {
h = Math.floor( j/width );
w = j % width;
n = 0;
for (var oi=0; oi < octaves; oi++) {
var exp = Math.pow(2, oi);
n += simplex.noise(w/width * exp, h/height* exp) / (exp * 2) ;
}
//n /= octaves;
n = Math.floor(Math.abs(n) * 255);
//n = Math.floor((simplex.noise(w/width, h/height)+1)/2 * 255);
imageData[ i ] = n;
imageData[ i + 1 ] = n;
imageData[ i + 2 ] = n;
imageData[ i + 3 ] = 255;
}
context.putImageData( image, 0, 0 );
console.log('done', Date.now() - now);
document.body.appendChild(canvas);
var texture = new THREE.Texture( canvas );
texture.needsUpdate = true;
return texture;
}
var texture = createNoiseTexture(1024, 1024);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment