Rendering Ellipses with Recursion

   



Key Constructs

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:



   



Fundamentals of SVG Programming. Concepts to Source Code
Fundamentals of SVG Programming: Concepts to Source Code (Graphics Series)
ISBN: 1584502983
EAN: 2147483647
Year: 2003
Pages: 362

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net