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
26 Comments
2 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>

March 11th 2010 - 3:26pm

What year am I in? 'Chief exorcist says Devil is in Vatican' (via @RichardDawkins) http://bit.ly/9qqNk8

Discussion

28 Responses to Perlin Noise Flow Field

Leave a Reply

Pingbacks / Trackbacks

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

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

  2. 9 months 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 [...]

  1. Ken 4 months ago

    inspiring stuff.. very nice…

    Reply to this comment

  2. Denzo 3 months ago

    You are lucky there are so many rainy days in England :)

    Reply to this comment