Permalink
Browse files

Added fillColor method to OptimizedPerlin. Supports BitmapDataChannel…

… constants.
  • Loading branch information...
1 parent fb08a38 commit 1412b0bceab743a47638d31a3a2413346fa9f5a1 @skyboy committed Jun 11, 2011
Showing with 537 additions and 39 deletions.
  1. +537 −39 skyboy/math/OptimizedPerlin.as
View
576 skyboy/math/OptimizedPerlin.as
@@ -78,9 +78,21 @@ package skyboy.math { /*nl.ronvalstar.math*/
//
private var iSeed:int = 123;
- private var iXoffset:Number;
- private var iYoffset:Number;
- private var iZoffset:Number;
+ private var iXoffset1:Number;
+ private var iYoffset1:Number;
+ private var iZoffset1:Number;
+
+ private var iXoffset2:Number;
+ private var iYoffset2:Number;
+ private var iZoffset2:Number;
+
+ private var iXoffset3:Number;
+ private var iYoffset3:Number;
+ private var iZoffset3:Number;
+
+ private var iXoffset4:Number;
+ private var iYoffset4:Number;
+ private var iZoffset4:Number;
private const baseFactor:Number = 1 / 64;
@@ -99,9 +111,9 @@ package skyboy.math { /*nl.ronvalstar.math*/
var g1:Number, g2:Number, g3:Number, g4:Number, g5:Number, g6:Number, g7:Number, g8:Number;
var t:int, t2:int;
- $x += iXoffset;
- $y += iYoffset;
- $z += iZoffset;
+ $x += iXoffset1;
+ $y += iYoffset1;
+ $z += iZoffset1;
for (var i:int;i<iOctaves;i++)
{
@@ -214,17 +226,16 @@ package skyboy.math { /*nl.ronvalstar.math*/
oNoise.fill(bmp, x, y, z);
}
public function fill(bitmap:BitmapData, $x:Number = 0, $y:Number = 0, $z:Number = 0):void {
- var s:Number = 0, baseX:Number;
- var x1:Number, y1:Number, z1:Number;
+ var s:Number, x1:Number, y1:Number, z1:Number, baseX:Number;
var fFreq:Number, fPers:Number, x:Number, y:Number, z:Number;
var xf:Number, yf:Number, zf:Number, u:Number, v:Number, w:Number;
- var g1:Number, g2:Number, g3:Number, g4:Number, g5:Number, g6:Number, g7:Number, g8:Number;
- var i:int, px:int, pw:int, py:int, color:int, t:int, t2:int;
- var X:int, Y:int, Z:int, A:int, B:int, AA:int, AB:int, BA:int, BB:int, hash:int;
-
- baseX = $x * baseFactor + iXoffset;
- $y = $y * baseFactor + iYoffset;
- $z = $z * baseFactor + iZoffset;
+ var g1:Number, g2:Number, g3:Number, g4:Number, g5:Number, g6:Number, g7:Number, g8:Number;;
+ var X:int, Y:int, Z:int, A:int, B:int, AA:int, AB:int, BA:int, BB:int, hash:int, io:int = iOctaves;
+ var i:int, px:int, pw:int, py:int, t:int, t2:int, color:int;
+
+ baseX = $x * baseFactor + iXoffset1;
+ $y = $y * baseFactor + iYoffset1;
+ $z = $z * baseFactor + iZoffset1;
var width:int = bitmap.width;
var height:int = bitmap.height;
@@ -235,107 +246,106 @@ package skyboy.math { /*nl.ronvalstar.math*/
$x = baseX;
pw = py * width;
for ( px = width; px--; ) {
- s = 0;
-
- for ( i = iOctaves ; i--; ) {
+ s = 0e0;
+ for ( i = io ; i--; ) {
fFreq = aOctFreq[i];
fPers = aOctPers[i];
-
+
x = $x * fFreq;
y = $y * fFreq;
z = $z * fFreq;
-
+
xf = x - (x % 1);//Math.floor(x);
yf = y - (y % 1);//Math.floor(y);
zf = z - (z % 1);//Math.floor(z);
-
+
X = xf & 255;
Y = yf & 255;
Z = zf & 255;
-
+
x -= xf;
y -= yf;
z -= zf;
-
+
u = x * x * x * (x * (x * 6 - 15) + 10);
v = y * y * y * (y * (y * 6 - 15) + 10);
w = z * z * z * (z * (z * 6 - 15) + 10);
-
+
A = p[X] + Y;
AA = p[A] + Z;
AB = p[A + 1] + Z;
B = p[X + 1] + Y;
BA = p[B] + Z
BB = p[B + 1] + Z;
-
+
x1 = x - 1;
y1 = y - 1;
z1 = z - 1;
-
+
hash = p[BB + 1] & 15;
t = int(hash < 8);
g1 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g1 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z1 ));
-
+
hash = p[AB + 1] & 15;
t = int(hash < 8);
g2 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g2 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z1 ));
-
+
hash = p[BA + 1] & 15;
t = int(hash < 8);
g3 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g3 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z1 ));
-
+
hash = p[AA + 1] & 15;
t = int(hash < 8);
g4 = ((-(hash & 1) | 1)* (t * x + (1 - t) * y));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g4 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z1 ));
-
+
hash = p[BB] & 15;
t = int(hash < 8);
g5 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g5 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z ));
-
+
hash = p[AB] & 15;
t = int(hash < 8);
g6 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g6 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z ));
-
+
hash = p[BA] & 15;
t = int(hash < 8);
g7 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g7 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z ));
-
+
hash = p[AA] & 15;
t = int(hash < 8);
g8 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y));
t = int(hash == (12 | (hash & 2)));
t2 = int(hash < 4);
g8 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z ));
-
+
g2 += u * (g1 - g2);
g4 += u * (g3 - g4);
g6 += u * (g5 - g6);
g8 += u * (g7 - g8);
-
+
g4 += v * (g2 - g4);
g8 += v * (g6 - g8);
-
+
s += (g8 + w * (g4 - g8)) * fPers;
}
@@ -350,6 +360,482 @@ package skyboy.math { /*nl.ronvalstar.math*/
bitmap.setVector(bitmap.rect, data);
}
+ public static function fillColor(bmp:BitmapData, chans:int, x:Number = 0, y:Number = 0, z:Number = 0):void {
+ oNoise.fillColor(bmp, chans, x, y, z);
+ }
+ public function fillColor(bitmap:BitmapData, channels:int = 7, $x:Number = 0, $y:Number = 0, $z:Number = 0):void {
+ var grey:Boolean = (channels & 15) == 0;
+ var temp:Number = -(1/fPersMax);
+ var s1:Number, s2:Number, s3:Number, s4:Number, color4:int;
+ var fFreq:Number, fPers:Number, x:Number, y:Number, z:Number;
+ var baseX1:Number, baseX2:Number, baseX3:Number, baseX4:Number;
+ var xf:Number, yf:Number, zf:Number, u:Number, v:Number, w:Number;
+ var x1:Number, y1:Number, z1:Number, $x4:Number, $y4:Number, $z4:Number;
+ var $x2:Number, $x3:Number, $y2:Number, $y3:Number, $z2:Number, $z3:Number;
+ var i:int, px:int, pw:int, py:int, t:int, t2:int, color1:int, color2:int, color3:int;
+ var g1:Number, g2:Number, g3:Number, g4:Number, g5:Number, g6:Number, g7:Number, g8:Number;
+ var X:int, Y:int, Z:int, A:int, B:int, AA:int, AB:int, BA:int, BB:int, hash:int, io:int = iOctaves;
+ var blue:Boolean = (channels & 4) != 0, red:Boolean = (channels & 1) != 0, alpha:Boolean = (channels & 8) != 0;
+ var green:Boolean = ((channels & 2) | int(grey)) != 0;
+ var s01:Number = int(!green) * temp, s02:Number = int(!blue) * temp, s03:Number = int(!red) * temp, s04:Number = int(!alpha) * -temp;
+
+ baseX2 = $x * baseFactor + iXoffset2;
+ $y2 = $y * baseFactor + iYoffset2;
+ $z2 = $z * baseFactor + iZoffset2;
+
+ baseX3 = $x * baseFactor + iXoffset3;
+ $y3 = $y * baseFactor + iYoffset3;
+ $z3 = $z * baseFactor + iZoffset3;
+
+ baseX4 = $x * baseFactor + iXoffset4;
+ $y4 = $y * baseFactor + iYoffset4;
+ $z4 = $z * baseFactor + iZoffset4;
+
+ baseX1 = $x * baseFactor + iXoffset1;
+ $y = $y * baseFactor + iYoffset1;
+ $z = $z * baseFactor + iZoffset1;
+
+ var width:int = bitmap.width;
+ var height:int = bitmap.height;
+
+ var data:Vector.<uint> = bitmap.getVector(bitmap.rect);
+
+ for ( py = height; py--; ) {
+ $x = baseX1;
+ $x2 = baseX2;
+ $x3 = baseX3;
+ $x4 = baseX4;
+ pw = py * width;
+ for ( px = width; px--; ) {
+ s1 = s01;
+ s2 = s02;
+ s3 = s03;
+ s4 = s04;
+ for ( i = io ; i--; ) {
+ fFreq = aOctFreq[i];
+ fPers = aOctPers[i];
+
+ if (green) {
+ x = $x * fFreq;
+ y = $y * fFreq;
+ z = $z * fFreq;
+
+ xf = x - (x % 1);//Math.floor(x);
+ yf = y - (y % 1);//Math.floor(y);
+ zf = z - (z % 1);//Math.floor(z);
+
+ X = xf & 255;
+ Y = yf & 255;
+ Z = zf & 255;
+
+ x -= xf;
+ y -= yf;
+ z -= zf;
+
+ u = x * x * x * (x * (x * 6 - 15) + 10);
+ v = y * y * y * (y * (y * 6 - 15) + 10);
+ w = z * z * z * (z * (z * 6 - 15) + 10);
+
+ A = p[X] + Y;
+ AA = p[A] + Z;
+ AB = p[A + 1] + Z;
+ B = p[X + 1] + Y;
+ BA = p[B] + Z
+ BB = p[B + 1] + Z;
+
+ x1 = x - 1;
+ y1 = y - 1;
+ z1 = z - 1;
+
+ hash = p[BB + 1] & 15;
+ t = int(hash < 8);
+ g1 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g1 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AB + 1] & 15;
+ t = int(hash < 8);
+ g2 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g2 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BA + 1] & 15;
+ t = int(hash < 8);
+ g3 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g3 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AA + 1] & 15;
+ t = int(hash < 8);
+ g4 = ((-(hash & 1) | 1)* (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g4 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BB] & 15;
+ t = int(hash < 8);
+ g5 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g5 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AB] & 15;
+ t = int(hash < 8);
+ g6 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g6 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z ));
+
+ hash = p[BA] & 15;
+ t = int(hash < 8);
+ g7 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g7 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AA] & 15;
+ t = int(hash < 8);
+ g8 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g8 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z ));
+
+ g2 += u * (g1 - g2);
+ g4 += u * (g3 - g4);
+ g6 += u * (g5 - g6);
+ g8 += u * (g7 - g8);
+
+ g4 += v * (g2 - g4);
+ g8 += v * (g6 - g8);
+
+ s1 += (g8 + w * (g4 - g8)) * fPers;
+ }
+
+ if (blue) {
+ x = $x2 * fFreq;
+ y = $y2 * fFreq;
+ z = $z2 * fFreq;
+
+ xf = x - (x % 1);//Math.floor(x);
+ yf = y - (y % 1);//Math.floor(y);
+ zf = z - (z % 1);//Math.floor(z);
+
+ X = xf & 255;
+ Y = yf & 255;
+ Z = zf & 255;
+
+ x -= xf;
+ y -= yf;
+ z -= zf;
+
+ u = x * x * x * (x * (x * 6 - 15) + 10);
+ v = y * y * y * (y * (y * 6 - 15) + 10);
+ w = z * z * z * (z * (z * 6 - 15) + 10);
+
+ A = p[X] + Y;
+ AA = p[A] + Z;
+ AB = p[A + 1] + Z;
+ B = p[X + 1] + Y;
+ BA = p[B] + Z
+ BB = p[B + 1] + Z;
+
+ x1 = x - 1;
+ y1 = y - 1;
+ z1 = z - 1;
+
+ hash = p[BB + 1] & 15;
+ t = int(hash < 8);
+ g1 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g1 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AB + 1] & 15;
+ t = int(hash < 8);
+ g2 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g2 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BA + 1] & 15;
+ t = int(hash < 8);
+ g3 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g3 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AA + 1] & 15;
+ t = int(hash < 8);
+ g4 = ((-(hash & 1) | 1)* (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g4 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BB] & 15;
+ t = int(hash < 8);
+ g5 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g5 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AB] & 15;
+ t = int(hash < 8);
+ g6 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g6 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z ));
+
+ hash = p[BA] & 15;
+ t = int(hash < 8);
+ g7 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g7 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AA] & 15;
+ t = int(hash < 8);
+ g8 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g8 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z ));
+
+ g2 += u * (g1 - g2);
+ g4 += u * (g3 - g4);
+ g6 += u * (g5 - g6);
+ g8 += u * (g7 - g8);
+
+ g4 += v * (g2 - g4);
+ g8 += v * (g6 - g8);
+
+ s2 += (g8 + w * (g4 - g8)) * fPers;
+ }
+
+ if (red) {
+ x = $x3 * fFreq;
+ y = $y3 * fFreq;
+ z = $z3 * fFreq;
+
+ xf = x - (x % 1);//Math.floor(x);
+ yf = y - (y % 1);//Math.floor(y);
+ zf = z - (z % 1);//Math.floor(z);
+
+ X = xf & 255;
+ Y = yf & 255;
+ Z = zf & 255;
+
+ x -= xf;
+ y -= yf;
+ z -= zf;
+
+ u = x * x * x * (x * (x * 6 - 15) + 10);
+ v = y * y * y * (y * (y * 6 - 15) + 10);
+ w = z * z * z * (z * (z * 6 - 15) + 10);
+
+ A = p[X] + Y;
+ AA = p[A] + Z;
+ AB = p[A + 1] + Z;
+ B = p[X + 1] + Y;
+ BA = p[B] + Z
+ BB = p[B + 1] + Z;
+
+ x1 = x - 1;
+ y1 = y - 1;
+ z1 = z - 1;
+
+ hash = p[BB + 1] & 15;
+ t = int(hash < 8);
+ g1 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g1 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AB + 1] & 15;
+ t = int(hash < 8);
+ g2 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g2 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BA + 1] & 15;
+ t = int(hash < 8);
+ g3 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g3 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AA + 1] & 15;
+ t = int(hash < 8);
+ g4 = ((-(hash & 1) | 1)* (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g4 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BB] & 15;
+ t = int(hash < 8);
+ g5 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g5 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AB] & 15;
+ t = int(hash < 8);
+ g6 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g6 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z ));
+
+ hash = p[BA] & 15;
+ t = int(hash < 8);
+ g7 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g7 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AA] & 15;
+ t = int(hash < 8);
+ g8 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g8 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z ));
+
+ g2 += u * (g1 - g2);
+ g4 += u * (g3 - g4);
+ g6 += u * (g5 - g6);
+ g8 += u * (g7 - g8);
+
+ g4 += v * (g2 - g4);
+ g8 += v * (g6 - g8);
+
+ s3 += (g8 + w * (g4 - g8)) * fPers;
+ }
+
+ if (alpha) {
+ x = $x4 * fFreq;
+ y = $y4 * fFreq;
+ z = $z4 * fFreq;
+
+ xf = x - (x % 1);//Math.floor(x);
+ yf = y - (y % 1);//Math.floor(y);
+ zf = z - (z % 1);//Math.floor(z);
+
+ X = xf & 255;
+ Y = yf & 255;
+ Z = zf & 255;
+
+ x -= xf;
+ y -= yf;
+ z -= zf;
+
+ u = x * x * x * (x * (x * 6 - 15) + 10);
+ v = y * y * y * (y * (y * 6 - 15) + 10);
+ w = z * z * z * (z * (z * 6 - 15) + 10);
+
+ A = p[X] + Y;
+ AA = p[A] + Z;
+ AB = p[A + 1] + Z;
+ B = p[X + 1] + Y;
+ BA = p[B] + Z
+ BB = p[B + 1] + Z;
+
+ x1 = x - 1;
+ y1 = y - 1;
+ z1 = z - 1;
+
+ hash = p[BB + 1] & 15;
+ t = int(hash < 8);
+ g1 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g1 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AB + 1] & 15;
+ t = int(hash < 8);
+ g2 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g2 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BA + 1] & 15;
+ t = int(hash < 8);
+ g3 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g3 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z1 ));
+
+ hash = p[AA + 1] & 15;
+ t = int(hash < 8);
+ g4 = ((-(hash & 1) | 1)* (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g4 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z1 ));
+
+ hash = p[BB] & 15;
+ t = int(hash < 8);
+ g5 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g5 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AB] & 15;
+ t = int(hash < 8);
+ g6 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y1));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g6 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y1 + (1 - t2) * (t * x + (1 - t) * z ));
+
+ hash = p[BA] & 15;
+ t = int(hash < 8);
+ g7 = (( -(hash & 1) | 1) * (t * x1 + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g7 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x1 + (1 - t) * z ));
+
+ hash = p[AA] & 15;
+ t = int(hash < 8);
+ g8 = (( -(hash & 1) | 1) * (t * x + (1 - t) * y));
+ t = int(hash == (12 | (hash & 2)));
+ t2 = int(hash < 4);
+ g8 += ((int(!(hash & 2)) << 1) - 1) * (t2 * y + (1 - t2) * (t * x + (1 - t) * z ));
+
+ g2 += u * (g1 - g2);
+ g4 += u * (g3 - g4);
+ g6 += u * (g5 - g6);
+ g8 += u * (g7 - g8);
+
+ g4 += v * (g2 - g4);
+ g8 += v * (g6 - g8);
+
+ s4 += (g8 + w * (g4 - g8)) * fPers;
+ }
+ }
+
+ if (grey) {
+ s2 = s1;
+ s3 = s1;
+ }
+ color1 = ((s1 * fPersMax + 1) * 127) + 1;
+ color2 = ((s2 * fPersMax + 1) * 127) + 1;
+ color3 = ((s3 * fPersMax + 1) * 127) + 1;
+ color4 = ((s4 * fPersMax + 1) * 127) + 1;
+ data[pw + px] = (color4 << 24) | (color3 << 16) | (color1 << 8) | color2;
+
+ $x += baseFactor;
+ $x2 += baseFactor;
+ $x3 += baseFactor;
+ $x4 += baseFactor;
+ }
+
+ $y += baseFactor;
+ $y2 += baseFactor;
+ $y3 += baseFactor;
+ $y4 += baseFactor;
+ }
+ bitmap.setVector(bitmap.rect, data);
+ }
+
// GETTER / SETTER
//
@@ -436,9 +922,21 @@ package skyboy.math { /*nl.ronvalstar.math*/
}
private function seedOffset():void {
- iXoffset = iSeed = (iSeed * 16807) % 2147483647;
- iYoffset = iSeed = (iSeed * 16807) % 2147483647;
- iZoffset = iSeed = (iSeed * 16807) % 2147483647;
+ iXoffset1 = iSeed = (iSeed * 16807) % 2147483647;
+ iYoffset1 = iSeed = (iSeed * 16807) % 2147483647;
+ iZoffset1 = iSeed = (iSeed * 16807) % 2147483647;
+
+ iXoffset2 = iSeed = (iSeed * 16807) % 2147483647;
+ iYoffset2 = iSeed = (iSeed * 16807) % 2147483647;
+ iZoffset2 = iSeed = (iSeed * 16807) % 2147483647;
+
+ iXoffset3 = iSeed = (iSeed * 16807) % 2147483647;
+ iYoffset3 = iSeed = (iSeed * 16807) % 2147483647;
+ iZoffset3 = iSeed = (iSeed * 16807) % 2147483647;
+
+ iXoffset4 = iSeed = (iSeed * 16807) % 2147483647;
+ iYoffset4 = iSeed = (iSeed * 16807) % 2147483647;
+ iZoffset4 = iSeed = (iSeed * 16807) % 2147483647;
}
}
}

0 comments on commit 1412b0b

Please sign in to comment.