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 />

Using the drawing API<br />

Winding rule names<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

The names refer to a more specific rule that defines how these fills are managed. Positively wound paths are assigned<br />

a value of +1; negatively wound paths are assigned a value of -1. Starting from a point within an <strong>en</strong>closed area of a<br />

shape, draw a line from that point ext<strong>en</strong>ding out indefinitely. The number of times that line crosses a path, and the<br />

combined values of those paths, are used to determine the fill. For ev<strong>en</strong>-odd winding, the count of times the line crosses<br />

a path is used. Wh<strong>en</strong> the count is odd, the area is filled. For ev<strong>en</strong> counts, the area is unfilled. For non-zero winding, the<br />

values assigned to the paths are used. Wh<strong>en</strong> the combined values of the path are not 0, the area is filled. Wh<strong>en</strong> the<br />

combined value is 0, the area is unfilled.<br />

A B<br />

Winding rule counts and fills<br />

A. Ev<strong>en</strong>-odd winding rule B. Non-zero winding rule<br />

Using winding rules<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

These fill rules are complicated, but in some situations they are necessary. For example, consider drawing a star shape.<br />

With the standard ev<strong>en</strong>-odd rule, the shape would require t<strong>en</strong> differ<strong>en</strong>t lines. With the non-zero winding rule, those<br />

t<strong>en</strong> lines are reduced to five. Here is the ActionScript for a star with five lines and a non-zero winding rule:<br />

graphics.beginFill(0x60A0FF);<br />

graphics.drawPath( Vector.([1,2,2,2,2]), Vector.([66,10, 23,127, 122,50, 10,49,<br />

109,127]), GraphicsPathWinding.NON_ZERO);<br />

And here is the star shape:<br />

A B C<br />

A star shape using differ<strong>en</strong>t winding rules<br />

A. Ev<strong>en</strong>-odd 10 lines B. Ev<strong>en</strong>-odd 5 lines C. Non-zero 5 lines<br />

And, as images are animated or used as textures on three-dim<strong>en</strong>sional objects and overlap, the winding rules become<br />

more important.<br />

Last updated 6/6/2012<br />

238

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

Saved successfully!

Ooh no, something went wrong!