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

金魚の集団

Get Adobe Flash player
by s26 22 Jan 2011
    Embed
package{
    import flash.display.Sprite;
    import flash.events.Event;

    
    public class SpringLines extends Sprite{
        private var chaseList:Array;
        private var numLine:uint = 18;
        private var numPoints:uint = 20;
        private var colorList:Array = [0xe0002e,0x8ede2d,0x009fe0];
        
        /*---------------------
        まず、配列を作ります。
        上で決めた数だけ要素を作って、点のリストに入れます。
        それを線のリストに入れます。
        各線ごとにRandamPointが入ります。
                     各線の一番前の点をマウスの周りにランダムに取得をしています。
        --------------------*/
        public function SpringLines(){
            chaseList = new Array();
            for (var i:int = 0;i < numLine;i++){
                var list:Array = new Array();
                for ( var j:uint = 0;j<numPoints;j++){
                    var cp:ChasePoint = new ChasePoint();
                    list.push(cp);
                }
                chaseList.push(list);
            }
            
            
            for ( i = 0; i < numLine; i ++){
                cp = chaseList[i][0];
                var randamTimer:RandamPoint = new RandamPoint( this,cp);
            }
            
            addEventListener(Event.ENTER_FRAME,onEnterframe);
        }
        
        /*-------------
        繰り返される作業について。
        グラフィックを消します。
        ---------------*/
        private function onEnterframe( evt:Event):void{
            graphics.clear();
            for(var i:int = 0;i < numLine;i++){
                var list:Array = chaseList[i];
                var p0:ChasePoint;
                var p1:ChasePoint;
                p0 = list[0];
                p1 = list[1];
                movePoint( p1,p0,0.1,0.8);
                var c:uint = colorList[0];
                var a:Number = 0.6;
                for(var j:int = 2;j<list.length;j++){
                    p0 = list[j-1];
                    p1 = list[j];
                    movePoint(p1,p0,0.4,0.4);
                    graphics.lineStyle(1,c,a);
                    graphics.moveTo(p0.x,p0.y)
                    graphics.lineTo(p1.x,p1.y);
                    a -= 0.27;
                }
            }
        }
        /*-----------------
        何を、どこに。行き過ぎる具合、すばやさ。
        ----------------*/
        private function movePoint(pA:ChasePoint,pB:ChasePoint,spring:Number,friction:Number):void{
            var targetX:Number = pB.x;
            var targetY:Number = pB.y;
            pA.vx += ( targetX - pA.x)*spring;
            pA.vx *= friction;
            pA.x += pA.vx;
            pA.vy += (targetY-pA.y)*spring;
            pA.vy *= friction;
            pA.y += pA.vy;
        }
        
    }
}
/*----------------------
変数を持たせる為に用意。
------------------------*/
class ChasePoint{
    public var x:Number;
    public var y:Number;
    public var vx:Number;
    public var vy:Number;
    public function ChasePoint(){
        x = 0;
        y = 0;
        vx = 0;
        vy = 0;
    }
}
/*------------------------------
繰り返し、ランダムな数値を取得してくれる。
-----------------------------*/
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.DisplayObject;
class RandamPoint{
    private var cp:ChasePoint;
    private var timerObj:Timer;
    private var dpo:DisplayObject;
    private var dis:Number = 80;
    public function RandamPoint( targetobject:DisplayObject,p:ChasePoint){
        dpo = targetobject;
        cp = p;
        setTimer();
    }

    private function setTimer():void{
        timerObj = new Timer(0);
        timerObj.addEventListener(TimerEvent.TIMER,onTimer);
        timerObj.start();
    }

    private function onTimer(evt:TimerEvent):void{
        cp.x = Math.random()*dis - dis/2+dpo.mouseX;
        cp.y = Math.random()*dis-dis/2+dpo.mouseY;
        timerObj.delay = Math.random()*200 + 200;
    }
}