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

最終課題

マウスが移動した場所から波紋が広がるようにし、
円の色がランダムに変化するプログラムを作成しました。
更に、数を50から300に増やし、
円を塗りつぶしました。
Get Adobe Flash player
by maxcm168 30 Jan 2012
/**
 * Copyright maxcm168 ( http://wonderfl.net/user/maxcm168 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9TSl
 */

// forked from maxcm168's マウスが移動した場所から波紋が広がる(random)
// forked from maxcm168's マウスが移動した場所から波紋が広がる
// forked from maxcm168's forked from: forked from: マウスでクリックしたところから円が広がる(複数可能)
// forked from maxcm168's forked from: マウスでクリックしたところから円が広がる(複数可能)
// forked from maxcm168's マウスでクリックしたところから円が広がる(複数可能)
// forked from lenonsun's マウスでクリックしたところから円が広がる(複数可能)
// マウスでクリックしたところから円が広がる(複数可能)
package 
{
    import flash.events.MouseEvent;
    
    import frocessing.display.F5MovieClip2D;
    /**
     * マウスでクリックしたところから円が広がる
     * @author shmdmoto
     */
    public class clickInterpolate1 extends F5MovieClip2D
    {
        public var intR:Array;  // 円の半径
        public var circX:Array; // 円の中心のX座標
        public var circY:Array; // 円の中心のX座標
        public var fCol:Array;
        public function clickInterpolate1() {
            super(false);
        }
        public function setup() : void
        {
            intR = new Array(300);
            circX = new Array(300);
            circY = new Array(300);
            fCol = new Array(300);
            colorMode(HSB,360,100,100);
            for( var i : int = 0 ; i < 300 ; i++) {
                intR[i] = new Interpolate(5, 1, 100);
                intR[i].pause(); // はじめは停止
                circX[i] = new Number();
                circX[i] = 0.0;
                circY[i] = new Number();
                circY[i] = 0.0;
                //fcol[i] = new Number();
                //fcol[i] = 0;
            }
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
        }
        public function draw() : void
        {
            for( var i : int = 0 ; i < 300 ; i++ ) {
                if( intR[i].isRunning() ) { // 半径が変化していれば表示
                    noFill();
                    fill(fCol[i], 100-100*intR[i].val()/100,100 );
                    stroke(fCol[i], 100-100*intR[i].val()/100,100 );
                    ellipse(circX[i], circY[i],
                        intR[i].val(), intR[i].val() );
                }
            }
        }
        public function onMove(event:MouseEvent):void 
        {
            for( var i : int = 0 ; i < 300 ; i++ ) {
                // 停止中のInterpolateを見つける
                if( !intR[i].isRunning() ) { 
                    circX[i] = event.stageX;
                    circY[i] = event.stageY;
                    fCol[i] = random(360);
                    intR[i].start();
                    break; //一つ見つけたら終わり
                }
            }
        }        
    }
}

// 以下は,動きを記述するためのクラスですので,編集しないでください.
import flash.utils.getTimer;
import frocessing.math.PerlinNoise;
/**
 * Interpolate:指定した時間で,開始値から終値までの過渡的を
 *             記述するクラス
 */
class Interpolate
{
    private static const NOINIT  :int = 1;
    private static const RUNNING :int = 2;
    private static const WAITING :int = 3;
    private static const STOPPED :int = 4;
    private var duration  :Number;
    private var begin     :Number;
    private var end       :Number;
    private var pow       :Number;
    private var tOffset   :Number;
    private var tElapsed  :Number;
    private var prevVal   :Number;
    private var tRestart  :Number;
    public  var status    :int = NOINIT;
    public function Interpolate( t:Number, s:Number, f:Number,
                                 p:Number = 1) {
        begin = prevVal = s;
        end = f;
        duration = t;
        pow = p;
        tOffset = 0;
        tElapsed = 0;
    }
    public function val() :Number {
        var t :Number;
        if( status == NOINIT){
            tOffset = getTimer()/1000;
            prevVal = begin;
            status = RUNNING;
        } else if( status == RUNNING ) {
            t = getTimer()/1000;
            tElapsed = t -tOffset;
            if( tElapsed < duration ) {
                prevVal = begin + ( end - begin )*Math.pow(tElapsed/duration,pow);
            } else {
                prevVal = end;
                status = STOPPED;
            }
        } else if( status == WAITING){
            t = getTimer()/1000;
            if( t >= tRestart) {
                status = RUNNING;
                tOffset = t - tElapsed;        
            }
        }
        return prevVal;
    }
    public function pause() :void
    {
        status = STOPPED;
    }
    public function cont() :void
    {
        status = RUNNING;
        tOffset = getTimer()/1000-tElapsed;        
    }
    public function start() :void
    {
        status = RUNNING;
        tOffset = getTimer()/1000;                
    }
    public function wait( waitTime :Number ) :void
    {
        status = WAITING;
        tRestart = getTimer() + waitTime;
    }
    
    public function isRunning() :Boolean
    {
        if( status == RUNNING ) {
            return true;
        } else {
            return false;
        }
    }
    public function isStopped() :Boolean
    {
        if( status == STOPPED ) {
            return true;
        } else {
            return false;
        }
    }
    public function isEnd() :Boolean
    {
        if( prevVal >= end) {
            return true;
        } else {
            return false;
        }
    }
}
/**
 * LFO:指定した時間での周期的変動を記述するクラス
 */
class LFO {
    public static const SIN    :int = 1;
    public static const COS    :int = 2;
    public static const SAW    :int = 3;
    public static const TRI    :int = 4;
    public static const SQR    :int = 5;
    public static const ABSSIN :int = 6;
    public static const NOISE  :int = 7;
    private static const NOINIT  :int = 1;
    private static const RUNNING :int = 2;
    private static const WAITING :int = 3;
    private static const STOPPED :int = 4;
    private var period    :Number;
    private var amplitude :Number;
    private var phase     :Number;
    private var offset    :Number;
    private var type      :int = SIN;
    private var isStart   :Boolean;
    private var t_offset  :Number;
    private var status    :int = NOINIT;
    
    public function LFO( prd :Number, amp :Number,
                         of :Number = 0, ph :Number = 0)
    {
        period    = prd;
        amplitude = amp;
        offset    = of;
        phase     = ph;
    }
    public function setPeak( min :Number, max :Number) :void
    {
        offset = (min + max) / 2;
        if( min < max ) {
            amplitude    = (max - min) / 2;
        } else {
            amplitude    = (min - max) / 2;
        }        
    }
    public function setType( t :int ) :void
    {
        type = t;
    }
    public function val( mul :Number=1.0 ) :Number {
        if(status == NOINIT) {
            status = RUNNING;
            t_offset = getTimer() / 1000.0;
            return val();
        } else if(status == RUNNING ) {
            var t :Number = getTimer() / 1000.0 - t_offset;
            var temp :Number;
            switch(type) {
                case SIN :
                    return  offset + mul * amplitude * 
                    Math.sin(2.0 * Math.PI *( t/period + phase) );
                case COS :
                    return  offset + mul * amplitude *
                    Math.cos(2.0 * Math.PI *( t/period + phase) );
                case SAW :
                    temp = t / period + 0.5 + phase - 
                    Math.floor( t / period + 0.5 + phase ) - 0.5;
                    return  offset + 2.0 * mul * amplitude * temp;
                case TRI :
                    temp = t / period + phase - 
                    Math.floor (t / period + phase );
                    if( 0.0 <= temp && temp < 0.25 ) {
                        return offset + mul * amplitude * 4.0 * temp;
                    } else if( temp < 0.75 ) {
                        return offset + mul * amplitude * (  2.0 - 4.0 * temp);
                    } else {
                        return offset + mul * amplitude * ( -4.0 + 4.0 * temp);
                    }
                case SQR :
                    temp = t/period + phase - 
                    Math.floor( t / period + phase);
                    if( temp < 0.5 ){
                        return offset + mul * amplitude;
                    } else {
                        return offset - mul * amplitude;
                    }
                case ABSSIN :
                    return  offset + 
                    Math.abs(mul * amplitude * Math.sin(2.0*Math.PI *( t/period + phase)));
                case NOISE :
                    var p :PerlinNoise = new PerlinNoise(); 
                    return offset -mul * amplitude + 2.0 * mul * amplitude * p.noise(t/period+phase,1);
                default :
                    return 0.0;
            }
        } else {
            return 0.0;
        }        
    }
}