Comp 360 Lab 2: Affine Transformations and Fractals in CODO Language, Lab Reports of Computer Graphics

A lab assignment for implementing the codo language for affine geometry and generating fractals using iterated function systems. Students will write code to parse and execute commands, implement basic constructors, and utilize utility functions and constructor functions for geometry and transformations. The document also includes details on codo data types, constants, command syntax, and examples of simple shapes and operators.

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-w5e
koofers-user-w5e 🇺🇸

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Comp 360 Lab 2 : Affine Transformations
Due Monday, 2 October 2006, 11:59 PM
Overview
In this project you will implement the CODO (COnnect the DOts) language for affine
geometry. 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, October 2nd. 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 [email protected]. 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 noted 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 vertically.
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:
Points
Vectors
Lines
Transformations
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Comp 360 Lab 2: Affine Transformations and Fractals in CODO Language and more Lab Reports Computer Graphics in PDF only on Docsity!

Comp 360 Lab 2 : Affine Transformations

Due Monday, 2 October 2006, 11:59 PM

Overview

In this project you will implement the CODO (COnnect the DOts) language for affine geometry. 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, October 2nd. 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 [email protected]. 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 noted 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 vertically.

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:

  • Points
  • Vectors
  • Lines
  • Transformations

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 data 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. This year we will not require you to implement the CODO namespace functionality. Our neighborhood graduate student has provided this for you.

CODO Constants

Three constants are defined in CODO. These names cannot be modified or removed from the CODO namespace. (NOTE: If you attempt to modify these constants, the program will not crash; it will simply print error messages in the command prompt.

C: The point representing the origin of the global coordinate system, with affine coordi- nates C = (0,0,1).

W: The unit vector pointing along the x-axis of the global coordinate system, with affine coordinates W = (1,0,0).

I: The identity transformation, implemented as a 3x3 matrix with 1s on the diagonal and 0s elsewhere. NOTE: If you are using the support framework, you will have to provide the structure for the identity and add it to the environment. This will be discussed in the tutorial sessions.

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. This year if you use the support framework, we will not require you to implement the utility functions. Once again, our neighborhood

Drawing commands

  • lineWidth ( w ) This command causes any lines or points drawn after its execution to have width w, where w is given in number of pixels. Note that w is a double-precision value.
  • color ( r g b ) This command causes any lines or points drawn after its execution to have the color given by the (red, green, blue) triple (r, g, b), where each element is a double-precision value between 0 and 1.
  • draw ( object ) Draw the geometry specified by object. This can be either a name in the CODO namespace, or a constructor function. If object evaluates to a vector or a transforma- tion, nothing is drawn and an error is posted to the program console. (NOTE: Draw will have special functionality for fractals. This will be described later).

Constructor Functions (100 Points Total)

Geometry Fundamentals (5 Points)

  • vector ( P Q ) Construct the vector (Q-P) from points P and Q.
  • line ( P Q ) Construct the line object that connects points P and Q.
  • transform ( X M ) Construct the object created by transforming the object X by the transformation M. X may be either a vector, a point, or a set of lines. The newly constructed object will have the same data type as X.

Affine Transformations (15 Points)

  • translate ( V ) Construct the transformation that translates points by the vector V.
  • rotate ( Q d ) Construct the transformation that rotates points or vectors counterclockwise around the point Q by d degrees.
  • scale ( Q s ) Construct the transformation that scales by a factor of s about the point Q.
  • Nscale ( Q V s ) Construct the transformation that scales from the point Q in the direction of the vector V by the factor s.
  • image ( A B C P Q R ) Construct the affine transformation that maps the points A, B, and C onto the points P, Q, R.
  • compose ( T1 T2 ... Tk ) Construct a new transformation by composing the transformations T1 through Tk. The resulting transformation should be equivalent to transforming first by T1, then by T2, and so on through Tk. This function must be given at least two arguments.

Simple Shapes (15 Points)

  • polygon ( P Q n ) Construct a regular polygon of n sides, centered at point P, with point Q as a vertex.
  • circle ( P r ) Construct a circle centered at point P with radius r.
  • ellipse ( P V a b ) Construct an ellipse centered at point P, with semi-major axis direction V, semi-major axis length a, and semi-minor axis length b.
  • wheel ( P Q n ) Construct a wheel. The arguments are identical to those of the polygon command.
  • rosette ( P Q n ) Construct a rosette. The arguments are identical to those of the polygon command.
  • spiral ( P Q n s d ) Construct a polygonal spiral with n segments, centered at point P, with the first segment joining P to point Q. Each successive arm should be scaled by a factor of s, and the angle between each adjacent spiral segment should be d degrees.

Simple Operators (15 Points)

  • shiftOp ( V k object ) Construct k copies of object, where each successive copy is translated by the vector V. The object, which may be either a named object or a constructor function, must represent a set of lines. If object is of some other data type, an error should be reported to the console.
  • spinOp ( P d k object ) Construct k copies of object, where each successive copy is rotated by d degrees around the point P. As in shiftOp, the object must represent a set of lines, or an error should be generated.
  • scaleOp ( P s k object ) Construct k copies of object, where each successive copy is scaled by a factor of s

The Hangman Fractal, a Fractal Bush, and a Fractal Tree.

Turtle Bump Fractal (15 Points)

  • bump ( C1 C2 ... CN ) Construct a bump fractal using a series of turtle commands from lab 1. These com- mands are of the following form: - forward ( s ) Instructs the turtle to move and draw s steps. - move ( s ) Instructs the turtle to move without drawing s steps. - turn ( d ) Instructs the turtle to turn d degrees counterclockwise. - resize( s ) Instructs the turtle to resize its step size.

This function should create an iterated function system to build an equivalent fractal. Are there any cases where the IFS generates a shape that differs from the output of the corresponding turtle program? If so, why? If not, why not? (These questions should be addressed in your README file).

Pretty Pictures (15 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 four interesting pictures. At least two of these should be new fractal commands. The others may be new commands or interesting script files.

Notes

Your program should exit any time the user presses the escape key.

You should not use any OpenGL commands other than the ones you used in lab 1. OpenGL provides the ability to set up and apply transformation matrices, but you should not use OpenGL for this purpose within this lab. You will need to create your own facilities for composing and applying affine transformations.

There are no commands to define points and vectors by giving their coordinates. You should not extend the command set to allow such definitions. All points and vectors must be derived from the CODO constants by applying transformations. (This is an absolute condition for commands and script files).

Implementation Notes

Lab 2 has a framework that provides the base functionality of the CODO system. There is an environment for CODO in which objects are stored with their corresponding names (if they have them). There are blank class definitions for Polygons, Rosettes, Transformations, etc. It is your responsibility to fill out the definitions of these classes. The Point, Vector, and Line classes have already been populated for you to give you some hints as to how to proceed with your implementation. Each class has a draw method that is used to render itself. All rendering code should be placed in this function for an object type. Assume that this method is only called from the context of the rendering function callback. Each class also has Print and Copy methods that you will have to provide the intelligence for (including the Point, Line, and Vector classes).

One important implementation note, the CODO Namespace has a built in garbage col- lector that deletes objects that are not assigned to a variable name during each idle callback. This is important because when constructors are passed as arguments to other constructors, you must know that the input object will be deleted unless the object is already assigned or is being assigned to a variable name. If some of your classes contain pointers to other data types be sure to use the copy method for the input object(s).

Drawing Fractals

When drawing fractals there is one extra bit of functionality. When the user presses the ‘-’ or ‘+’ keys, the fractals should either decrease or increase their level of rendering. This does not apply to their base cases (so if a child fractal is the base case to a parent fractal then the child will not be affected this functionality). If you are using the framework then this functionality is handled by the incr and decr methods for fractals which you will need to implement.

The keystrokes ‘-’ and ‘+’ can only modify the geometry visible on the screen. Objects in the namespace are not affected.

As an example, consider the following set of commands.

  1. set ( myVec transform ( W compose ( scale ( C 50 ) rotate ( C 90 ) ) ) )
  2. set ( myPoint transform ( C translate ( myVec ) ) )

Only one partner per group should turn in code. The other partner should put a README file in his or her own ~/comp360/lab2 directory that gives their partner’s name and username.

Do not touch the files in your submission directory after the project deadline. If your project will be completed late, email your labby and let him know. Otherwise, he may attempt to grade an incomplete or nonexistent project directory, and the project grade will reflect this.