# Assignment 2: Trees and DXF Files

Watch this brief clip of Dan Garcia graphically demonstrating recursion in BYOB (Build Your Own Blocks), a variant of Scratch:

## Instructions

1. Here is Python code inspired by Dan's "vee" program. Try running it. If you need to install Python first, see the Software Setup page for instructions.

2. Here is Python code that generates the outline of a tree that can be laser cut. It also generates a DXF file. But it uses only one terminal shape: a square. Note: this code requires the dxfwrite package. If you need to install dxfwrite on your computer, see the Software Setup page for instructions.

3. View your generated DXF file in DraftSight to check it for correctness. You may need to do View -> Zoom -> Fit in order to center the figure in the DraftSight graphics window.

4. Modify the treegen code by adding three new terminal shapes. One of these must be a ring (donut). Note: the inner ring of the donut must be a different color so that it can be cut before the tree outline. You must use an arc primitive to draw your arc; do not try to approximate it with a polygon. The other terminal shapes can be a five-pointed star, a hexagon, an arrowhead, or whatever you like.

5. Note: the Tkinter canvas and the DXF canvas use different coordinate systems. Both the scaling and the positive angle direction are different. To help you convert between the separate coordinate systems, we've created a helper function named 'dxf_angle' that accepts as input the angle you would have used to draw in Tkinter and returns the angle you should use to draw in DXF.

6. Now engage your creativity: you can change the size or number or angles of the branches, set minimum and maximum depth values for the tree, have branch thickness vary with depth, or do whatever else you like to make this project your own. But you cannot use this freedom to "dumb down" the assignment; you still must have at least four different terminal shapes, at least one of them must involve an arc, and at least one must involve a hollow shape. (The donut satisfies both criteria.)

7. Make two trees on the laser cutter, one with stand type A and one with stand type B. Each tree must have at least 5 terminal nodes. Share plastic with your classmates so that the trees can be of different colors.
Here is an example of a tree structure a student created in an earlier instance of this course:

Click for larger version.

## What to Hand In

• Hand in your Python code and your two DXF files via AutoLab.
• Post a picture of your assembled two-component tree to Piazza in the thread provided for that purpose.
• Also bring your assembled tree to class on the due date to show off.

## Grading

• 7 points for correct Python code
• 2 points for generating trees with at least 5 terminal nodes and complementary slots, correctly colored
• 1 point for cutting the plastic and posting a picture of the assembled tree to Piazza

Back to 15-294 course home page

Last modified: Wed Nov 4 01:34:40 EST 2015