Perlin
/**
* Copyright UNDERCOVER ( http://wonderfl.net/user/UNDERCOVER )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/brkX
*/
package {
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap
import flash.geom.Point;
import flash.events.Event;
public class FlashTest extends Sprite {
private var test:Sprite;
private var canvas:BitmapData;
private var random:Number;
private var redArray:Array
private var PointArrayA:Array;
private var PointArrayB:Array;
public function FlashTest() {
// write as3 code here..
redArray= new Array(256);
for (var j:int = 0; j < 16; j++) {
redArray[j * 16] =4.2949e+009
redArray[j * 16+1] = 4.2949e+009
redArray[j * 16 + 2] =4.29491e+009
redArray[j * 16 + 3] = 4.29493e+009
redArray[j * 16 + 4] = 4.29494e+009
redArray[j * 16 + 5] = 4.29495e+009
redArray[j * 16 + 6] = 4.29497e+009
redArray[j * 16 + 7] = 4.294910e+009
redArray[j * 16 + 8] = 4.29497e+009
redArray[j * 16 + 9] = 4.29497e+009
redArray[j * 16 + 10] = 4.29497e+009
redArray[j * 16 + 11] = 4.29495e+009
redArray[j * 16 + 12] = 4.29494e+009
redArray[j * 16 + 13] = 4.29493e+009
redArray[j * 16 + 14] = 4.29491e+009
redArray[j * 16 + 15] = 4.2949e+009;
}
test = addChild(new Sprite()) as Sprite;
PointArrayA = [];
PointArrayB = [];
for (var i:int = 0; i < 3; i++ ) {
PointArrayA[i] = new Point(Math.random()*stage.stageWidth,Math.random()*stage.stageHeight)
PointArrayB[i] = new Point(Math.random() * 10 - 5, Math.random() * 10 - 5);
}
canvas = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x00FF0000);
test.addChild(new Bitmap(canvas)) as Bitmap;
addEventListener(Event.ENTER_FRAME, update);
}
private function update(e:Event):void {
random=Math.random()*10000
var i:int = 0;
while (i < 3) {
PointArrayA[i].x = PointArrayA[i].x + PointArrayB[i].x
PointArrayA[i].y=PointArrayA[i].y+PointArrayB[i].y
++i;
}
canvas.perlinNoise(stage.stageWidth, stage.stageHeight,3, random, false, true,1,false,PointArrayA)
canvas.paletteMap(canvas, canvas.rect, new Point(0, 0),redArray, null, null, null);
}
}
}