function Perlin::onAdd(%this)
{
%list = "151\t160\t137\t91\t90\t15\t131\t13\t201\t95\t96.... Etc, I'll pm u this if u ask me";
for(%i=0;%i<256;%i++)
{
%field = getField(%list,%i);
if(%field $= "")
continue;
%this.p[%i] = %field;
%this.p[256 + %i] = %field;
}
}
function Perlin::fade(%this,%t)
{
return %t * %t * %t * (%t * (%t * 6 - 15) + 10);
}
function Perlin::lerp(%this,%t,%a,%b)
{
return %a + %t * (%b - %a);
}
function Perlin::grad(%this,%hash,%x,%y,%z)
{
%h = %hash & 15;
%u = %h < 8 ? %x : %y;
%v = %h < 4 ? %y : %h == 12 || %h == 14 ? %x : %z;
return ((%h & 1) == 0 ? %u : -%u) + ((%h & 2) == 0 ? %v : -%v);
}
function Perlin::noise(%this,%x,%y,%z)
{
%floorX = ~~%x;
%floorY = ~~%y;
%floorZ = ~~%z;
%xb = %floorX & 255;
%yb = %floorY & 255;
%zb = %floorZ & 255;
%x -= %floorX;
%y -= %floorY;
%z -= %floorZ;
%xMinus1 = %x - 1;
%yMinus1 = %y - 1;
%zMinus1 = %z - 1;
%u = %this.fade(%x);
%v = %this.fade(%y);
%w = %this.fade(%z);
%A = %this.p[%xb] + %yb;
%AA = %this.p[%A] + %zb;
%AB = %this.p[%A + 1] + %zb;
%B = %this.p[%xb + 1] + %yb;
%BA = %this.p[%B] + %zb;
%BB = %this.p[%B + 1] + %zb;
return %this.lerp
(
%w,
%this.lerp
(
%v,
%this.lerp(%u,%this.grad(%this.p[%AA],%x,%y,%z),%this.grad(%this.p[%BA],%xMinus1,%y,%z)),
%this.lerp(%u,%this.grad(%this.p[%AB],%x,%yMinus1,%z),%this.grad(%this.p[%BB],%xMinus1,%yMinus1,%z))
),
%this.lerp
(
%v,
%this.lerp(%u,%this.grad(%this.p[%AA + 1],%x,%y,%zMinus1),%this.grad(%this.p[%BA + 1],%xMinus1,%y,%z - 1)),
%this.lerp(%u,%this.grad(%this.p[%AB + 1],%x,%yMinus1,%zMinus1),%this.grad(%this.p[%BB + 1],%xMinus1,%yMinus1,%zMinus1))
)
);
}
it was fixed
thanks z0w0
(it was actually in my history, he told me to forget off, but still thanks)
Edit: still broken, just less broken