The interpreter project

Create a grammar

  gray line


About me

About shape grammars


gray line

The interpreter project

Set up

Create a grammar

Run a grammar

Get out of trouble

gray line

The Yingzao fashi project

gray line
Contact me

i (at) andrew (dot) li

gray line

Nakata shape 0 Nakata rule

Create a new grammar document
  1. Create a new Rhino document (File / New). This is your grammar document. I usually use the template Small objects / millimeters, although it may not make any difference.

  2. Initialize the Rhino document. This formats the front and sets up the back end. For a Mac:

    1. Run the script. Select Tools / PythonScript / Run. Or, at the command line, enter ‘RunPythonScript’.

    2. Select the ‘initialize’ script. You may have to navigate to ‘package / commands’ first. The system initializes the engine, and asks whether it should initialize the Rhino document as well. Enter ‘y’.

    For Windows:

    1. Open the Python script editor (Tools / PythonScript / Edit).

    2. Open the ‘initialize’, ‘create_rule’, and ‘apply_rule’ scripts. Select File / Open. Navigate to ‘package / commands’, and select each script in turn. The scripts open in the editor. (Try not to change the script. If you do, close the script without saving. More details here.)

    3. Run the ‘initialize’ script. Click the initialize tab. Click the green triangle. The system initializes the engine, and asks whether it should initialize the Rhino document as well. Enter ‘y’.

Create the grammar
  1. Draw the initial shape. This is the shape that will be repeatedly transformed as you apply rules to it. Draw it on the layer ‘Shape 0’ near the origin in the upper right quadrant. Suppose you want to generate a Nakata lattice. Then the initial shape is a grid with a labeled point in each cell. (See upper left image.)

  2. Draw the rule shapes. Draw the left and right shapes of a rule on the ‘Default’ layer below the x-axis. For a Nakata lattice, the left shape is a square with a labeled point. The right shape is a square with the Nakata curve inscribed; there is no labeled point.

  3. Run (On a Mac, run the ‘create_rule’ script as you ran the ‘initialize’ script above.) You will be prompted for:

    1. The left shape;

    2. The reference point of the left shape;

    3. The right shape; and

    4. The reference point of the right shape.

  4. The system will draw the rule in the upper left quadrant on a new layer with a unique name (composed of a long integer). (See upper right image.)

  5. Save the document. This is a Rhino document, so it will have the suffix ‘3dm’. You may want to choose a file name that shows that the file contains a grammar, e.g., ‘nakata_sg.3dm’.

Tips on drawing shapes
  1. The lines must be individual lines. You can draw polygons (e.g., rectangles) and polylines, but explode them into individual lines.

  2. The lines must be maximal: that is, one long line; not several short ones. More technically, collinear lines must not overlap or abut.

  3. The labeled point is an annotation dot (also called text dot) with an associated string (e.g., ‘a’, ‘1’). The string may be empty (‘’).

  4. You are drawing in three dimensions, so you can create three-dimensional shapes. Use the perspective view to check that lines are what you think they are. For instance, a line may appear in the top view to be parallel to the xy-plane, but is not.

  5. You can use scripts to draw shapes. This may help with three-dimensional shapes.

  6. You can often use curves indirectly. Draw the curve; then replace it with lines connecting its control points. New shapes will contain straight lines; replace these with the corresponding curve. You can do this with Python scripts. (One of these lines may fuse with another, in which case you will have to do a bit of surgery to separate it.)

  7. The system draws new shapes and rules above the x-axis. It’s best not to draw anything here. The only exception is the initial shape (see above).

  8. Anything you draw should be below the x-axis, on the default layer or on layers created by you. Don’t use a layer name that begins with ‘shape’ or ‘Shape’.

gray line

This grammar creates the Nakata lattice on the previous page. The initial shape, on the left, consists of a grid with a labeled point in each cell. The rule, on the right, inserts the Nakata curve under a transformation determined by the location of the labeled point. The frames surrounding the left and right rule shapes are not parts of the shapes, but indicate the coordinate system. When all the cells are filled, another rule (not shown) deletes the interior grid.

gray line