Perlin noise in as3

When I started doing processing I fell in love with the Perlin noise function. A little while later Flash 8 came out including noise. But I was a bit disappointed in their noise implementation, since it was only (and still is) a BitmapData function (without falloff). Perlin noise can be used for much than just bitmaps. Of course you could just getpixel the generated noise data but that only gives you integer noise values.
So I did what I always wanted to do but never did (because I thought it would be too difficult): wrote a Perlin noise class. Actually I just ported the main part from Ken Perlin’s improved noise. But I still had to implement octaves, falloff and seed. The function now looks like Perlin.noise(x:Number,y:Number,z:Number):Number. I’d also like to insert a fourth dimension in there. So we would have three spacial- and one time dimension.

Flash does calculate it’s noise about a hundred times faster than this class does. So if you’re ok with integer input values for noise you might be better off getpixeling the noise data than using this class. But I don’t claim to be the god of code either; there is probably a lot that could be done to optimize this class. So if you have any suggestions please comment.

In the next example the bitmaps are created with the new noise function and setpixel. I’ve set the octaves horizontally and the falloff vertically. The first row has the same falloff as the second but a different seed for each bitmap. The x and y positions of the little ball are also controlled by Perlin noise with an octave of two and a falloff of one half. Click to view example
Here’s the download containing the above example. Things should become clear from the source code. If you still have any questions feel free to comment.
Here’s another example with multiple balls. Each cycle the balls gravity is calculated by feeding it’s position into the noise function. The collision in this example is managed by APE

There was a slight error in the falloff calculation. I’ve updated the download (version 1.2).

-another update-
Mario Klingemann made some optimizations. The class is now almost twice as fast! I haven’t had time to update my downloads yet so in the meantime get the optimized version here

Posted in actionscript, flash
Tagged , ,


  1. Evan
    Posted 2008/01/05 at 00:36 | Permalink

    Hi Ron,

    Nice site…thanks for your informative posts…

    I have been trying to implement Seb’s z slicing technique to animate the noise while using your 3D Perlin Noise class but to no avail. Your source example has the Perlin.noise(x, y, z) static method return a Number …. when I onEnterframe with a recall to Perlin.noise with a change in the z parameter I just get a really jerky anim and nowhere near as good looking as Seb’s.

    Seb animated 3dperlin noise involves a z-slicing of a “blob” of noise. Any tips how do to that?

    Is there a way to just call Perlin.noise once and then slice from there?

    May you please provide some more tips or source code.

    thanks again,

    Evan from Canada

  2. Sjeiti
    Posted 2008/01/07 at 17:04 | Permalink

    Hi Evan,

    The noise class is as fast as I could get it, so it’s probably better for single point calculations (like the APE example) than entire blobs.
    Sebs blobs calculates only one slice per frame and animates those over the planes. What could also speed it up is a low number of octaves and a not too big a bitmap.

    have fun,

    Ron from the Netherlands

  3. Posted 2008/07/11 at 19:14 | Permalink

    I followed your invitation and optimized the class a bit. So this new version is almost twice as fast:

  4. Posted 2011/04/17 at 16:50 | Permalink

    Great article! I wanted to ask you about the “scale” input on the second example. Where in the equation does that get worked into?

    I identify this as the main part of the noise function
    s += n((x+iXoffset)*fFreq,(y+iYoffset)*fFreq,(z+iZoffset)*fFreq) * fPers;
    Where would I fit scale into? It looks like its where fPers should go but I’m not sure.

14 Trackbacks

  1. [...] thankfully this nice chap Ron Valstar has just converted it into [...]

  2. [...] only does 2d. Seb Lee-Delisle has been doing some experiments using a custom Perlin Noise class, by Ron Valstar. I decided to roll my own Now, what I’ve come up with has a few problems – first of all you can’t [...]

  3. [...] fall, built with two different Flash implementations of 3D Perlin noise. The one on the right uses Ron Valstar’s Perlin class (as does Seb’s demo), which appears to be a faithful port of Ken Perlin’s Improved [...]

  4. [...] cool nonetheless. Another little newsflash in that first post is that Mario Klingemann optimized my original Perlin Noise class. It’s now almost twice as fast! Funny how two simple things (type casting and unrolling [...]

  5. [...] todays post on nodename about Perlin Clouds and Frocessing I came across Ron Valstar’s AS3 version of Ken Perlin’s Improved Noise reference implementation which I must have missed last [...]

  6. By Fingerprints by Anatoly Zenkov « byK on 2010/03/04 at 05:46

    [...] note: Free Perlin noise class for AS3.0 from Sjeiti. Share and [...]

  7. [...] is a BitmapData function only. Therefore, remedy comes quite a long time ago (2007) in the form of Ron Valstar and in an even more optimized perlin noise version by Mario Klingemann. Fair enough so far! But [...]

  8. By Sjeiti :: noise r us « on 2010/05/10 at 13:40

    [...] sjeitiauthors: Ron Valstar and Mario Klingemanspeed: 60 [...]

  9. [...] note: Free Perlin noise class for AS3.0 from [...]

  10. [...] Optimized Perlin Noise seen in the community before. I think the route of that source began with Ron Valstar’s AS3 version (@Sjeiti), then with a optimized version by @quasimondo, and further optimized with a haxe-version [...]

  11. By noise r us - Sjeiti on 2012/07/03 at 09:30

    [...] sjeitiauthors: Ron Valstar and Mario Klingemanspeed: 60 [...]

  12. By Perlin Noise and Frocessing - Sjeiti on 2012/07/03 at 16:07

    [...] cool nonetheless. Another little newsflash in that first post is that Mario Klingemann optimized my original Perlin Noise class. It’s now almost twice as fast! Funny how two simple things (type casting and unrolling [...]

  13. [...] created the clouds with noise. To get “3D slices” I used a 3d Perlin noise generator by Ron Valstar. The regular Flash noise class lets you generate noise on X and Y axis, this allows you to move in [...]

  14. [...] thankfully this nice chap Ron Valstar has just converted it into [...]

Post a Comment