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

Chapter 36 Example 15

Get Adobe Flash player
by actionscriptbible 09 Feb 2010
/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8ZkN
 */

package {
  import flash.display.*;
  import flash.events.Event;
  import flash.events.KeyboardEvent;
  public class ch36ex15 extends Sprite {
    protected var bmp:BitmapData;
    protected var octaves:int = 1;
    public function ch36ex15() {
      bmp = new BitmapData(stage.stageWidth, stage.stageHeight);
      var bitmap:Bitmap = new Bitmap(bmp);
      stage.addChildAt(bitmap, 0);
      addEventListener(Event.ENTER_FRAME, onEnterFrame);
      stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    }
    protected function onKeyDown(event:KeyboardEvent):void {
      switch (String.fromCharCode(event.charCode)) {
        case "+": case "=": octaves++; break;
        case "-": case "_": octaves--; break;
      }
    }
    protected function onEnterFrame(event:Event):void {
      bmp.perlinNoise(mouseX, mouseY, octaves, 1, false, false);
      graphics.clear();
      graphics.lineStyle(0, 0xffffff, 0.5);
      graphics.drawRect(0, 0, mouseX, mouseY);
    }
  }
}