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

Archimedes' principle

ふりょーく
Get Adobe Flash player
by Susisu 09 Jun 2011
    Embed
package {
    //なんか微妙なので作り直し中
    import flash.display.Sprite;
    import flash.display.Graphics;
    import flash.events.Event;
    public class FlashTest extends Sprite {
        private var boxes:Vector.<Box>;
        private const s:Number=50;
        private const t:Number=5;
        private const g:Number=9.8;
        private const r:Number=1.0;
        public function FlashTest() {
            boxes=new Vector.<Box>();
            boxes.push(new Box(20,0,60,0xffcf80,0.5));
            boxes.push(new Box(200,0,60,0x80c0ff,0.91));    //ice
            boxes.push(new Box(380,0,60,0xc0c0c0,2.7));    //aluminium
            var l:int=boxes.length;
            for(var i:int=0;i<l;i++){
               addChild(boxes[i]);
            }

            
            var g:Graphics=graphics;
            g.beginFill(0x80ffff);
            g.drawRect(0,200,465,265);
            g.endFill();
            addEventListener(Event.ENTER_FRAME,enterFrameHandler);
        }
        private function enterFrameHandler(event:Event):void{
            var l:int=boxes.length;
            for(var i:int=0;i<l;i++){
                boxes[i].x+=boxes[i].vx/t;
                boxes[i].y+=boxes[i].vy/t;
                
                if(boxes[i].y+boxes[i].size>465){
                    boxes[i].y=465-boxes[i].size;
                    boxes[i].vy*=-0.50;
                }
                
                var f:Number=0;
                f+=boxes[i].density*Math.pow(boxes[i].size/s,3)*g;
                if(boxes[i].y+boxes[i].size>200){
                    if(boxes[i].y<200){
                        f-=r*(boxes[i].y+boxes[i].size-200)/s*Math.pow(boxes[i].size/s,2)*g;
                    }
                    else{
                        f-=r*Math.pow(boxes[i].size/s,3)*g;
                    }
                    f-=boxes[i].vy*0.10;
                }                
                
                boxes[i].vy+=f/boxes[i].density*Math.pow(boxes[i].size/s,3);
            }
        }

    }
}
import flash.display.Sprite;
import flash.display.Graphics;
class Box extends Sprite{
    public var size:Number;
    public var density:Number;
    public var vx:Number;
    public var vy:Number;
    public function Box(x:Number=0,y:Number=0,size:Number=40,color:uint=0x000000,density:Number=1){
        var g:Graphics=graphics;
        g.beginFill(color);
        g.drawRect(0,0,size,size);
        g.endFill();
        this.size=size;
        this.density=density;
        vx=0;
        vy=0;
        this.x=x;
        this.y=y;
    }

}