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 uly 10 Feb 2009
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    public class Wave extends Sprite {
        private var dx:int;
        private var ty:int;
        private var w:uint;
        private var water:Shape;
        private var old_my:int;
        private var prevMap:Array;
        private var resultMap:Array;
        private var numOfWave:int = 1;
        private var numOfVerts:int = 80;
        private var maxDistance:int = 50;
        private var y0:int = 370;
        private var _txt1:TextField;

   public function Wave() {

       w = stage.width + 200;
       dx =  w / numOfVerts;
       water = new Shape();
       water.graphics.beginFill(0x3366ff,.3);
       water.graphics.drawRect(-200,100,stage.width+800,200);
       addChild(water);
       _txt1 = new TextField();
       _txt1.x = 15;
       _txt1.y = 15;
       addChild(_txt1);
       initialize(1);
    }
    public function onResize():void{
        var background:Sprite = new Sprite();
        background.graphics.beginFill(0xadd4fc, .6);
        background.graphics.drawRect(0,0,550,550);
        var waterbase:Sprite = new Sprite();
        waterbase.graphics.beginFill(0xadd4fc, 1);
        waterbase.graphics.drawRect(0,300,550,250);
        addChild(waterbase);
        addChild(background);
        w = stage.width + 200;
        dx = w / numOfVerts;
    }
    public function initialize(waterLevel:uint):void{
        ty = 300 + 110 * (1 - waterLevel);
        y0 = 370;
        onResize();
        water.x = water.x - 100;
        old_my = water.mouseY;
        prevMap = new Array(numOfWave);
        resultMap = new Array(numOfWave);
        var num3:int = 0;
        while (num3 < numOfWave) {
          prevMap[num3] = new Array(numOfVerts);
          resultMap[num3] = new Array(numOfVerts);
          var num1:int = 0;
          while (num1 < numOfVerts) {
            prevMap[num3][num1] = 0;
            var num2:int = 2 * Math.abs(num1 / numOfVerts - 0.5);
            num2 *= num2;
            resultMap[num3][num1] = 10 * num2;
            ++num1;
          }
          ++num3;
        }
        addEventListener(Event.ENTER_FRAME,draw);
      }

      public function clamp(x:int, min:int, max:int):int{
        return Math.max(min, Math.min(max, x));
      }

      public function draw(e:Event):void{
        _txt1.text = String(water.mouseY);
        y0 += (ty - y0) * 0.1;
        var num11:int = clamp(water.mouseX, 0, stage.width);
        var num10:int = clamp(water.mouseY, 0, 455);
        var num3:int = 0;
        while (num3 < numOfWave) {
          var num2:int = 1;
          while (num2 < numOfVerts - 1) {
            var num8:int = num2 * dx;
            var num7:int = y0 + resultMap[num3][num2];
            var num6:int = num8 - num11;
            var num5:int = num7 - num10;
            var num4:int = Math.sqrt(num6 * num6 + num5 * num5);
            if (num4 < maxDistance) {
              resultMap[num3][num2] += (1 - num4 / maxDistance) * (num10 - old_my) * 0.5 * (num3 + 1) / numOfWave;
            }
            ++num2;
          }
          ++num3;
        }
        old_my = num10;
        var num9:Array = new Array();
        num2 = 0;
        while (num2 < resultMap.length) {
          num9.push(resultMap[num2].concat());
          ++num2;
        }
        num3 = 0;
        while (num3 < numOfWave) {
          num2 = 1;
          while (num2 < numOfVerts - 1) {
            resultMap[num3][num2] = (num9[num3][num2 + 1] + num9[num3][num2 - 1]) * 1 - prevMap[num3][num2];
            resultMap[num3][num2] *= 0.9400000000000001 + 0.01 * num3;
            ++num2;
          }
          ++num3;
        }
        var num12:int = water.height;
        water.alpha = 100 - num12 * 0.1;
        water.graphics.clear();
        water.graphics.moveTo(0, y0);
        water.graphics.beginFill(0xadd4fc,.1);
        num3 = 0;
        while (num3 < numOfWave) {
          num2 = 0;
          while (num2 < numOfVerts) {
            if (num3 % 2 == 1) {
              water.graphics.lineTo((numOfVerts - num2 - 1) * dx, y0 + resultMap[num3][numOfVerts - num2 - 1]);
            } else {
              water.graphics.lineTo(num2 * dx, y0 + resultMap[num3][num2]);
            }
            ++num2;
          }
          ++num3;
        }
        water.graphics.endFill();
        prevMap = num9;
      }
      public function drawMask():void{
        water.graphics.clear();
        var num3:int = 0;
        while (num3 < numOfWave) {
          water.graphics.moveTo(0, y0);
          water.graphics.beginFill(0xffffff, .1);
          var num1:int = 0;
          while (num1 < numOfVerts) {
            water.graphics.lineTo(num1 * dx, y0 + resultMap[num3][num1]);
            ++num1;
          }
          water.graphics.lineTo(w, y0);
          water.graphics.lineTo(w, y0 + 200);
          water.graphics.lineTo(0, y0 + 200);
          water.graphics.endFill();
          ++num3;
        }
      }
    }
}