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 a Python program that takes an HPGL file for a gear template and outputs a DXF file for the laser cutter. We don't actually care about HPGL in this assignment, but you can read through the code to learn how to produce a DXF file.

    • To run the hpgl2dxf demo code (and to complete this assignment) you will need to install the dxfwrite package if it's not already present on your machine (e.g., if "import dxfwrite" fails). See the Software Setup page for instructions.

  3. Write your own code to recursively generate a tree like Dan does and produce a DXF file so you can cut the tree from plastic. Note that Dan's original code draws tree branches as single lines; you'll have to draw pairs of parallel lines to produce branches of non-zero width. Your code should also display the lines on the screen so you can debug your contour generation, and to help you select the most interesting trees to cut. The two sample programs above will get you started.

  4. A note about units: HPGL coordinates are in thousands of an inch. Tkinter coordinates are in whole pixels (positive integers). DXF can use several types of units, as specified by a parameter in the HEADER section, but the Rabbit Laser ignores this and always assumes millimeters. Therefore, your code should calculate in millimeters and do a coordinate conversion to derive integer pixels for TKinter.

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

  6. Go a step further and modify your code to generate trees that can fit together at right angles using the same kind of slots we created for the iPad stand we built in class. To do this, you should modify the drawbase function to create a base with a slot in it. The base must be wide enough to prevent the tree from falling over if it's lopsided. Note that the garcia.py program already takes an optional argument indicating whether the tree should use stand type A or stand type B, just like the iPad stand.

  7. Now engage your creativity: you could change the shapes of the terminal nodes, or the size or number or angles of the branches. Perhaps set minimum and maximum depth values for the tree. Or do whatever else you like to make this project your own. See the example trees below.

  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 are some examples of trees students created in a previous course, when we did not have the base and slot requirement:

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 Monday to show off.
  • Everything is due by Monday, Nov. 10.

Grading

  • 7 points for correct Python code
  • 2 points for generating trees with at least 5 terminal nodes and complementary slots
  • 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: Sat Nov 8 19:20:20 EST 2014