Your task it to write a program PTree.cpp with a recursive function pTree() and a main() program that calls the recursive function. You may write a recursive helper function that pTree() calls rather...

Your task it to write a program PTree.cpp with a recursive function pTree() and a main() program that calls the recursive function. You may write a recursive helper function that pTree() calls rather than making pTree() itself recursive. Your program shall take two command-line arguments L and N (in that order): ˆ L The length of one side of the base square (double) ˆ N The depth of the recursion (int). You should implement a class PTree that derives from sf::Drawable (or one of its subclasses). You can then have it draw itself to your main window. The sf::RectangleShape and sf::ConvexShape classes are both good ways to draw a square. Note that the SFML libraries expect angles to be in degrees, but the standard math libraries expect radians. You can use the M_PI constant in the library to help convert between radians and degrees. Also, the sf::Shape subclasses use the upperleft corners of their bounding boxes as their origin rather than their centers, which aects rotation transforms. You can use sf::Shape::setOrigin() to change this behavior. You should create an SFML window that is sized appropriately for your nal image. A large value for L should not cause the image to spill over the boundary of your window and a small value should not cause most of the window to be empty space.


PS3: Recursive Graphics (Pythagoras Tree) Due: Monday, March 20, 11:59pm In this assignment, you will write a program that plots a Pythagoras tree as illustrated below. The Pythagoras tree is named after the Greek mathematician Pythagoras because each triple of the touching squares encloses a right triangle, in a con�guration traditionally used to depict the Pythagorean theorem. It is a plane fractal constructed from squares invented by the Dutch mathematics teacher Albert E Bosman in 1942. In 1957, Bosman published a book on Het wondere onderzoekingsveld der vlakke meetkunde (�the wonderous exploration �eld of plane geometry�) that contained a description of the Pythagorean tree. If the largest square has a size of L×L, the entire Pythagoras tree �ts snugly inside a box of size 6·L×4·L. 1 Details Your task it to write a program PTree.cpp with a recursive function pTree() and a main() program that calls the recursive function. You may write a recursive helper function that pTree() calls rather than making pTree() itself recursive. Your program shall take two command-line arguments L and N (in that order): ˆ L The length of one side of the base square (double) ˆ N The depth of the recursion (int) Base square Iteration 1 1 https://en.wikipedia.org/wiki/Pythagoras_tree_(fractal) https://en.wikipedia.org/wiki/Pythagoras https://en.wikipedia.org/wiki/Pythagorean_theorem https://en.wikipedia.org/wiki/Fractal Iteration 2 Iteration 3 You should implement a class PTree that derives from sf::Drawable (or one of its sub- classes). You can then have it draw itself to your main window. The sf::RectangleShape and sf::ConvexShape classes are both good ways to draw a square. Note that the SFML libraries expect angles to be in degrees, but the standard math libraries expect radians. You can use the M_PI constant in the library to help convert between radians and degrees. Also, the sf::Shape subclasses use the upper- left corners of their bounding boxes as their origin rather than their centers, which a�ects rotation transforms. You can use sf::Shape::setOrigin() to change this behavior. You should create an SFML window that is sized appropriately for your �nal image. A large value for L should not cause the image to spill over the boundary of your window and a small value should not cause most of the window to be empty space. 2 Math Here is some help with the mathematics of the Pythagorean tree. ˆ Each step involves drawing two smaller Pythagorean trees. ˆ If the parent square has side S than the two child squares have side S · cos(θ) and S · sin(θ). ˆ If θ = 45 deg then cos(θ) = sin(θ) = √ 2 2 and the two squares will be the same size. If you are doing the extra credit, the two squares will be of di�erent sizes. 2 3 Extra Credit You can earn extra credit by making use of multiple colors in your tree. Additionally, you can adapt the tree to take an additional parameter denoting the angle of the inner triangle (make sure that it has a default of 45 deg). You can also add other reasonable features, such as animation. If you do any of the extra credit work, make sure to describe exactly what you did in Readme-ps3.md. 4 What to turn in Your make�le should build a program named PTree which takes two command line arguments L and N (in that order). Submit a tarball to Blackboard containing: 3 ˆ Your main.cpp ˆ Your PTree.cpp and PTree.hpp. ˆ The make�le for your project. The make�le should have targets all, PTree, lint and clean. Make sure that all prerequisites are correct. ˆ Your Readme-ps3.md that includes 1. Your name 2. Statement of functionality of your program (e.g. fully works, partial functionality, extra credit) 3. Any other notes ˆ Any other source �les that you created. ˆ Any images, fonts, or other resources used ˆ A screenshot of program output Make sure that all of your �les are in a directory named ps3 before archiving it and that there are no .o or other compiled �les in it. 5 Grading rubric Feature Points Comment Core Implementation 10 Full & Correct Implementation 1 Draws the base square 2 Draws child squares 2 Squares placed to form a right triangle. 2 Size of triangles matches expected parameters 1 Recurses to the correct depth. 1 Has proper orientation 1 Sizes window to �t image -2 Non-recursive implementation Make�le 1 1 Has targets PTree, lint, all, and clean Screenshot 1 Readme 1 Complete Extra Credit 3 +1 Uses multiple colors at di�erent levels of the tree +2 Implements variations of the Pythagoras tree with di�er- ent angles +1 Other reasonable extension. Penalties -2 Linting problems -1 Submission includes .o �les -1 Submission not in a directory named ps3 -10% Each day late Total 14 4 Details Math Extra Credit What to turn in Grading rubric
Mar 21, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here