Summary

   



 Download CD Content

Overview

As you may already know, recursion plays an important role in computer science, partly because its expressive power can yield compact and elegant algorithms that are far superior to their iteration-based counterparts. In fact, deceptively simple and succinct recursion-based algorithms can produce surprisingly beautiful graphics images. When producing such images with SVG, though, the cost of doing so often involves greater memory and slower performance. Moreover, there are situations when you can use a simple iterative algorithm that is much faster than an equivalent recursive algorithm; two examples of this scenario involve the calculation of Fibonacci numbers and the factorial value of a non-negative integer.

When you combine recursion with ECMAScript and SVG, the performance can be slower than the Java equivalent by a factor of five or more, despite the fact that Java is an interpreted language. In this chapter, the file names that contain the string 'triangle ' or 'Sierpinski ' are the fastest: they require two or three seconds on a 2GHz Pentium-4 PC. The remaining examples in this chapter are very compute-intensive, and they will probably cause a slower PC to 'hang' or require far too much time to render the SVG contents.

This chapter contains various examples of generating recursion-based SVG graphics images. The first example, which renders a set of nested triangles, contains the necessary logic and ECMAScript code that can be enhanced in order to render a Sierpinski curve that is presented in the second example. All code and images for this chapter can be found on the companion CD-ROM in the Chapter 16 folder.



   



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