In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

BitmapData Threshold Test

Get Adobe Flash player
by nutsu 06 Mar 2010
/**
 * Copyright nutsu ( http://wonderfl.net/user/nutsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uiGq
 */

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import frocessing.geom.FGradientMatrix;
    public class ThresholdTest extends Sprite {
    		private var bd2:BitmapData;
    		private var bd:BitmapData
        public function ThresholdTest() {
            var w:int = 465;
            var h:int = 465;
            
            bd = new BitmapData( w ,h, false, 0x0 );
            
            var s:Shape = new Shape();
            var mat:FGradientMatrix = new FGradientMatrix();
           
            mat.createLinear( 0, 0, w, 0 );
            s.graphics.beginGradientFill( "linear",[0,0x00ff00],[1,1],[0,255],mat);
            s.graphics.drawRect( 0, 0, w, h );
            s.graphics.endFill();
            bd.draw( s );
            
            s.graphics.clear();
            mat.createLinear( 0, 0, 0, h );
            s.graphics.beginGradientFill( "linear",[0,0x0000ff],[1,1],[0,255],mat);
            s.graphics.drawRect( 0, 0, w, h );
            s.graphics.endFill();
            bd.draw( s, null, null, "add" );
            
            
            addChild( new Bitmap(bd2 = new BitmapData(w,h,false,0)) );
            
            //threshold test するす。
            addEventListener( Event.ENTER_FRAME, onenter );
        }
        
        private function onenter( e:Event ):void
        {
        		var m:uint = ((mouseX>>1) & 0xff )<<8 | ((mouseY>>1)&0xff );
        		bd2.fillRect( bd2.rect, 0 );
        		 bd2.threshold( 
            		bd, bd.rect, bd.rect.topLeft,
            		">=",
            		0xffffffff,
            		0xffff00ff,
            		m,
            		false
            	);
            	//おわり。maskおもしろいね。
        }
    }
}