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 Kihara 18 Jun 2011
/**
 * Copyright Kihara ( http://wonderfl.net/user/Kihara )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/plZX
 */

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    [SWF(backgroundColor=0, width=500, height=500)]
    public class flasn_ex3_5 extends Sprite
    {
        private var data:Array=[];
        public function flasn_ex3_5()
        {
            //ウィンドウのサイズが変わってもFlashのサイズを変えない
            stage.scaleMode = StageScaleMode.NO_SCALE;
            //原点をちゃんと左上にする
            stage.align = StageAlign.TOP_LEFT;
            
            for(var i:int=0;i<100;i++){
                var graph:Graph=new Graph(Math.random()*10+5,0,0,Math.random()*40+10,Math.random()*0xFFFFFF);
                graph.x=Math.random()*500;
                graph.y=Math.random()*500;
                graph.vx=Math.random()*10-5;
                graph.vy=Math.random()*10-5;
                graph.vr=Math.random()*10-5;
                data.push(graph);
                addChild(data[i]);
            }
            trace(stage.width,stage.height);
            trace(stage.stageWidth,stage.stageHeight);
            
            addEventListener(Event.ENTER_FRAME,onEnterFrame);
        }
        public function spring(g1:Graph,g2:Graph):void{
            var d:Number,ax:Number,ay:Number,ar:Number,k:Number=0.0001;
                d=Math.sqrt((g1.x-g2.x)*(g1,x-g2.x)+(g1.y-g2.y)*(g1.y-g2.y));
                if(d<100){
                   ar=(g1.vr-g2.vr)*k;
                   ax=(g1.x-g2.x)*k;
                   ay=(g1.y-g2.y)*k;
                   //g1.al+=0.2;
                   g1.vr+=ar/g1.r2;
                   g1.vx+=ax/g1.r2;
                   g1.vy+=ay/g1.r2;
                   g2.vr+=-ar/g2.r2;
                   g2.vx+=-ax/g2.r2;
                   g2.vy+=-ay/g2.r2;
                }
        }

        
        public function onEnterFrame(e:Event):void{
            for(var s:int=0;s<data.length-1;s++){
                for(var t:int=s+1;t<data.length;t++){
                    spring(data[s],data[t]);
                }
            }
            for(var i:int=0;i<data.length;i++){
                data[i].move();
                if(data[i].x< -data[i].r2){
                    data[i].x=stage.stageWidth+data[i].r2;
                }
                else if(data[i].x>stage.stageWidth+data[i].r2){
                    data[i].x= -data[i].r2;
                }
                if(data[i].y< -data[i].r2){
                    data[i].y=stage.stageHeight+data[i].r2;
                }
                else if(data[i].y>stage.stageHeight+data[i].r2){
                    data[i].y= -data[i].r2;
                }
            }
        }
    }
}
import flash.display.Sprite;

class Graph extends Sprite{
    public var vx:Number;
    public var vy:Number;
    public var vr:Number;
    public var r2:Number;
    private var c2:Number;
    private var radius:Number;
    
    private function bou(num:int):void{
        var odd:Array=[];
        var even:Array=[];
        
        for(var i:int=0;i<num;i++){
            if(i%2==0)
                even.push(i*(2*Math.PI/num)+radius);
            else if(i%2==1)
                odd.push(i*(2*Math.PI/num)+radius);
        }
        
        graphics.lineStyle(2,c2);
        if(num%2==0){
            graphics.moveTo(r2*Math.cos(even[0]),r2*Math.sin(even[0]));
            for(var k:int=even.length-1;k>=0;k--){
                graphics.lineTo(r2*Math.cos(even[k]),r2*Math.sin(even[k]));
            }
            graphics.moveTo(r2*Math.cos(odd[0]),r2*Math.sin(odd[0]));
            for(k=odd.length-1;k>=0;k--){
                graphics.lineTo(r2*Math.cos(odd[k]),r2*Math.sin(odd[k]));
            }
        }
        else if(num%2==1){
            var arrays:Array=even.concat(odd);
            graphics.moveTo(r2*Math.cos(arrays[0]),r2*Math.sin(arrays[0]));
            for(var n:int=arrays.length-1;n>=0;n--)
                graphics.lineTo(r2*Math.cos(arrays[n]),r2*Math.sin(arrays[n]));
        }
    }
    
    public function Graph(num:int,_x:Number,_y:Number,r:Number,color:Number){
        vx=_x;
        vy=_y;
        r2=r;
        c2=color;
        radius=Math.random()*180/Math.PI;
        bou(num);
    }
    
    public function move():void{
        this.x+=vx;
        this.y+=vy;
        this.rotation+=vr;
    }
}