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: forked from: Brush forked from: Hairs

髪束に軌跡を付けてみたら、何やら筆っぽくなりました
MOUSE_DOUNで描画します
/**
 * Copyright savinius ( http://wonderfl.net/user/savinius )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uVQZ
 */

// forked from Atira's forked from: Brush forked from: Hairs
// forked from SeeDa's Brush forked from: Hairs
/*
 * 髪束に軌跡を付けてみたら、何やら筆っぽくなりました
 * MOUSE_DOUNで描画します
 */
package {
    import flash.display.*;
    import flash.geom.*;
    import flash.events.*;
    [SWF(width="500",height="500",backgroundColor="0x033303",frameRate="60")]
    
    public class Hairs extends Sprite {
        private var hairs:Array = new Array();
        private var brushStage:Sprite = new Sprite();
        private var paperBmd:BitmapData = new BitmapData(640,640,false,0x003333);
        private var paper:Bitmap = new Bitmap(paperBmd);
        private var drawFlg:Boolean = false;
        public function Hairs():void {
            addChild(paper);
            //addChild(brushStage);
            for (var i:uint = 0; i < 50; i++) {
                var hair:Hair = new Hair();
                brushStage.addChild(hair);
                hairs.push(hair);
            }
            stage.addEventListener(MouseEvent.MOUSE_DOWN, drawStart);
            stage.addEventListener(MouseEvent.MOUSE_UP, drawFinish);

            //Wonderfl.capture_delay( 30 );
        }
        private function drawStart(e:Event):void {
            addEventListener(Event.ENTER_FRAME, draw);
        }
        private function drawFinish(e:Event):void {
            removeEventListener(Event.ENTER_FRAME, draw);
        }
        private function draw(e:Event):void {
            paperBmd.draw(brushStage);
        }
    }
}

import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.*;
class Hair extends Sprite {
    private var nSpeed:Number;
    private var nColor:uint;
    private var points:Vector.<Number> = new Vector.<Number>();
    private var commands:Vector.<int> = new Vector.<int>();
    private var pointsNum:uint = 20;
    private var pointDist:Number = 2;
    private var offsetX:Number;
    private var offsetY:Number;
    public function Hair():void {
        // 追跡スピードに変化を持たせることによって、描画位置をずらす
        nSpeed   = Math.random()*8+10;
            offsetX = Math.random()*nSpeed-(nSpeed/2);
            offsetY = Math.random()*nSpeed-(nSpeed/2);
        var nB:uint = Math.floor(Math.random()*128) + 128;
        var nO:uint = Math.floor(Math.random()*nB);
        nColor = nB*256*256*256 +  nB * 256  + nB;
        
        commands.push(1);
        points.push(mouseX,mouseY);
        for (var i:uint = 1; i < pointsNum; i++) {
            points.push(mouseX, mouseY);
            commands.push(2);
        }
        addEventListener(Event.ENTER_FRAME, xMove);
    }
    private function xMove(e:Event):void {
        // ターゲットまでの距離を求める
        var mX:Number = mouseX+offsetX;
        var mY:Number = mouseY+offsetY;
        var dist:Number = Point.distance(new Point(points[0],points[1]), new Point(mX, mY));
        if(dist > nSpeed) {
            // ターゲットへの角度を求める
            var radian:Number = Math.atan2(mY-points[1], mX-points[0]);
            // 移動
            points[0] += Math.cos(radian)*nSpeed;
            points[1] += Math.sin(radian)*nSpeed;
        }
        // 2番目以降の点を移動する
        for (var i:uint = 1; i < pointsNum; i++) {
            var tP:Point = new Point(points[i*2-2], points[i*2-1]);
            var cP:Point = new Point(points[i*2], points[i*2+1]);
            dist = Point.distance(tP,cP);
            if (dist > pointDist) {
                var dX:Number = tP.x - cP.x;
                var dY:Number = tP.y - cP.y;
                var rad:Number = Math.atan2(dX,dY);
                dist -= pointDist;
                points[i*2] += Math.sin(rad) * dist;
                points[i*2+1] += Math.cos(rad) * dist;
            }
        }
        // 再描画
        graphics.clear();
        graphics.lineStyle(1,nColor);
        graphics.drawPath(commands,points);
    }
}