13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with bitmaps<br />

package<br />

{<br />

import flash.display.Sprite;<br />

import flash.display.Bitmap;<br />

import flash.display.BitmapData;<br />

import flash.display.BitmapDataChannel;<br />

}<br />

public class BitmapNoise1 ext<strong>en</strong>ds Sprite<br />

{<br />

public function BitmapNoise1()<br />

{<br />

var myBitmap:BitmapData = new BitmapData(250, 250,false, 0xff000000);<br />

myBitmap.noise(500, 0, 255, BitmapDataChannel.BLUE,false);<br />

var image:Bitmap = new Bitmap(myBitmap);<br />

addChild(image);<br />

}<br />

}<br />

If you want to create a more organic-looking texture, use the perlinNoise() method. The perlinNoise() method<br />

produces realistic, organic textures that are ideal for smoke, clouds, water, fire, or ev<strong>en</strong> explosions.<br />

Because it is g<strong>en</strong>erated by an algorithm, the perlinNoise() method uses less memory than bitmap-based textures.<br />

However, it can still have an impact on processor usage, slowing down your cont<strong>en</strong>t and causing the scre<strong>en</strong> to be<br />

redrawn more slowly than the frame rate, especially on older computers. This is mainly due to the floating-point<br />

calculations that need to occur to process the perlin noise algorithms.<br />

The method accepts nine parameters (the first six are required):<br />

baseX (Number): Determines the x (size) value of patterns created.<br />

baseY (Number): Determines the y (size) value of the patterns created.<br />

numOctaves (uint): Number of octaves or individual noise functions to combine to create this noise. Larger<br />

numbers of octaves create images with greater detail but also require more processing time.<br />

randomSeed (int): The random seed number works exactly the same way as it does in the noise() function. To get<br />

a true random result, use the Math.random() method to pass a random number for this parameter.<br />

stitch (Boolean): If set to true, this method attempts to stitch (or smooth) the transition edges of the image to<br />

create seamless textures for tiling as a bitmap fill.<br />

fractalNoise (Boolean): This parameter relates to the edges of the gradi<strong>en</strong>ts being g<strong>en</strong>erated by the method. If<br />

set to true, the method g<strong>en</strong>erates fractal noise that smooths the edges of the effect. If set to false, it g<strong>en</strong>erates<br />

turbul<strong>en</strong>ce. An image with turbul<strong>en</strong>ce has visible discontinuities in the gradi<strong>en</strong>t that can make it better approximate<br />

sharper visual effects, like flames and ocean waves.<br />

channelOptions (uint): The channelOptions parameter works exactly the same way as it does in the noise()<br />

method. It specifies to which color channel (of the bitmap) the noise pattern is applied. The number can be a<br />

combination of any of the four color channel ARGB values. The default value is 7.<br />

grayScale (Boolean): The grayScale parameter works exactly the same way as it does in the noise() method. If<br />

set to true, it applies the randomSeed value to the bitmap pixels, effectively washing all color out of the image. The<br />

default value is false.<br />

offsets (Array): An array of points that correspond to x and y offsets for each octave. By manipulating the offset<br />

values, you can smoothly scroll the layers of the image. Each point in the offset array affects a specific octave noise<br />

function. The default value is null.<br />

Last updated 6/6/2012<br />

251

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!