Lets make some (perlin) noise!

This thread sort of continues from this one but concentrates on some of the funky stuff we can do with the new Flash 8 perlin noise function, like create clouds, wood, water and other cool new things.

Edit: Please experiment and add your creation! You can find a playground .fla a couple of posts down…

Here’s a perlin noise generated displacement map warping an image:

import flash.display.BitmapData;
import flash.geom.Point;
import flash.filters.DisplacementMapFilter;
import flash.filters.DropShadowFilter;
Stage.scaleMode="noScale";
// Perlin noise variables, I encourage you to play around with these...
var baseX              :Number = 200;
var baseY              :Number = 200;    
var nOctaves           :Number = 1; 
var randomSeed         :Number = Math.random()*10;
var bStitch         :Boolean = false;
var bFractalNoise      :Boolean = true;
var nChannels          :Number = 1;
var bGreyScale      :Boolean= false;
// Offset array for perlin function
var p1 = new Point(45, 34);
var p2 = new Point(50, 60);
perlinOffset = new Array(p1, p2);
// Create the bitmapdata we are going to change with the perinNoise function        
bmp = new flash.display.BitmapData(400,300,true,0x00000000);

onEnterFrame = function (){
    //    change the values in the perlinOffset to animate each perlin layer
    perlinOffset[0].y-=2;
    perlinOffset[0].x-=2;
    perlinOffset[1].x+=1;
    perlinOffset[1].y+=1;
    //    apply perlin noise to our bitmapdata
    bmp.perlinNoise(baseX, baseY, nOctaves, randomSeed, bStitch, bFractalNoise, nChannels, bGreyScale, perlinOffset);
    //
    //    Uncomment the following line to see the generated perlin noise
    //_root.attachBitmap(bmp, 1, "auto", true);
    //
    //    Now use the bitmapdata in bmp as a base for the distortion
    dmf = new DisplacementMapFilter(bmp, new Point(0, 0), 1, 1, 20, 20, "color");
    //    and apply it to our pic (instance name sourcePic)
    sourcePic.filters = [dmf];
}