Course Home | Homework | Lab Open Hours | Programming | Schedule & Lecture Notes | Submit | Turing Access

Saint Louis University

Computer Science 150
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2006

Dept. of Math & Computer Science

Programming Assignment 09

Recursive Pyramid

Due: 8:00pm, Monday 11 December 2006


Contents:


Collaboration Policy

For this assignment, you must work individually in regard to the design and implementation of your project.

Please make sure you adhere to the policies on academic integrity in this regard.


Overview

The goal of this assignment is to create a Pyramid class using structural recursion. The high-level technique should be quite similar to that use for creating a Bullseye class in the book, and that code could be used closely as a model for this assignment.

The most signigifant difference between the two goals involves the treatment of the reference point. The reference point for our bullseye was the center of the bullseye. By this convention, the reference point for the inner part of a bullseye coincides with the reference point for the complete bullseye (in fact, it also coincides with the reference point of each Circle instance we use).

For a pyramid, we want you to support the use of the bottom-middle point of the pyramid as the reference point. An example of the pyramid is shown here.

The black dot is not actually part of the pyramid, but just a visual representation of the placement of the pyramid's reference point. When thinking recursively, you will have to accomodate for the placement of the smaller pyramid on top of the bottom level.


Interface

Please support the following public specifications:

Your pyramid automatically inherits other behaviors such as move, rotate and scale from the Drawable class. You should not need to explicitly implement any of those methods, but their behavior will be dependent upon your correct treatment of the concept of a pyramid's reference point. You should check that those methods work with your class.


Unit Testing

The first figure shown above was created with the following simple unit test.
if __name__ == "__main__":
    paper = Canvas(250,250)

    refPointImage = Circle(2, Point(125,225))
    refPointImage.setFillColor('black')
    refPointImage.setDepth(-1)
    paper.add(refPointImage)

    tower = Pyramid(8, 200, 'skyBlue')
    paper.add(tower)
    tower.move(125, 225)

    raw_input("Press return to continue")
Continuing with this test, executing
    tower.rotate(30)
    tower.scale(0.5)
    raw_input("Press return to continue")
should result in the following image.

Note carefully that the reference point of the pyramid remains fixed with those transformations.


Submitting Your Assignment

You should create a new file, Pyramid.py, which contains all of your own code. This file must be submitted electronically.

You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments.

Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.


Grading Standards

The assignment is worth 10 points.


Extra Credit

Implement an additional method, addLevel() which adds one additional level to the bottom of the pyramid (essentially lifting up the existing position and placing a new, wider rectangle upon the reference point). The geometry of that new level should be consistent with the existing pattern.


Michael Goldwasser
Last modified: Tuesday, 05 December 2006