Anonymous user
Perlin noise: Difference between revisions
m
→{{header|REXX}}: added whitespace, changed some comments, elided quotation marks for a long constant.
No edit summary |
m (→{{header|REXX}}: added whitespace, changed some comments, elided quotation marks for a long constant.) |
||
Line 1,185:
The original decimal (data) table was compressed into a single hexadecimal value (without spaces).
<lang rexx>/*REXX program implements a Perlin noise algorithm of a point in 3D─space. */
_=
||
||
||
end /*j*/ /* [↑] assign an indexed array. */
parse arg x y z d . /*obtain optional arguments from the CL*/
if x=='' | x=="," then x= 3.14
if y=='' | y=="," then y=
if z=='' | z=="," then z=
if d=='' | d=="," then d=
numeric digits d /*use D decimal digits for precision.*/
say 'Perlin noise for the 3D point ['space(x y z, 3)"] ───► " PerlinNoise(x, y, z)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fade: procedure; parse arg t; return t**3 * (t * (t * 6 - 15) + 10)
floor: procedure; parse arg x; _= x % 1; return _ - (x < 0) * (x \= _)
lerp: procedure; parse arg t,a,b; return a + t * (b - a)
pick: _= abs( arg(1) ) // 256; return @._
/*──────────────────────────────────────────────────────────────────────────────────────*/
grad: procedure; parse arg hash,x,y,z; _= abs(hash) // 16 /*force positive remainder
otherwise
/*──────────────────────────────────────────────────────────────────────────────────────*/
PerlinNoise: procedure expose @.; parse arg x,y,z
x$= floor(x) // 256; x = x - floor(x); xm= x-1;
y$= floor(y) // 256; y = y - floor(y); ym= y-1;
z$= floor(z) // 256; z = z - floor(z); zm= z-1;
a = pick(x$ ) + y$; aa= pick(a) + z$; ab= pick(a +1) + z$
b = pick(x$ +1) + y$; ba= pick(b) + z$; bb= pick(b +1) + z$
Line 1,229 ⟶ 1,230:
lerp(u, grad( pick(ab+1), x , ym, zm ), ,
grad( pick(bb+1), xm, ym, zm )))) /1</lang>
(Output note: this REXX program uses '''100''' decimal digit precision, but ''20'' decimal digits would've been adequate.)
(Note that REXX uses ''decimal'' floating point, not binary.)
|