Difference between revisions of "CSC111 Final Exam 2015b"
Line 3: | Line 3: | ||
<onlydft> | <onlydft> | ||
<br /> | <br /> | ||
+ | =Fractal Orange Tree= | ||
+ | <br /> | ||
+ | [[Image:FractalOrangeTree.png|center|600px]] | ||
+ | <br /> | ||
+ | Write a well documented and organized Python program that will generate a tree ''identical to the tree shown below''. Your program must generate a tree as close as possible to the one shown. You should not reproduce the text in the image; '''just the tree, its colors, its leaves, and its fruit.''' | ||
+ | <br /> | ||
+ | <center>[[Image:FractalTreeWithLeavesAndOranges.png| 600px]]</center> | ||
+ | <br /> | ||
+ | * Make sure your name is included in the header of your program. | ||
+ | * Call your program '''final1.py''' and the image '''finalc.jpg''' or '''finalc.png'''. Submit both to Moodle, in the Final 1 Program and Final 1 Image sections. | ||
+ | * If you need help capturing the final image, please visit [http://www.take-a-screenshot.org/ this page]. | ||
+ | * I used these colors in the program that generated the image above: "red", "orange", "blue", "lightgreen," and "brown". | ||
+ | * Note that the width of the branches are different. If I ask the program to print the width of each branch as it starts drawing the tree, I get this: | ||
+ | |||
+ | width = 19 | ||
+ | width = 17 | ||
+ | width = 15 | ||
+ | width = 13 | ||
+ | width = 11 | ||
+ | width = 9 | ||
+ | width = 7 | ||
+ | width = 5 | ||
+ | width = 3 | ||
+ | width = 1 | ||
+ | ... | ||
+ | |||
+ | * Here is the main() function of the solution program: | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | def main(): | ||
+ | win = GraphWin("Fractal Tree", MAXWIDTH, MAXHEIGHT ) | ||
+ | theta = 0.65 # use 0.02 for tall skinny trees, 0.7 for fat trees | ||
+ | draw_tree(win, | ||
+ | 9, | ||
+ | theta, | ||
+ | MAXWIDTH*0.9, MAXWIDTH//2, | ||
+ | MAXHEIGHT-50, | ||
+ | -math.pi/2, | ||
+ | "brown" ) | ||
+ | |||
+ | win.getMouse() | ||
+ | win.close() | ||
+ | |||
+ | </source> | ||
+ | |||
+ | <br /> | ||
+ | * The variable <tt>trunk_ration</tt> is set to 0.49 in the recursive function. | ||
+ | * You have to figure out how to modify the recursive function to make it display the leaves and the oranges. <font color="magenta">Your program should not generate the leaves or oranges outside the recursive function.</font> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | Good luck! | ||
=Find the Largest Element of a List of Lists= | =Find the Largest Element of a List of Lists= | ||
<br /> | <br /> |