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 yuugurenote 17 Aug 2011
    Embed
/**
 * Copyright yuugurenote ( http://wonderfl.net/user/yuugurenote )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jHN2
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import flash.display.DisplayObject;
    [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]

    public class Main110817_01 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var max:Number=30;

        public var _myCircle:myCircle;
        public var _myCircle2:myCircle2;
        public var _myCircle2_Ar:Array=new Array  ;

        public function Main110817_01() {

            //ラインを配置
            _myCircle=new myCircle  ;
            _myCircle.x=sw/2;
            _myCircle.y=sh/2;
            addChild(_myCircle);

            for (var i:Number=0; i<max; i++) {
                _myCircle2=new myCircle2  ;
                _myCircle2.x=Math.random()*sw;
                _myCircle2.y=Math.random()*sh;
                addChild(_myCircle2);
                _myCircle2_Ar.push(_myCircle2);
            }
            addEventListener(Event.ENTER_FRAME,xEnter2);
        }

        public function xEnter2(e:Event):void {
            for (var i:Number=0; i<_myCircle2_Ar.length; i++) {
                var rad:Number=Math.atan2(_myCircle2_Ar[i].y-_myCircle.y,_myCircle2_Ar[i].x-_myCircle.x);
                var dis:Number=Math.sqrt(Math.pow(_myCircle.x-_myCircle2_Ar[i].x,2)+Math.pow(_myCircle.y-_myCircle2_Ar[i].y,2));
                var per:Number=80/dis;
                _myCircle2_Ar[i].x+=per*Math.cos(rad);
                _myCircle2_Ar[i].y+=per*Math.sin(rad);
            }
        }

    }
}
import flash.display.Sprite;
import flash.events.Event;

class myCircle extends Sprite {
    public var radius:Number=10;
    public var speedX:Number=Math.random()*8;
    public var speedY:Number=Math.random()*6;

    public function myCircle() {
        graphics.lineStyle(1,0x999999,1,false,"none");
        graphics.drawCircle(0,0,radius);
        this.addEventListener(Event.ENTER_FRAME,xEnter);
    }
    private function xEnter(e:Event):void {

        this.x+=speedX;
        this.y+=speedY;

        if (this.x+radius>stage.stageWidth) {
            this.x=stage.stageWidth-radius;
            speedX=- speedX;
        }
        if (this.x-radius<0) {
            this.x=radius;
            speedX=- speedX;
        }
        if (this.y+radius>stage.stageHeight) {
            this.y=stage.stageHeight-radius;
            speedY=- speedY;
        }
        if (this.y-radius<0) {
            this.y=radius;
            speedY=- speedY;
        }
    }
}

class myCircle2 extends Sprite {
    public var radius:Number=5;
    public var speedX:Number=Math.random()*2;
    public var speedY:Number=Math.random()*3;

    public function myCircle2() {
        graphics.beginFill(0xCCCCCC,1);
        graphics.drawCircle(0,0,radius);
        graphics.endFill();
        this.addEventListener(Event.ENTER_FRAME,xEnter);
    }
    private function xEnter(e:Event):void {

        this.x+=speedX;
        this.y+=speedY;

        if (this.x+radius>stage.stageWidth) {
            this.x=stage.stageWidth-radius;
            speedX=- speedX;
        }
        if (this.x-radius<0) {
            this.x=radius;
            speedX=- speedX;
        }
        if (this.y+radius>stage.stageHeight) {
            this.y=stage.stageHeight-radius;
            speedY=- speedY;
        }
        if (this.y-radius<0) {
            this.y=radius;
            speedY=- speedY;
        }
    }
}