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

エッジ抽出した

ジャギる
/**
 * Copyright 3f5 ( http://wonderfl.net/user/3f5 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/l0d1
 */

// forked from 3f5's エッジ抽出できない
package {
    import flash.events.TimerEvent;
    import flash.text.TextLineMetrics;
    import flash.utils.Timer;
    import flash.text.TextFormat;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.text.TextField;
    import flash.display.Sprite;
    public class Edge extends Sprite {
        public function Edge() {
            var textFormat:TextFormat = new TextFormat();
            textFormat.size = 450;
            var text:TextField = new TextField();
            text.text = 'あ';
            text.autoSize = 'left';
            text.setTextFormat(textFormat);
            
            var bitmap:BitmapData = new BitmapData(text.width, text.height);
            bitmap.draw(text);
            
            var sprite:Sprite = new Sprite();
            sprite.graphics.lineStyle(7, 0x000000, 1, false);
            sprite.graphics.beginFill(0xFF0000);

            var map:Object = {};
            
            //stage.addChild(text);
            stage.addChild(sprite);
            
            var p:Array = [
                [1, 0],
                [0, -1],
                [-1, 0],
                [1, 1],
                [0, 1],
                [-1, -1],
                [-1, 1],
                [1, -1]
            ];
            
            for (var _x:uint = 0; _x < bitmap.width; _x++) {
                map[_x] = {};
                for (var _y:uint = 0; _y < bitmap.height; _y++) {
                    map[_x][_y] = false;
                }
            }
            
            var next:Array, prev:Array, y:int, x:int, pattern:Array, _pattern:Array, length:int;

            for (y = 0; y < bitmap.height; y++) {
                for (x = 0; x < bitmap.width; x++) {
                    if (compColor(bitmap.getPixel(x, y), 0x000000) && !map[x][y]) {
                        //sprite.graphics.lineStyle(1, Math.floor(Math.random() * 0xFFFFFF));
                        sprite.graphics.moveTo(x, y);
                        next = [x, y];
                        while (next != null) {
                          map[next[0]][next[1]] = true;
                          prev = [next[0], next[1]];
                          sprite.graphics.lineTo(next[0], next[1]);
                          next = null;
                          for each (pattern in p) {
                              _x = pattern[0] + prev[0];
                              _y = pattern[1] + prev[1];
                              if (!map[_x][_y] && compColor(bitmap.getPixel(_x, _y), 0x000000)) {
                                 for each (_pattern in p) {
                                     if (compColor(bitmap.getPixel(_x + _pattern[0], _y + _pattern[1]), 0xFFFFFF)) {
                                         next = [_x, _y];
                                         break;
                                     }
                                 }
                              }
                              if (next != null) break;
                          }
                       }
                    }

                }
            }
            
            sprite.graphics.endFill();
        }
        
        private function sleep(delay:int, callback:Function):void {
            var timer:Timer = new Timer(delay, 1);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE, callback);
            timer.start();
        }

        private function compColor(col1:Number, col2:Number):Boolean {
            /*
            
            var r1:int = (col1 >> 16) & 0xFF;
            var g1:int = (col1 >>  8) & 0xFF;
            var b1:int = (col1 >>  0) & 0xFF;

            var r2:int = (col2 >> 16) & 0xFF;
            var g2:int = (col2 >>  8) & 0xFF;
            var b2:int = (col2 >>  0) & 0xFF;
            
            if (Math.abs(r1 - r2) <= 40 && Math.abs(g1 - g2) <= 40 && Math.abs(b1 - b2) <= 40) {
                return true;
            }
            else {
                return false;
            }*/

            if (Math.abs(col1 - col2) <= 1048575) {
              return true;
            }
            
            return false;
        }

    }
}