|
|
Generating 'midpoint' nested objects that are in the polygon 'family' (in a manner of speaking) rely on the following type of code fragment:
// arrays for inner polygon... newXPts = Array(vertexCount); newYPts = Array(vertexCount); for(var v=0; v<vertexCount; v++) { // clockwise from upper-left vertex... newXPts[v] = (oldXPts[v]+ oldXPts[(v+1)%vertexCount])/2; newYPts[v] = (oldYPts[v]+ oldYPts[(v+1)%vertexCount])/2; }
Recursion is a very useful technique for rendering visually rich and complex patterns that are based on simple geometric objects such as triangles and ellipses.
Performance is always a key factor when you write recursively invoked ECMAScript functions, and in some cases you might need to find an iteration-based equivalent algorithm that produces the desired results.
CD-ROM Library
The folder for this chapter on the book's companion CD-ROM contains the SVG documents that are required for viewing the following graphics images:
|
|