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

Circle Wave

CreateJS作るためのサンプル。
jsto.it
http://jsdo.it/kawamu/9n6Y

github
https://github.com/kawamurashin/WaveCircle
Get Adobe Flash player
by kawamura 08 May 2014
    Embed
/**
 * Copyright kawamura ( http://wonderfl.net/user/kawamura )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/faHb
 */

package {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import net.hires.debug.Stats;
[SWF(frameRate='60', width='465', height='465')]
public class Main extends Sprite {

    public function Main() {
        if(stage)init(null);
        else addEventListener(Event.ADDED_TO_STAGE,init);
    }

    private function init(event:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE,init);
        //
        layout();
    }

    private function layout():void {
        var viewManager:ViewManager = ViewManager.getInstance();
        addChild(viewManager);

        var stats:Stats = new Stats();
        addChild(stats);

    }
}
}
import flash.display.Sprite;
import flash.events.Event;
class ViewManager extends Sprite{
    private static var instance:ViewManager;
    public var cx:Number;
    public var cy:Number;
    private var circle:CircleRing;
    public function ViewManager(block:SingletonBlock) {
        if(stage)init(null);
        else addEventListener(Event.ADDED_TO_STAGE,init);
    }
    public static function getInstance():ViewManager
    {
        if(instance == null)
        {
            instance = new ViewManager(new SingletonBlock());
        }
        return instance;
    }

    private function init(event:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        //
        layout();
    }

    private function layout():void {
        //
        cx = stage.stageWidth *0.5;
        cy = stage.stageHeight *0.5;
        circle = new CircleRing();
        addChild(circle);

        addEventListener(Event.ENTER_FRAME,enterFrameHandler);
    }

    private function enterFrameHandler(event:Event):void {
        circle.onEnterFrame();
    }
}
class SingletonBlock{

}



import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
class CircleRing extends Sprite {
    private const MEMBERS:uint = 360;
    private const K:Number = 0.1;

    public function CircleRing() {
        if (stage)init(null);
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private var expansionForce:Number;
    private var radius:Number;
    private var viewManager:ViewManager;
    //private var balancePoint:Sprite;
    private var pointList:Array;

    public function onEnterFrame():void {
        var i:uint;
        var n:uint;

        var prePoint:CirclePoint
        var point:CirclePoint;
        var nextPoint:CirclePoint;
        var force:Number;
        var disX:Number = 0;
        var disY:Number = 0;

        //
        n = pointList.length;
        for (i = 0; i < n; i++) {
            point = pointList[i];

            disX = point.defaultX - point.x;
            disY = point.defaultY - point.y;

            point.forceX = 0.05 * disX;
            point.forceY = 0.05 * disY;



            //
            if (i == 0) {
                prePoint = pointList[n - 1];
                nextPoint = pointList[i + 1];
            }
            else if (i == n - 1) {
                prePoint = pointList[i - 1];
                nextPoint = pointList[0];
            }
            else {
                prePoint = pointList[i - 1];
                nextPoint = pointList[i + 1];
            }
            disX = prePoint.x - point.x;
            disY = prePoint.y - point.y;
            point.forceX += K * disX;
            point.forceY += K * disY;

            disX = nextPoint.x - point.x;
            disY = nextPoint.y - point.y;
            point.forceX += K * disX;
            point.forceY += K * disY;


        }

        for (i = 0; i < n; i++)
        {
            point = pointList[i];
            point.onEnterFrame();
        }

        draw();
    }

    private function timerHandler(event:TimerEvent):void {
        var point:CirclePoint;
        var theta:Number;
        var force:Number;
        var i:uint;
        var n:uint;
        var number:uint;
        var num:int;
        var numberList:Array = [];
        var f:Number;
        var w:uint;

        f = 2 + 8 * Math.random();
        //n =  Math.floor(Math.random() * pointList.length);
        number = Math.floor(Math.random() * pointList.length);
        w = 6 + 18 * Math.random();
        n = w;
        for (i = 0; i < n; i++)
        {
            num = number - Math.floor(n * 0.5) + i;
            if (num < 0)
            {
                num += MEMBERS;
            }
            else if ( num >= MEMBERS)
            {
                num -= MEMBERS;
            }


            point = pointList[num];

            theta = Math.atan2(viewManager.cy - point.y, viewManager.cx - point.x);
            force = f * Math.sin(Math.PI * (i / n));
            point.forceX = force * Math.cos(theta);
            point.forceY = force * Math.sin(theta);
            point.onEnterFrame();
        }

        //

        var timer:Timer = new Timer(1000,1);
        timer.addEventListener(TimerEvent.TIMER, timerHandler);
        timer.start();
    }

    private function layout():void {
        var i:uint;
        var n:uint;
        var g:Graphics;
        var theta:Number;
        var point:CirclePoint;
        //
        viewManager = ViewManager.getInstance();
        //
        /*
        balancePoint = new Sprite();
        addChild(balancePoint);
        g = balancePoint.graphics;
        g.beginFill(0xFF0000);
        g.drawCircle(0, 0, 8);
        */
        //
        pointList = [];
        radius = 200;
        n = MEMBERS;
        for (i = 0; i < n; i++) {
            theta = i * (360 / n) * Math.PI / 180;
            point = new CirclePoint();
            addChild(point);
            point.defaultX = viewManager.cx + radius * Math.cos(theta);
            point.defaultY = viewManager.cy + radius * Math.sin(theta);
            pointList.push(point)
        }
        draw();

        /**/
        var timer:Timer = new Timer(1000,1);
        timer.addEventListener(TimerEvent.TIMER, timerHandler);
        timer.start();

    }

    private function draw():void {
        var i:uint;
        var n:uint;
        var point:CirclePoint;
        var g:Graphics = this.graphics;
        g.clear();
        g.beginFill(0x000000)
        n = pointList.length;
        for (i = 0; i < n; i++) {
            point = pointList[i];
            if (i == 0) {
                g.moveTo(point.x, point.y);
            }
            else {
                g.lineTo(point.x, point.y);
            }
        }

    }

    private function init(event:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        //
        layout();
    }
}
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;

class CirclePoint extends Sprite {
    private var M:Number = 1;
    private var U:Number = 0.01;
    private var _defaultX:Number = 0;
    private var _defaultY:Number = 0;
    private var _forceX:Number = 0;
    private var _forceY:Number = 0;
    private var _vx:Number = 0;
    private var _vy:Number = 0;
    public function CirclePoint() {
        if(stage)init(null);
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }
    public function onEnterFrame():void
    {
        vx += (_forceX/M) - U * vx;

        vy += (_forceY/M) - U * vy;
        x += vx;
        y += vy;

    }

    private function init(event:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        //
        layout();
    }

    private function layout():void {
        /*
        var g:Graphics = this.graphics;
        g.beginFill(0xff0000);
        g.drawCircle(0,0,2);
        */
    }

    public function get vx():Number {
        return _vx;
    }

    public function set vx(value:Number):void {
        _vx = value;
    }

    public function get vy():Number {
        return _vy;
    }

    public function set vy(value:Number):void {
        _vy = value;
    }

    public function get forceX():Number {
        return _forceX;
    }

    public function set forceX(value:Number):void {
        _forceX = value;
    }

    public function get forceY():Number {
        return _forceY;
    }

    public function set forceY(value:Number):void {
        _forceY = value;
    }

    public function get defaultX():Number 
    {
        return _defaultX;
    }

    public function set defaultX(value:Number):void 
    {
        _defaultX = value;
        this.x = _defaultX;
    }

    public function get defaultY():Number 
    {
        return _defaultY;
    }

    public function set defaultY(value:Number):void 
    {
        _defaultY = value;
        this.y = _defaultY;
    }
}