Flow Field with Perlin Noise

It was a rainy Sunday and I found myself playing around with perlin noise for a couple of hours.

The idea was to create a simple flow field using the BitmapData perlinNoise method, and use this to influence the movement of autonomous agents. There is no complex vector math or steering behaviours, just some simple logic for how a particle or agent reacts to the current pixel it is positioned over.

Despite its simplicity, by changing parameters such as the level of offset per frame or the x and y frequency, it is possible to create some interesting effects which resemble the movement of flocking birds, shoals of fish or indeed more fittingly for this time of year; panicking Christmas shoppers desperately hunting for gifts.

At each update step, an agent will grab the value of the pixel it is on top of and alter its trajectory based on the brightness of the pixel. Throw in some variance relating to how strongly an individual agent will react to this value and some interesting patterns begin to emerge.

The basic logic I’m using in this demo is as follows:

// Get the pixel the agent is over
var pixel:uint = noiseBitmap.getPixel( agent.x, agent.y );

// Find the brightness of the pixel
var brightness:Number = pixel / 0xFFFFFF;

// Set the angle and the speed according to brightness
var speed:Number = brightness * agent.speed;
var angle:Number = brightness * 360 * Math.PI / 180;

// Update the agent's position / rotation
agent.x += Math.cos( angle ) * speed;
agent.y += Math.sin( angle ) * speed;
agent.rotation = brightness * 360;

Feel free to download the source code and start tweaking the many variables. Adding further life to the agents by introducing collision or allowing additional individual traits beyond simply speed and wander might be one option worth exploring.

Download: Perlin Noise Flow Field

Have fun!…

Posted on 14 Dec 2008
28 Comments
4 Trackbacks

Meta

Perlin Noise Flow Field was posted on December 14th 2008 in the category Lab / Actionscript 3.0, Code, Flash, Lab, Open Source and tagged; , , , , , , .

You can Leave a comment.

Twitter <follow>

February 7th 2012 - 5:37pm

RT @_leonardsouza_: 37signals to stop developing for IE8 » http://t.co/wL6dtZSg

Discussion

32 Responses to Perlin Noise Flow Field

1 2 3

Leave a Reply

Pingbacks / Trackbacks

  1. 3 years ago Weekly Shared Items - 19. December, 2008 « toxin 2.0

    [...] Perlin Noise Flow Field [...]

  2. 2 years ago mostly a codeBlog » Webcam Flow field in Flash

    [...] was lurking about over at Justin Windle’s blog Soulwire, wish my blog had an alter ego with a cool name.. It was a bit to dark, the background is [...]

  3. 1 year ago suche einfaches partikelsystem (schwarm) mit dynamischer anzahl - Flashforum

    [...] haste dir schonmal FLINT angeschaut? oder hier ein nettes perlin noise flow field cheers, sal __________________ NKUNITED.DE – FLASH [...]

  4. 7 months ago Aerodynamik mit AS3 Ideen? - Flashforum

    [...] [...]

  1. subblue 3 years ago
  2. PlasticBit 3 years ago

    Great stuff – Perlin noise is such a useful generator for so many things!

    Reply to this comment

  3. tf 3 years ago

    rahh beautifull (i cant remember where i saw this kind of effect few days ago, if i catch it, i’ll tell you)

    i guess simply adding a brightness halo under mouse cursor could do some interesting interactive effect, like making the agents flee ? only with bitmap operation… nice :)

    i’ve also seen some experiments of ppls mixing this kind of effect with 3D, this gives ideas …
    http://vimeo.com/1128712
    http://vimeo.com/692779 (opengl)

    Reply to this comment

  4. Soulwire 3 years ago

    Nice! Cheers for the links TF, I love the 2nd one in particular :)

    3D is definately the next step, and I like the idea of using other bitmap effects to encourage different kinds of movement. Just need a few more rainy Sundays!

    Reply to this comment

  5. nitzan 3 years ago

    I am risking sounding like a true novice(which i am in advanced AS tbh) but getting a 1046 when trying to test the file.

    1046: Type was not found or was not a compile-time constant: MovieClip.

    Reply to this comment

  6. Soulwire 3 years ago

    I’m not certain why you would be receiving that error in this instance, but check that the MovieClip class is being imported.

    import flash.display.MovieClip;

    Are you compiling from the Flash IDE?

    Reply to this comment

  7. nitzan 3 years ago

    yeah, compiling in flash. that seemed to solve it . thanks.

    Reply to this comment

  8. MHAQS 3 years ago

    Good one there Justin. You kinda beat me to a CG version of something similar. Although, I might not be able to beat Robert Hodgin(flight404.com) at Nervo, but the technique you demonstrated is approximately the same used by him but with some exceptions including Boid Behavior.

    If you haven’t already seen it: http://www.nervo.tv (This work is full of inspiration).

    Reply to this comment

  9. Soulwire 3 years ago

    @Nitzan

    Good stuff, glad you got it sorted!

    @Mohammad

    Yeah, Nando is the man! So too is Robert, I love his work – I heard him talk at FOTB 07 and he mentioned the Perlin Noise technique, it’s a useful method. I’m looking forward to a spare hour when I can implement 3D.

    Hope papersteer is going well

    Reply to this comment

  10. MHAQS 3 years ago

    Sure, I’ll be looking forward to the 3D version. I’ve been busy with my job lately and I have tons of stuff to update :(. I branched PaperSteer into pure ActionScript 3 and PV3D, and I might upload the two branches soon. Papervision was giving me a hard time with frame rates because I had to rewrite the whole drawing routine from scratch as it uses constant redrawing of meshes. All in all, PaperSteer is coming off well. It has all the plug-ins running now with no memory leaks (as far as I tested eek…) and it works pretty fast.

    Let’s hope I could find some extra time to write about it and upload the build.

    Reply to this comment

  11. Soulwire 3 years ago

    Re. being too busy to get those self initiated projects finished – I know what you mean and definitely sympathise!

    Sounds like you’re having a nightmare with PV3D. Have you looked at using native AS3 in FP10 for the meshes (I presume the meshes are for the sake of the demo and not intrinsic to the engine, or does the core of PaperSteer handle rendering too?). Is this to do with implementing your own camera?

    I had a look in November at the repository but didn’t see the new branch – I’ll check it out now though. Keep up the good work mate :)

    Reply to this comment

  12. MHAQS 3 years ago

    Re: Sounds like you’re having a nightmare with PV3D. Have you looked at using native AS3 in FP10 for the meshes (I presume the meshes are for the sake of the demo and not intrinsic to the engine…

    To start, the repository has been updated with the two branches. The documentation has been uploaded as well. You can check it now Justin ;). Your work gave me motivation to upload it.

    Sorry for spamming your blog:

    Yes, I thought that I should handle the drawing routine through the native FP10 API but then I remembered I wanted this to be done using PV3D, no matter what. This was supposed to be a PV3D King entry and I was sure I would get the first place but…. oh well. The papersteer core library does not handle the drawing routine but the Demo and Plugins do as they do in the original version.

    And thanks once again for inspiring me…

    Reply to this comment

1 2 3