Previous Page
Next Page

Recipe 10.7. Embossing

Problem

You want to emboss a display object.

Solution

Apply a convolution filter with an emboss matrix.

Discussion

An emboss effect causes the edges of a surface to appear raised or recessed. A emboss matrix has a positive value in the center with values on the left and the opposite values on the right arranged in a symmetrical pattern. They determine the amount of embossing applied. The greater the value, the more embossing is applied. The values on the top and bottom of the center column determine whether the embossing causes a raised or raised effect, and they also need to be symmetrical. The following describes a generic emboss matrix:

a   d   -c
b   e   -b
c  -d   -a

The following is an example of a basic emboss matrix:

-1   1   1
-1   1   1
-1  -1   1

The following 3x3 matrix defines a good general purpose emboss effect when applied with a convolution filter:

-2  -1   0
-1   1   1
 0   1   2

The following example applies the preceding emboss effect to a display object. Note that a divisor isn't necessary, since the values are symmetrical and the center value is 1:

sampleSprite.filters = [new ConvolutionFilter(3, 3, [-2, -1, 0, -1, 1, 1, 0, 1, 2])];

See Also

Recipe 10.6


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)