Skip to content

Instantly share code, notes, and snippets.

@jsermeno
Created August 9, 2011 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsermeno/1133593 to your computer and use it in GitHub Desktop.
Save jsermeno/1133593 to your computer and use it in GitHub Desktop.
Perlin Noise Negative Coordinates
noise: function (x, y, z) {
// Find unit cube that contains point
var xFloor = ~~x;
var yFloor = ~~y;
var zFloor = ~~z;
var iX = xFloor & 255;
var iY = yFloor & 255;
var iZ = zFloor & 255;
...
noise: function (x, y, z) {
// Find unit cube that contains point
var xFloor = ~~x;
var yFloor = ~~y;
var zFloor = ~~z;
var iX = xFloor & 255;
var iY = yFloor & 255;
var iZ = zFloor & 255;
// Find relative x, y, z of the point in the cube.
x -= xFloor;
y -= yFloor;
z -= zFloor;
if (x < 0) { x += 1; iX = (iX + 255) & 255; }
if (y < 0) { y += 1; iY = (iY + 255) & 255; }
if (z < 0) { z += 1; iZ = (iZ + 255) & 255; }
@stephen-uac
Copy link

Is there a full version of this script in Javascript available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment