Monday, March 19, 2012

Flex SDK -- Perlin Noise (AS3)

The Flex SDK has a built-in perlin noise algorithm already.

------------ begin script ------------


function createPerlinImage(width:int, height:int, octaveCnt:int=4) : BitmapData {   
 var bmp:BitmapData = new BitmapData(width, height, true);
 bmp.perlinNoise(width, height, octaveCnt, getTimer() * Math.random(), true, false, BitmapDataChannel.ALPHA, true);
 return bmp;
};

function createImage(event:Event) : void {
 var width:int = 200;
 var height:int = 300;
 
 var bmpDisp:Bitmap = new Bitmap(createPerlinImage(width, height, 4));
 bmpDisp.x = 200;
 stage.addChild(bmpDisp);
}