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

wave simulation

うーん…
Get Adobe Flash player
by Nos_lkSsvOhB 17 May 2013
/**
 * Copyright Nos_lkSsvOhB ( http://wonderfl.net/user/Nos_lkSsvOhB )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/29uc
 */

// forked from horiuchi's flash on 2010-5-4
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    [SWF(backgroundColor = 0xDCDBB8)]
    public class Main extends Sprite {
        private var si:Number, om:Number;
        private var c:Number;
        private var de:Number;
        private var max:Number;
        private var Vp:Number;
        private var p:Number;
        private var dt:Number;
        private var dx:Number;
        private var s_x:Number;
        private var s_y:Number;
        private var t:Number;
        private var xx:Number;
        private var u:Array;
        private var ef:Sprite;
        public function Main() {
            //u_t_x
            c=0.2;
            //delay
            de=0.99;
            max=100;
            Vp=0;
            //pitch
            p=4;
            dt=0.05;
            dx=0.05;
            s_x=30;
            s_y=232;
            this.u=new Array();
            for(t=0;t<3;t++){
                u[t]=new Array();
            }
            for(xx=0;xx<max;xx++){
                u[0][xx]=Vp;
            }
            for(xx=0;xx<max;xx++){
                u[1][xx]=Vp;
            }


            ef=new Sprite();
            this.addChild(ef);

            this.ef.addEventListener(Event.ENTER_FRAME,onEnter);
        }
        private function onEnter(event:Event):void {
            if(mouseX>=0*p+s_x && mouseX<max*p+s_x){
                u[1][int((mouseX-s_x)/p)]=(mouseY-s_y)/p;
            }
            for(xx=0;xx<max;xx++){
                if(xx==0)
                    u[2][0]=u[1][0];
                else if(xx==max-1)
                    u[2][max-1]=u[1][max-1];
                else
                    u[2][xx]=c*(u[1][xx+1]-2*u[1][xx]+u[1][xx-1])/dx*dt+2*u[1][xx]-u[0][xx];
            }
            this.graphics.clear();
            this.graphics.lineStyle(1,0,100);
            this.graphics.moveTo(s_x,u[2][0]+s_y);
            for(xx=1;xx<max;xx++){
                this.graphics.lineTo(xx*p+s_x,u[2][xx]+s_y);
            }
            for(xx=0;xx<max;xx++){
                u[0][xx]=de*u[1][xx];
                u[1][xx]=de*u[2][xx];
            }
        }
    }
}