Comp 360 Lab 2 : Affine Graphics

Due Monday, 28 September 2009, 11:59 PM

Overview

In this project you will implement the CODO (COnnect the DOts) language for affine graphics. Using this language, you will render simple and complex two dimensional shapes. You will also generate fractals using iterated function systems.
This project is due at 11:59 PM on Monday, September 28. It is worth 100 points.
For this lab, you must work with a different partner than the one you worked with in lab 1. As soon as possible, send an email with your partner's name and username to powei.feng@rice.edu. If you have trouble finding a partner, let us know and we will try to pair you up.

Specification

The user interface for this program is similar to the interface in your turtle program. The program will parse and execute commands entered by the user at the command line. In addition, the program will respond to certain keys, as indicated below.
The first portion of the lab involves implementing the basic constructors of the CODO shapes. Higher-level constructors should be implemented in terms of simple constructors. For example, a polygon is created by applying rotation to an initial point. You will get no credit for turning in a turtle-based implementation of any command.
The global coordinate system is set up so that the origin lies in the center of the program window, the x-axis increases horizontally to the right, and the y-axis increases upward.
Your program accepts one optional command-line argument, a string specifying the name of a file. The file will be executed as a script (see the section "Script Files," below). Under Windows, opening your program by dragging a file onto the program's icon will pass the name of the file as an argument to your main() routine.

The CODO Language

CODO Data Types

There are four types of objects (or data types) that are specified in CODO:
Most of the commands listed below involve creating, manipulating, naming, and drawing these data types. Any object of any data type can have a name. Points and lines can be drawn on the screen, but vectors and transformations cannot.

The CODO Namespace

There is a single CODO namespace shared by all data types. Each name the user defines is associated with a unique object. Once defined, a named object cannot be modified or removed from the namespace, except through the clearNames command. In particular, if a name exists in the namespace, a new object may not be associated with this name (until the namespace is cleared).
Names are not case-sensitive, so point1 is the same name as Point1. You will not be required to implment the CODO namespace functionality.

CODO Constants

Two constants are defined in CODO. These names cannot be modified or removed from the CODO namespace.

CODO Command Syntax

The commands that your program must respond to are similar in format to the turtle commands of lab 1. As in lab 1, command tokens are separated by one or more blank spaces.
There are two kinds of CODO commands: utility functions and constructor functions. Utility functions do not return data; instead, they cause some kind of change to the program's state, such as drawing new geometry. Constructor functions create a new CODO object. (Note that constructor functions are used exclusively as arguments to utility functions or other constructor functions.) You are not required to implement the utility functions.
All numeric arguments passed to commands should be treated as doubles, except for parameters that must be integers (such as the number of edges or the fractal level). Arguments that are CODO data types, such as points, may be given either as names from the CODO namespace or as constructor functions.

CODO Utilities

If you do not use the framework, you will need to write the code to support these functions. If you are using the framework, remember whitespace separates all tokens.

Basic CODO Commands and Utilities

Drawing commands

Constructor Functions (100 Points Total)

Geometry Fundamentals (5 Points)

Affine Transformations (15 Points)

Simple Shapes (15 Points)

Simple Operators (15 Points)

Fractals (25 Points)

For each fractal command given below, k specifies the level of iteration and basecase is the object used to initiate the iteration. The basecase must be a named set of lines or points or a constructor function for a set of points or lines. Fractal figures should be centered on the origin and scaled to fit within the window.

Pretty Pictures (25 Points)

Create new constructor functions or script files for interesting and unique geometry of your own. Be creative. You should document how to produce your pictures in your README file.
For full credit, you need to create at least five interesting pictures. At least two of these should be new fractal commands. The others may be new commands or interesting script files.

Notes

Other Requirements

Hints

Script Files

The commands given above to draw a basic Sierpinski gasket probably look tedious. Nobody wants to spend a lot of time defining points and vectors, but CODO only provides one point (C) and one vector (W), from which all other points and vectors must be derived. One solution is to collect a series of commonly used definitions into a script file.
There are two ways to load a script file: as a command-line argument, and through the load command. The general rule that command tokens are separated by one or more blank spaces extends to the script file format. The Sierpinski gasket example given above might look as follows in a script file:
 set ( myVec  transform ( W compose ( scale ( C 50 ) rotate ( C 90 ) ) ) )
 set ( myPoint transform ( C  translate  ( myVec  ) ) )
 set ( myTri polygon ( C myPoint 3 ) )
 set ( mySierp gasket ( 3 .5 2 myTri ) )
 draw ( mySierp )

If you are using the framework, there should be one command per line and the entire command should be contained in that line. Additionally, the ability to comment out lines has been provided - any line that starts with the character '#' will be ignored.

What To Turn In

Create the directory lab2. This directory should contain your source code and all files needed to build your program in Visual Studio (or a CMakeList.txt file). Also include a README file containing:
Only one partner per group should turn in code.
If your project will be completed late, email your labby and let him know.
Please follow the instruction on the COMP 360 home page to submit your lab.



File translated from TEX by TTH, version 3.85.
On 15 Sep 2009, 10:10.