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:


  1. This file 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. This file 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.

  3. The treegen program requires the dxfwrite package. Just unzip it into the directory containing your own code.

  4. View your generated DXF file in Inkscape to check it for correctness.

  5. 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. And you must correctly calculate the endpoints of the arc; you are not allowed to fudge it by hand-tuning a constant. The other terminal shapes can be a five-pointed star, a hexagon, an arrowhead, or whatever you like.

  6. 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.

  7. 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.)

  8. 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.


  • 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: Mon Nov 7 21:28:33 EST 2016