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

ひげ

respect HIGE
俺もひげほしい。 
クリックでエラーを修正 
@author jc at bk-zen.com
Get Adobe Flash player
by bkzen 03 Dec 2015
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6695
 */

package  
{
    import flash.display.BitmapData;
    import flash.display.GradientType;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    
    /**
     * respect HIGE
     * 俺もひげほしい。 
     * クリックでエラーを修正 
     * @author jc at bk-zen.com
     */
    public class HigeMoja extends Sprite
    {
        private var tips:TextField;
        private var startX: Number;
        private var startY: Number;
        private var guide: Shape;
        
        public function HigeMoja() 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e: Event = null): void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            //
            tips = new TextField();
            tips.selectable = false;
            tips.text = "drag  stage.";
            tips.autoSize = TextFieldAutoSize.LEFT;
            tips.x = (stage.stageWidth - tips.width) / 2;
            tips.y = (stage.stageHeight - tips.height) / 2;
            addChild(tips);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
        }
        
        private function onMouseDown(e:MouseEvent):void 
        {
            guide = new Shape();
            addChild(guide);
            if (tips) removeChild(tips);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            stage.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            startX = stage.mouseX;
            startY = stage.mouseY;
            guide.x = startX;
            guide.y = startY;
        }
        
        private function onMove(e:MouseEvent):void 
        {
            var g: Graphics = guide.graphics;
            g.clear();
            g.lineStyle(1, 0xCCCCCC);
            g.drawEllipse(0, 0, stage.mouseX - startX, stage.mouseY - startY);
            g.endFill();
        }
        
        private function onMouseUp(e:MouseEvent):void 
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
            stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            // 
            makeFace();
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
        }
        
        private function makeFace():void
        {
            var g: Graphics = guide.graphics;
            var minX: Number = Math.min(startX, stage.mouseX);
            var minY: Number = Math.min(startY, stage.mouseY);
            var maxX: Number = Math.max(startX, stage.mouseX);
            var maxY: Number = Math.max(startY, stage.mouseY);
            var w: Number = maxX - minX;
            var h: Number = maxY - minY;
            if (w < 1 || h < 1) return ;
            guide.x = minX;
            guide.y = minY;
            g.clear();
            g.lineStyle(1, 0x333333);
            g.drawEllipse(0, 0, w, h);
            
            g.moveTo(w / 5 * 1.3, h / 4);
            g.lineTo(w / 5 * 1.7, h / 4);
            g.moveTo(w / 5, h / 5);
            g.lineTo(w / 5 * 2, h / 5);
            
            g.moveTo(w / 5 * 3.3, h / 4);
            g.lineTo(w / 5 * 3.7, h / 4);
            g.moveTo(w / 5 * 3, h / 5);
            g.lineTo(w / 5 * 4, h / 5);
            
            g.moveTo(w / 2, h / 5 * 3);
            g.lineTo(w / 2, h / 5 * 2);
            
            g.moveTo(w / 5 * 1.5, h / 5 * 4);
            g.lineTo(w / 5 * 3.5, h / 5 * 4);
            
            g.endFill();
            
            // ひげエリア
            var higeArea: Shape = new Shape();
            var matrix: Matrix = new Matrix();
            matrix.createGradientBox(w, h, 90 * Math.PI / 180);
            higeArea.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, 0x333333], [1.0, 1.0], [0xCC, 0xFF], matrix);
            higeArea.graphics.drawEllipse(0, 0, w, h);
            
            var dh: int = h / 0xFF * (0xFF - 0xCC);
            var bmd: BitmapData = new BitmapData(w, dh, true, 0xFFFFFFFF);
            bmd.lock();
            matrix = new Matrix();
            matrix.ty = dh - h;
            bmd.draw(higeArea, matrix);
            bmd.unlock();
            var n: int = bmd.width * bmd.height;
            for (var i: int = 0; i < n; i++ )
            {
                var x: int = i % bmd.width;
                var y: int = i / bmd.width;
                var c: uint = bmd.getPixel32(x, y);
                if (c != 0xFFFFFFFF)
                {
                    var b: int = c & 0xFF;
                    var whiskerL: Number = Math.random() * (0xFF - b) / 0xFF * 20;
                    var whiskerR: Number = Math.random() * 2 * Math.PI;
                    var acX: Number = x + whiskerL * Math.cos(whiskerR);
                    var acY: Number = y + whiskerL * Math.sin(whiskerR) + h - dh;
                    var ctrlD: Number = whiskerL * Math.random();
                    var ctrlR: Number = Math.random() * 2 * Math.PI;
                    var ctrlX: Number = x + ctrlD * Math.cos(ctrlR);
                    var ctrlY: Number = y + ctrlD * Math.sin(ctrlR) + h - dh;
                    g.lineStyle(1, 0, (0xFF - b) / 0xFF);
                    g.moveTo(x, y + h - dh);
                    g.curveTo(ctrlX, ctrlY, acX, acY);
                }
            }
            tips = null;
            }
        
    }
    
}