MCS-177 Project 8: L-Systems (Fall 2016)

Start: Tuesday 11/2; (Extended) deadline: Thursday 12/1, by 11:55pm


Overview

In this project, you will experiment with L-systems, which use grammatical rules to generate strings that can be interpreted as instructions for drawing fractals. The required portions of this project include only a very modest amount of programming; the emphasis is instead on thinking about what grows and what stays the same as the string of instructions is expanded.

Unlike projects 6, 7, 9 and 10, you are to do this project individually.

Warm-up exercises (not to be turned in)

  1. Read Section 9.4.1 L-systems p. 318-320, then do Exercises 9.20 and 9.22.

  2. Read Section 9.4.2 Automatically Expanding Production Rules p. 321-322, then do Exercises 9.27 for levels 3 and 4.

  3. Read Section 9.4.3 More Advanced L-systems p. 323-326. In particular, read the code for the lsystem function in Listing 9.8 p. 325.

Specific tasks

  1. Download the file containing the lsystem function and the other functions it relies on. Save this file in your directory as lsystems.py. Throughout this project, you will be modifying this file. Your Task#1 is to use the lsystem function to draw a level 4 Koch curve with each line segment having a length of 6 units. You should set the initial heading to 0 (that is, horizontal, pointed to the right) and set the initial position to a point on the negative x axis that causes the curve to be centered horizontally. For example, if you were doing a level 1 curve, you would use an initial position of (−9, 0) because the curve causes a net forward motion of 18 units.

  2. Do exercise 9.30 (p. 327): Modify the drawLS function to support the G operation, which allows the turtle to go forward without drawing a line.

  3. For Task#3, consider the L-system given in exercise 9.31 (p. 327).

  4. Do exercise 9.32 (p. 327): Use the L-system given there and the specified angle of 25 in order to create a drawing that looks like a plant growing upward. You will need to use some trial and error to choose appropriate values for the depth as well as the initial position and heading and the length of the individual line segments. Your goal is to produce an interesting drawing that stays within the available space.

  5. Change the applyProduction function so that the dictionary of rules maps each symbol not to a single replacement string, but to a list of alternative strings, one of which is randomly chosen each time a replacement needs to be performed. (You can randomly choose an element of a list using the choice function within the random module.) As in the original version of applyProduction, some symbols may not be listed in the rules at all, in which case they should be left unchanged.

  6. Pick two sets of L-system rules that are not described in the textbook or this project. Write Python expressions that will generate drawings of L-systems following your rules.

Extra Credit

Submitting your work

You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following file:

Before submitting your work, read through the grading criteria to make sure that you have fulfilled all requirements for receiving full credit.

Grading

You will earn one point for each of the following accomplishments (with those after 20 being extra credit):

  1. You produced a drawing of a level 4 Koch curve, not necessarily centered but correct in all other regards.

  2. You correctly centered the level 4 Koch curve so that it is symmetrical about the y axis.

  3. You modified the drawLS function so that it recognizes the letter G.

  4. Your modification to the drawLS function includes moving the turtle forward the appropriate distance.

  5. Your modification to the drawLS function does not do any extraneous drawing.

  6. Your modification to the drawLS function does not prevent subsequent letters from doing their proper drawing.

  7. You chose an appropriate (non-zero) angle for task 3, so that when F is replaced, the replacement still leaves the turtle's heading unchanged.

  8. Your code for task 3 is appropriate in all regards other than the turning angle.

  9. Your description of the drawing from task 3 is sufficient that someone who has read our textbook would understand what the drawing looks like, at least so far as its general form goes. (That is, what sort of fractal is it?)

  10. Your description of the drawing from task 3 provides some specific facts about the drawing's appearance that stem from the particular way you used the L-system, rather than from the L-system and turning angle. (For example, how detailed is the fractal? How large is it, perhaps described relative to the window? How is it oriented?)

  11. Your description of the drawing from task 3 is written in college-level English.

  12. Your code for task 4 produces a drawing using the specified L-system.

  13. Your drawing for task 4 has appropriate specifics so that a plant-like form grows upward.

  14. Your drawing for task 4 has appropriate specifics so that it stays within the window.

  15. You modified applyProduction to randomly choose a replacement from a list of alternatives.

  16. Your modified version of applyProduction still leaves alone symbols that don't have rules.

  17. You show appropriate code for trying out the example stochastic L-system.

  18. You show appropriate code for trying out a L-system of your choice.

  19. You show appropriate code for trying out a L-system of your choice. (a different L-system from #18)

  20. Your procedures are not unnecessarily complex

  21. You wrote a correct contract for sortList
  22. Your sortList sorts the list in ascending order using recursion.