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

forked from: edge extraction test

Sobel operatorはなんか汚くなったので削除ぉ
Get Adobe Flash player
by aobyrne 28 Feb 2012
    Embed
// forked from uwi's edge extraction test
package {
    import flash.display.*;
    import flash.net.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import flash.geom.*;
    
    // Sobel operatorはなんか汚くなったので削除ぉ
    public class Edge extends Sprite {
        public function Edge() {
            var bmd : BitmapData = getTextBitmap("not special, just wired", new TextFormat("verdana", 40));
            var bmp : Bitmap = new Bitmap(bmd);
            addChild(bmp);
            
            edge0(bmd);
            edge1(bmd);
            edge2(bmd);
        }
        
        private function edge0(src : BitmapData) : void
        {
            var cf : ConvolutionFilter = new ConvolutionFilter(3, 3,
                [0, 1, 0, 1, -4, 1, 0, 1, 0]);
            var bmd : BitmapData = new BitmapData(src.width, src.height, false);
            bmd.applyFilter(src, src.rect, new Point(), cf);
            var bmp : Bitmap = new Bitmap(bmd);
            bmp.x = 0; bmp.y = 100;
            addChild(bmp);
        }
        
        private function edge1(src : BitmapData) : void
        {
            var cf : ConvolutionFilter = new ConvolutionFilter(3, 3,
                [1, 1, 1, 1, -8, 1, 1, 1, 1]);
            var bmd : BitmapData = new BitmapData(src.width, src.height, false);
            bmd.applyFilter(src, src.rect, new Point(), cf);
            var bmp : Bitmap = new Bitmap(bmd);
            bmp.x = 0; bmp.y = 200;
            addChild(bmp);
        }
        
        private function edge2(src : BitmapData) : void
        {
            var cf : ConvolutionFilter = new ConvolutionFilter(3, 3,
                [1, -2, 1, -2, 4, -2, 1, -2, 1]);
            var bmd : BitmapData = new BitmapData(src.width, src.height, false);
            bmd.applyFilter(src, src.rect, new Point(), cf);
            var bmp : Bitmap = new Bitmap(bmd);
            bmp.x = 0; bmp.y = 300;
            addChild(bmp);
        }
        
        // テキストをBitmapDataに変換
        private static function getTextBitmap(text : String, tfmt : TextFormat) : BitmapData {
            var tf : TextField = new TextField();
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.defaultTextFormat = tfmt;
            tf.text = text;
            var ret : BitmapData = new BitmapData(tf.width, tf.height, false, 0xffffff);
            ret.draw(tf);
            return ret;
        }
    }
}