9.5 Summary

In this chapter, we introduced recursion, a powerful programming technique that allows us to elegantly solve problems by taking advantage of “self-reference.” Fractals are graphically self-referential—that is, they contain smaller versions of themselves. We can implement recursion by simply letting a Python function call itself. Identification of the nonrecursive case, called the base case, is important to make sure that the recursive calls work correctly. Finally, we explored L-systems, which formally denote fractal behavior using a set of grammar rules. A string of symbols can be produced by repeatedly applying these rules. By interpreting this result string as a series of turtle commands, we can draw a fractal.

Key Terms

  • axiom

  • base case

  • call tree

  • fractal

  • grammar

  • Koch curve

  • L-system

  • production rule

  • recursion

  • recursive step

  • symbol

Programming Exercises

  1. 9.1     Modify the lSystem function so that it recursively expands the rules. This will allow you to add a vertical bar ("|") operator that means “go forward,” but with the distance to go forward being scaled according to the depth of the recursion.

  2. 9.2     Research L-systems and find a different set of production rules to implement.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.197.164