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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education