[ Launch: perlin noise ] 5061982 by enjalot
-
-
Save enjalot/5061982 to your computer and use it in GitHub Desktop.
perlin noise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"perlin noise","endpoint":"","display":"canvas","public":true,"require":[{"name":"perlin","url":"https://raw.github.com/josephg/noisejs/master/perlin.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/0R4kCzy.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//playing with noise.js from Joseph Gentle | |
//https://github.com/josephg/noisejs | |
var xres = 100; | |
var yres = 100; | |
var thresh = 30; | |
var threshMult = 10; | |
var alpha = 255; | |
var scale = 256; | |
var ctx = tributary.ctx; | |
var canvas = tributary.canvas; | |
var image = ctx.createImageData(canvas.width, canvas.height); | |
var data = image.data; | |
var start = Date.now(); | |
for (var x = 0; x < canvas.width; x++) { | |
//if (x % 100 == 0) { | |
// noise.seed(Math.random()); | |
//} | |
for (var y = 0; y < canvas.height; y++) { | |
var value = Math.abs(noise.simplex2(x / xres, y / yres)); | |
value *= scale; | |
var cell = (x + y * canvas.width) * 4; | |
data[cell] = data[cell + 1] = data[cell + 2] = value; | |
data[cell] += Math.max(0, (thresh - value) * threshMult); | |
data[cell + 3] = alpha; // alpha. | |
} | |
} | |
/* // Benchmark code. | |
start = Date.now(); | |
for (var x = 0; x < 10000; x++) { | |
for (var y = 0; y < 10000; y++) { | |
noise.simplex2(x / 50, y/50); | |
} | |
}*/ | |
var end = Date.now(); | |
ctx.fillColor = 'black'; | |
ctx.fillRect(0, 0, 100, 100); | |
ctx.putImageData(image, 0, 0); | |
ctx.font = '16px sans-serif' | |
ctx.textAlign = 'center'; | |
ctx.fillText('Rendered in ' + (end - start) + ' ms', canvas.width / 2, canvas.height - 20); | |
if(console) { | |
console.log('Rendered in ' + (end - start) + ' ms'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment