Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
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.
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.
Please support the following public specifications:
The constructor should support the syntax,
Pyramid(numLevels, height, color)
The height describes the overall height of the pyramid as a whole (not of the individual levels of the pyramid). The initial width of the bottom of the pyramid should implicitly be the same length as the height of the pyramid (just as we did when drawing pyramids in Chapter 4).
_draw(canvas)
As with the bullseye, you will not be able to visualize the pyramid unless you implement this method.
setColor(color)
This can be used to change the interior color of the pyramid.
changeWidth(factor)
This can be used to change the aspect ratio of our pyramid. The height of the pyramid should be unchanged by this call, but the width of each level of the pyramid should be multiplied by the given factor. As an example, here is the figure which corresponds to a call of changeWidth(0.5) on the original pyramid shown above.
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.
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.
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.
The assignment is worth 10 points.
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.