perlin noise - threshold

by Albert
♥0 | Line 28 | Modified 2011-03-09 20:54:33 | MIT License
play

ActionScript3 source code

/**
 * Copyright Albert ( http://wonderfl.net/user/Albert )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/CTWM
 */

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.geom.Point;
    import flash.geom.Rectangle;


    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var bmd1:BitmapData = new BitmapData(200, 200, true, 0xFFCCCCCC);
            
            var seed:int = int(Math.random() * int.MAX_VALUE);
            var channels:uint = BitmapDataChannel.RED | BitmapDataChannel.BLUE;
            bmd1.perlinNoise(100, 80, 12, seed, false, true, channels, false, null);
            
            var bitmap1:Bitmap = new Bitmap(bmd1);
            addChild(bitmap1);
            
            var bmd2:BitmapData = new BitmapData(200, 200, true, 0xFFCCCCCC);
            var pt:Point = new Point(0, 0);
            var rect:Rectangle = new Rectangle(0, 0, 200, 200);
            var threshold:uint =  0x00800000; 
            var color:uint = 0x20FF0000;
            var maskColor:uint = 0x00FF0000;
            bmd2.threshold(bmd1, rect, pt, ">", threshold, color, maskColor, true);
            
            var bitmap2:Bitmap = new Bitmap(bmd2);
            bitmap2.x = bitmap1.x + bitmap1.width + 10;
            addChild(bitmap2);            
        }
    }
}