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

ArtFilter1

○階調化
Get Adobe Flash player
by hrtsgt 11 Nov 2014
    Embed
/**
 * Copyright hrtsgt ( http://wonderfl.net/user/hrtsgt )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ra0G
 */

package{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.net.*;
    import flash.system.*;
    [SWF(width=465, height=465, backgroundColor=0xFFFFFF, frameRate=60)]
    /* ○階調化 */

    public class ArtFilter1 extends Sprite{
        private var _canvas:BitmapData;
        private var _source:BitmapData;
        private var _b:uint = 0xFF;
        private var _level:uint = 6;//階調数
    
        public function ArtFilter1(){
            var loader:Loader = new Loader();
            loader.load( new URLRequest("http://t.args.in/lab/lib/einstein.jpg"), new LoaderContext(true));
            loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete);//
        }
        
        private function onComplete( e:Event ):void{
            _source = Bitmap( LoaderInfo(e.target).loader.content ).bitmapData;
            _source.applyFilter( _source, _source.rect, new Point(0,0), new ColorMatrixFilter([ 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0, 0, 0, 1, 0]));//モノクロ化
            _canvas = new BitmapData( _source.width, _source.height, true, 0x0);
            addChild( new Bitmap(_source) );
            addChild( new Bitmap(_canvas) );
            this.addEventListener( Event.ENTER_FRAME, update);//
        }
        
        private function update( e:Event ):void{
            var __b:uint = Math.floor((_b-1)/(0xFF/_level))*(0xFF/_level);
            _canvas.threshold( _source, _source.rect, new Point(0,0), "==", _b << 16, 0xFF000000 | __b << 16 | __b << 8 | __b, 0x00FF0000, false);
            if( --_b <= 0 ) this.removeEventListener( Event.ENTER_FRAME, update);//
        }
    
    }
}