This lab will follow examples from the wonderful book "The Algorithmic Beauty of Plants (ABOP)". This book is available free at the link, and is well worth perusing. We will be generating plants using the grammars and approach summarized in Figure 1.24, "Examples of plant-like structures generated by bracketed OL systems", from that book. For this problem, you will implement a class called PLANT. The class has two methods: (1) An initializer. The function will take an initial state (string), a generator (dictionary), the number of generation iterations to run (n) and an angle delta (deltaTheta) for changing direction while drawing. When the class is initialized, you must run the generator with the specified parameter, and make the resulting string available as a member variable PLANT.str . To run the generator, every character in the input string is either (a) replaced by the corresponding value from the generator dictionary if it is in the generator dictionary, or (b) copied directly to the output string if it is not in the generator dictionary. This is repeated n times. The resulting string is stored in the PLANT.str member variable. For example: myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25) myPlant.str =='abaababa' --> True and myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20) myPlant.str=='FF[+F[+X]F[-X]+X]FF[-F[+X]F[-X]+X]+F[+X]F[-X]+X' --> True (2) A drawPlant method (no parameters). The draw method works as follows: start with a currentPt=(200,0). This is the current draw location. start with a theta of 90 degrees any alphabet character e.g. ('A','b','X') moves forward one step, drawing a line from currentPt to nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta)). ***This is the only drawing code you should use. Do not call plt.show() or run any other test code except in your testing __main__ block ***: plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='black') After drawing, set currentPt=nextPt. '[' saves current drawing state [currentPt, theta] on a stack (see Python Stack for details). ']' resets the currentPt and theta to the most recently saved drawing state from the stack. '+' increases the current drawing angle theta by deltaTheta degrees. '-' decreases the current drawing angle theta by deltaTheta degrees. The sample output provided in the file abop_1_24_a.png downloadable here was generated using the grammar given in figure 1.24(a) of ABOP. The sample image was generated using plt.axis('image') as well. Your plot from e.g. the main section does not need to look exactly like the sample png - just be sure to only use the plot command as given above. If in doubt, check with zyBooks.

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter2: Introduction To Systems Architecture
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question

11.30 Final Project -- Algorithmic Beauty of Plants

 

This lab will follow examples from the wonderful book "The Algorithmic Beauty of Plants (ABOP)". This book is available free at the link, and is well worth perusing. We will be generating plants using the grammars and approach summarized in Figure 1.24, "Examples of plant-like structures generated by bracketed OL systems", from that book.

For this problem, you will implement a class called PLANT. The class has two methods:

(1) An initializer. The function will take an initial state (string), a generator (dictionary), the number of generation iterations to run (n) and an angle delta (deltaTheta) for changing direction while drawing. When the class is initialized, you must run the generator with the specified parameter, and make the resulting string available as a member variable PLANT.str .

To run the generator, every character in the input string is either (a) replaced by the corresponding value from the generator dictionary if it is in the generator dictionary, or (b) copied directly to the output string if it is not in the generator dictionary. This is repeated n times. The resulting string is stored in the PLANT.str member variable.

For example:

myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25) myPlant.str =='abaababa' --> True

and

myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20) myPlant.str=='FF[+F[+X]F[-X]+X]FF[-F[+X]F[-X]+X]+F[+X]F[-X]+X' --> True

(2) A drawPlant method (no parameters).

The draw method works as follows:

  • start with a currentPt=(200,0). This is the current draw location.

  • start with a theta of 90 degrees

  • any alphabet character e.g. ('A','b','X') moves forward one step, drawing a line from currentPt to nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta)).

***This is the only drawing code you should use. Do not call plt.show() or run any other test code except in your testing __main__ block ***:

plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='black')

After drawing, set currentPt=nextPt.

  • '[' saves current drawing state [currentPt, theta] on a stack (see Python Stack for details).

  • ']' resets the currentPt and theta to the most recently saved drawing state from the stack.

  • '+' increases the current drawing angle theta by deltaTheta degrees.

  • '-' decreases the current drawing angle theta by deltaTheta degrees.

The sample output provided in the file abop_1_24_a.png downloadable here was generated using the grammar given in figure 1.24(a) of ABOP.

The sample image was generated using plt.axis('image') as well. Your plot from e.g. the main section does not need to look exactly like the sample png - just be sure to only use the plot command as given above. If in doubt, check with zyBooks.

250
200
150
100
50
200
250
Transcribed Image Text:250 200 150 100 50 200 250
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning