Perlin noise: Difference between revisions

Content added Content deleted
(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: Line 1,754:
{{trans|Java}}
{{trans|Java}}


<syntaxhighlight lang="python">def perlin_noise(x, y, z):
<syntaxhighlight lang="python">import math

X = int(x) & 255 # FIND UNIT CUBE THAT
def perlin_noise(x, y, z):
Y = int(y) & 255 # CONTAINS POINT.
Z = int(z) & 255
X = math.floor(x) & 255 # FIND UNIT CUBE THAT
x -= int(x) # FIND RELATIVE X,Y,Z
Y = math.floor(y) & 255 # CONTAINS POINT.
Z = math.floor(z) & 255
y -= int(y) # OF POINT IN CUBE.
x -= math.floor(x) # FIND RELATIVE X,Y,Z
z -= int(z)
y -= math.floor(y) # OF POINT IN CUBE.
z -= math.floor(z)
u = fade(x) # COMPUTE FADE CURVES
u = fade(x) # COMPUTE FADE CURVES
v = fade(y) # FOR EACH OF X,Y,Z.
v = fade(y) # FOR EACH OF X,Y,Z.