Making textures with noise functions

To modify the appearance of a bitmap, you can apply a noise effect to it, using either the noise() method or the perlinNoise() methods. A noise effect can be likened to the static that appears on an untuned television screen.

To apply a noise effect to a a bitmap, use the noise() method. This method applies a random color value to pixels within a specified area of a bitmap image.

This method accepts five parameters:

The following example creates a bitmap image and applies a blue noise pattern to it:

import flash.display.Bitmap;
import flash.display.BitmapData;

var myBitmap:BitmapData = new BitmapData(250, 250,false, 0xff000000);
myBitmap.noise(500, 0, 255, BitmapDataChannel.BLUE,false);
var image:Bitmap = new Bitmap(myBitmap);
addChild(image);

If you want to create a more organic-looking texture, use the perlinNoise() method. The perlinNoise() method produces realistic, organic textures that are ideal for smoke, clouds, water, fire, or even explosions.

Because it is generated by an algorithm, the perlinNoise() method uses less memory than bitmap-based textures. However, it can still have an impact on processor usage, slowing down your Flash content and causing the screen to be redrawn more slowly than the frame rate, especially on older computers. This is mainly due to the floating-point calculations that need to occur in order to process the perlin noise algorithms.

The method accepts nine parameters (the first six are required):

The following example creates a 150 x 150 pixel BitmapData object that calls the perlinNoise() method to generate a green and blue cloud effect:

import flash.display.Bitmap;
import flash.display.BitmapData;

var myBitmapDataObject:BitmapData = new BitmapData(150, 150, false, 0x00FF0000);

var seed:Number = Math.floor(Math.random() * 100);
var channels:uint = BitmapDataChannel.GREEN | BitmapDataChannel.BLUE; 
myBitmapDataObject.perlinNoise(100, 80, 6, seed, false, true, channels, false, null);

var myBitmap:Bitmap = new Bitmap(myBitmapDataObject);
addChild(myBitmap);

Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000248.html