You want to create random organic effects, such as clouds, smoke, or water.
Use the perlinNoise() method of the BitmapData class.
Like the noise() method, perlinNoise() creates random patterns on a bitmap. However, Perlin noise uses an algorithm that produces smooth, organic-looking textures. It was created by Ken Perlin for creating textures in the movie Tron. These textures are perfect for use as explosions, smoke, water, and many other natural-looking effects, and since they are generated by an algorithm, they require much less memory than bitmap-based textures. The usage is as follows:
bitmap.perlinNoise(baseX, baseY, octaves, seed, stitch, fractal, channels, grayscale, offsets);
The first six parameters are necessary; the final three are optional. Since there are so many parameters to consider, let’s create a simple example and then see what each one does. The following code creates a bitmap, applies Perlin noise to it and then displays it:
bitmap = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xff000000); bitmap.perlinNoise(100, 100, 1, 1000, false, false, 1, true, null); var image:Bitmap = new Bitmap(bitmap); addChild(image);
Add this code to a new class, and run it to see a simple Perlin noise pattern. See Figure 8-1 for an example of what you should see. Now you can start changing parameters and see what effect the changes have.
baseY determine the size of the pattern. Here they are set to 100 ...