Mike T. Henderson

Interactive Design & Art Direction

AS3 Perlin Noise Ripples

Mar 28 2008

Using the same logic from my wave machine, I reworked the code to make an AS3 version. What I learned is that there isn't really any difference with the perlinNoise method from AS2 to AS3.

The perlinNoise Method is constructed as follows:

bitmap.perlinNoise(baseX, baseY, octaves, seed, stitch, fractal, channels, grayscale, offsets);

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
 
// set up perlin Noise Properties
var baseX:int = 200;
var baseY:int = 25;
var octaves:int = 2;
var seed:int = Math.floor(Math.random()*10);
var stitch:Boolean = false;
var fractal:Boolean = true;
var grayScale:Boolean = false;
var channels:int = 1;
var xSpeed:int = 2;
var ySpeed:int = 5;
 
// create bitmapData and bitmap to hold it
var bitmap:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xff000000);
var image:Bitmap = new Bitmap(bitmap);
addChild(image);
 
// create offset
var point1:Point = new Point(0, 0);
var point2:Point = new Point(0, 0);
var offset:Array = [point1, point2];
 
// add onenterframe eventLisener
addEventListener(Event.ENTER_FRAME, onEnterFrame);
 
function onEnterFrame(e:Event):void {
offset[0].x += xSpeed;
offset[1].y += ySpeed;
bitmap.perlinNoise(baseX, baseY, octaves, seed, stitch, fractal, channels, grayScale, offset);
}
4 Posted under: BitmapData

4 Responses

  1. Jay says:

    very nice, thx for sharing!

  2. [...] AS3 Perlin Noise Ripples [...]

  3. Burrows says:

    thx, i like that...thx very much for your tutorial

  4. grabek says:

    dude - that's sooo easy! thanks!

Leave a Reply