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

Hoops -Ripple Objects-

メモ
* やたらCPU使用率が高い
* Hoopsと構造変えて、
* 各オブジェクトにアニメーション用のEnter Eventハンドラを持たせてみたが、
* その影響かとおもわれ。
Get Adobe Flash player
by ayataka 07 Feb 2009
/*
 * メモ
 * やたらCPU使用率が高い
 * Hoopsと構造変えて、
 * 各オブジェクトにアニメーション用のEnter Eventハンドラを持たせてみたが、
 * その影響かとおもわれ。
 */
package {
    //
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    /**
     *
     */
    [SWF(backgroundColor="#FFFFFF", frameRate=24)]
    public class Main extends Sprite {
        /**
         * Constructor
         */
        public function Main() {
            //
            var hoopCnt:int = 10;
            for(var cnt:int; cnt < hoopCnt; ++cnt) {
                var r:Ripple = new Ripple(
                                    Math.random() * this.stage.stageWidth,
                                    Math.random() * this.stage.stageHeight,
                                    0,
                                    Math.random() * 20 + 3,
                                    Util.getRandomColor(),
                                    Math.sqrt(2 * Math.pow(this.stage.stageWidth, 2)),
                                    Math.random() * 10,
                                    true);
                addChild( r );
            }
        }
    }
}


//-------------------------------------------------------------------------
// note :    local

// import package
import flash.display.*;
import flash.events.*;
import mx.effects.*;

/**
 * Hoop sprite
 */
class Hoop extends Sprite {
    /**
     */
    private var thickness:Number;
    private var color:uint;
    private var _radius:Number;

    /**
     * Constructor
     */
    public function Hoop(x:Number = 0, y:Number = 0, radius:Number = 0,
                         thickness:Number = 0, color:uint = 0) {
        //
        init(x, y, radius, thickness, color);
    }
    
    /**
     * reset
     */
    public function init(x:Number, y:Number, radius:Number,
                          thickness:Number, color:uint):void {
        //
        this.graphics.clear();
        this.graphics.beginFill(0, 0);
        this.graphics.lineStyle(thickness, color);
        this.graphics.drawCircle(0, 0, radius);
        this.graphics.endFill();
        // store
        this.x = x;
        this.y = y;
        this._radius = radius;
        this.thickness = thickness;
        this.color = color;
    }
     
    /**
     * getter and setter of radius
     */
    public function get radius():Number {
        return this._radius;
    }
    public function set radius(newValue:Number):void {
        //
        init(x, y, newValue, thickness, color);
    }
}

/**
 */
class Ripple extends Hoop {
    /**
     * animation properties.
     */
    private var maxRadius:Number;
    private var repeat:Boolean;
    private var dilay:Number;

    /**
     * Constructor
     */
    public function Ripple(x:Number = 0, y:Number = 0, radius:Number = 0,
                           thickness:Number = 0, color:uint = 0,
                           maxRadius:Number = 0, dilay:Number = 0,
                           repeat:Boolean = true) {
        // call super class constructor
        super(x, y, radius, thickness, color);
        
        // store
        this.maxRadius = maxRadius;
        this.repeat = repeat;
        this.dilay = dilay;        

        //
        addEventListener(Event.ENTER_FRAME, enterFrame);
    }


    /**
     * Enter frame handler
     */
    private function enterFrame(event:Event):void {
        //
        if( dilay >= 0 ) {
            var spf:Number = 1 / stage.frameRate;
            if( (dilay -= spf) >= 0 ) {
                return;
            }
        }

        //
        if( this.radius > maxRadius ) {
            if( repeat ) {
                this.radius = 0;
            }
            else {
                removeEventListener(Event.ENTER_FRAME, enterFrame);
            }
        }
        else {
            this.radius += 1;
        }
    }
}


//-------------------------------------------------------------------------
// note : for recycle

/**
 * My Utility Class
 */
final class Util {
    /**
     * Gets random color
     */
    static public function getRandomColor():uint {
        //
        var color:uint;
        /* 彩度、色相制御するならこっち
           Labがあったらそっち
        color |= Math.random() * 255 << 16;    // Red
        color |= Math.random() * 255 <<  8;    // Green
        color |= Math.random() * 255 <<  0;    // Blue
        */
        color = Math.random() * 0xFFFFFF;
        
        //
        return color;
    }
}