|
@@ -79,6 +79,18 @@ class Perlin {
|
|
return gx * (x - ix) + gy * (y - iy) + gz * (z - iz);
|
|
return gx * (x - ix) + gy * (y - iy) + gz * (z - iz);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ inline function gradient1DAt( x : Float, ix : Int, seed : Int ) {
|
|
|
|
+ var index = seed * 1013 + (ix%repeat) * 1619;
|
|
|
|
+ index = ((index ^ (index >>> 8)) & 0xFF);
|
|
|
|
+ #if flash
|
|
|
|
+ index <<= 5;
|
|
|
|
+ var gx = double(index);
|
|
|
|
+ #else
|
|
|
|
+ var gx = gradients[index << 2];
|
|
|
|
+ #end
|
|
|
|
+ return gx * (x - ix);
|
|
|
|
+ }
|
|
|
|
+
|
|
inline function gradientAt( x : Float, y : Float, ix : Int, iy : Int, seed : Int ) {
|
|
inline function gradientAt( x : Float, y : Float, ix : Int, iy : Int, seed : Int ) {
|
|
var index = seed * 1013 + (ix%repeat) * 1619 + (iy%repeat) * 31337;
|
|
var index = seed * 1013 + (ix%repeat) * 1619 + (iy%repeat) * 31337;
|
|
index = ((index ^ (index >>> 8)) & 0xFF);
|
|
index = ((index ^ (index >>> 8)) & 0xFF);
|
|
@@ -118,6 +130,13 @@ class Perlin {
|
|
return linear(v1, v2, zs);
|
|
return linear(v1, v2, zs);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function gradient1D( seed : Int, x : Float ) {
|
|
|
|
+ var ix = Std.int(x), xs = scurve(x - ix);
|
|
|
|
+ var ga = gradient1DAt(x, ix, seed);
|
|
|
|
+ var gb = gradient1DAt(x, ix + 1, seed);
|
|
|
|
+ return linear(ga, gb, xs);
|
|
|
|
+ }
|
|
|
|
+
|
|
public function gradient( seed : Int, x : Float, y : Float ) {
|
|
public function gradient( seed : Int, x : Float, y : Float ) {
|
|
return inlineGradient(seed, x, y);
|
|
return inlineGradient(seed, x, y);
|
|
}
|
|
}
|
|
@@ -144,6 +163,17 @@ class Perlin {
|
|
return v;
|
|
return v;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function perlin1D( seed : Int, x : Float, octaves : Int, persist : Float = 0.5, lacunarity = 2.0 ) {
|
|
|
|
+ var v = 0.;
|
|
|
|
+ var k = 1.;
|
|
|
|
+ for( i in 0...octaves ) {
|
|
|
|
+ v += gradient1D(seed + i, x) * k;
|
|
|
|
+ k *= persist;
|
|
|
|
+ x *= lacunarity;
|
|
|
|
+ }
|
|
|
|
+ return v;
|
|
|
|
+ }
|
|
|
|
+
|
|
public function ridged( seed : Int, x : Float, y : Float, octaves : Int, offset : Float = 0.5, gain : Float = 2.0, persist : Float = 0.5, lacunarity = 2.0 ) {
|
|
public function ridged( seed : Int, x : Float, y : Float, octaves : Int, offset : Float = 0.5, gain : Float = 2.0, persist : Float = 0.5, lacunarity = 2.0 ) {
|
|
var v = 0.;
|
|
var v = 0.;
|
|
var p = 1.;
|
|
var p = 1.;
|