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: 分散&整列

Get Adobe Flash player
by kevinlin 24 Jun 2012
    Embed
/**
 * Copyright kevinlin ( http://wonderfl.net/user/kevinlin )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nNrd
 */

// forked from yuugurenote's 分散&整列
package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.Point;

    [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]
    public class AS120623_01 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var max:Number=400;
        public var isExplode:Boolean=true;
        public var myArray:Array = new Array();
        public var mySet:Array = new Array();
        public var myPos:Array = new Array();
        public var _myCircle1:myCircle1;
        public var smax:Number = 0.1;
        public var smin:Number = 0.005;
        public var acc:Number = 1.1;
        public var speedx:Number = smax;
        public var speedy:Number = smax;

        public function AS120623_01() {            
            for (var i:Number=0; i<max; i++) {
                _myCircle1=new myCircle1();
                _myCircle1.x=Math.random()*sw;
                _myCircle1.y=Math.random()*sh;
                addChild(_myCircle1);
                myArray.push(_myCircle1);
                mySet.push( new Point(i%20*10+140,Math.floor(i/20)*10+140));
                myPos.push(new Point(Math.random()*sw,Math.random()*sh))
            }

            stage.addEventListener(MouseEvent.MOUSE_DOWN,xDown);
            addEventListener(Event.ENTER_FRAME,xEnter);
        }
        public function xDown(e:MouseEvent):void {
            if (isExplode) {
                //speed_min();
                isExplode=false;
            } else {
                speed_max();
                isExplode=true;
            }
        }
        public function xEnter(e:Event):void {
            if (isExplode) {
                for (var j:Number=0; j<max; j++) {
                    myArray[j].x += (myPos[j].x - myArray[j].x)*speedx;
                    myArray[j].y += (myPos[j].y - myArray[j].y)*speedy;                
                }
                speed_down();
            } else {
                for (var i:Number=0; i<max; i++) {
                    myArray[i].x += (mySet[i].x - myArray[i].x)*speedx;
                    myArray[i].y += (mySet[i].y - myArray[i].y)*speedy;
                }
                speed_up();
            }
        }
        public function speed_max():void {
            speedx = smax;
            speedy = smax;
        }
        public function speed_min():void {
            speedx = smin;
            speedy = smin;
        }
        public function speed_down():void {
            if(speedx>smin) speedx /= acc;
            if(speedy>smin) speedy /= acc;
        }
        public function speed_up():void {
            if(speedx<smax) speedx *= acc;
            if(speedy<smax) speedy *= acc;
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;
class myCircle1 extends Sprite {
    public var _r:Number;
    public function myCircle1() {
        this.graphics.beginFill(0xCCCCCC,1);
        this.graphics.drawCircle(0,0,5);
        this.graphics.endFill();
    }
}