-
var leng:int = 10;
-
for (var i:int = 0, j:int = leng; i <leng; i++, j = leng - i){
-
trace(i, j);
-
}
-
-
/*outputs
-
0 10
-
1 9
-
2 8
-
3 7
-
4 6
-
5 5
-
6 4
-
7 3
-
8 2
-
9 1
-
*/
Looping backwards and forwards.
Looping backwards and forwards.
The above demo's a class that triangulates a polygon given a list of points. To test this snippet you'll need the Pnt and Triangulate Classes, which you can download or copy from below.
Polygon triangulation is useful for lots of things... I first found that I needed it back in my Director days. I wanted to be able to draw a polygon and then extrude it into 3D space - in order to do this I needed to triangulate the polygon that was drawn. Luckily there was an undocumented feature in Lingo that did the triangulation. I'll probably do an extrusion demo soon. I've been looking into this to make the QuickBox2D polygon stuff a little easier.
Download all source and fla here....
Here is the Triangulate class:
... and the Pnt class:
I also found a nice description of the basic technique being employed here.
UPDATE:
This should be obvious, but I was targeting fp9 with this... thus the use of Array instead of Vector.
This is a classic that I've seen all over the place online... found myself needing it today and figured I should post it. It just an easy way to determine if a number is odd or even... I remember originally reading it over at Bit-101.com a few years back...
Two posts today because I think I missed a post recently...
This snippet shows an easy way to find the difference between two angles. The tricky part about doing this is finding the difference between something like 350 and 1 (which should be 11).
Over the years I have done this a few different ways - I needed it for something today and realized that my way was a tad clunky (had a little redundant logic) - So with a quick google search I found a more elegant solution.