Perlin noise: Difference between revisions

The Java reference implementation uses Math.floor, whereas in Python we had int(). The difference is in how it handles negative inputs: int() rounds towards 0.
(added Arturo implementation)
(The Java reference implementation uses Math.floor, whereas in Python we had int(). The difference is in how it handles negative inputs: int() rounds towards 0.)
Line 1,754:
{{trans|Java}}
 
<syntaxhighlight lang="python">defimport perlin_noise(x, y, z):math
 
X = int(x) & 255 # FIND UNIT CUBE THAT
def perlin_noise(x, y, z):
Y = int(y) & 255 # CONTAINS POINT.
ZX = intmath.floor(zx) & 255 # FIND UNIT CUBE THAT
xY -= intmath.floor(xy) & 255 # FINDCONTAINS RELATIVE X,Y,ZPOINT.
Z = math.floor(z) & 255
y -= int(y) # OF POINT IN CUBE.
Xx -= intmath.floor(x) & 255 # FIND UNITRELATIVE CUBE THATX,Y,Z
z -= int(z)
Yy -= intmath.floor(y) & 255 # CONTAINSOF POINT IN CUBE.
z -= intmath.floor(z)
u = fade(x) # COMPUTE FADE CURVES
v = fade(y) # FOR EACH OF X,Y,Z.
1

edit