Saint Louis University |
Computer Science 1300
|
Dept. of Math & Computer Science |
In an earlier assignment, Artist, you created an animation which included several animals. At that time, you relied on the use of the class, Layer, to manipulate your animal as a single coherent unit, rather than as a scattered collection of individual shapes. We saw several advantages in that representation of an animal, such as being able to easily move the animal in the scene.
That use of the class Layer was a step in the right direction, but this time we would like to go a step further, having you create and document a new class which represents your specific animal.
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.
For the sake of discussion, let's suppose that my original Artist submission has generated an animation which included several monkeys. Presumably my code included some 30-40 lines of code specifically for modeling the monkey. I probably instantiated various shapes to represent the arms, legs and tail of the monkey, as well as instantiating a new Layer to represent the monkey as a whole. Then the body parts were added to the layer, and the layer was added to the canvas.
Suppose that I were proud of my representation of a monkey and that I wanted to add more monkeys into my scene, or better yet, I wanted to allow other people to conveniently add my monkeys into their own animations. I might accomplish this by simply making the 30-40 lines of code which I had used available to others, verbatim, for inclusion in other places. But a much better design, in the spirit of object-oriented programming, would be to define a new class, named Monkey, containing the necessary code. Then, others could use this new class with minimal effort, just as they had used the more primitive shapes. For example, an artist might simply specify:chimp = Monkey() chimp.move(80,120) paper.add(chimp) chimp.move(0,20) chimp.scratch()
This is our goal. But to be able to define a class that fits into the
cs1graphics framework, we must use inheritance. For this assignment,
we ask that you define your animal class as a direct child of
the Drawable class (as demonstrated in the text with the
second implementation of the Car class in Chapter 9.4,
and with the Mailbox class in Chapter 9.6).
Therefore, we might start our class definition
using syntax such as:
from cs1graphics import *
class Monkey(Drawable):
...
This already allows our Monkey class to inherit many useful behaviors such as move, scale, rotate, and setDepth. However, we will be responsible for providing a low-level implementation of the _draw method that renders the object, and for any other new behaviors that we wish to add to the class (such as scratch). Presumably, new instance variables will be added to manage the various graphical components that comprise our object.
There are three distinct directions of work which are required for your submission.
In this assignment description, we have been using the discussion of a class Monkey purely for example. Your project should involve the development of a new class to represent your own choice of animal, most likely an animal used in your original Artist project (though you are free to change your mind).
Please adhere strictly to the following minimum requirements for the development of such a class:
You will need to write a constructor which appropriately initializes a newly created animal.
You may decide whether to allow additional parameters when calling the constructor which effect the initial settings for your animal.
You must implement _draw to describe the rendering of your animal, given its current state. Please note well that the layering effect for your drawable is explicitly determined by the order in which you draw the individual components (not by the "depth" attribute of those components).
Think carefully about the geometry from the perspective of the user. That is, if they execute, chimp.moveTo(100,100), hopefully the monkey is moved visually to that location with a meaningful reference point. That is, perhaps the bottom of the foot is moved there, or the nose, but it should not be that the monkey is placed halfway across the screen. In similar respect, rotate and scale are based upon the notion of the reference point.
By default, your newly constructed drawable has a reference point of (0,0), so you should design the geometry of all of your graphical components based on the assumption that (0,0) is the reference point.
All monkeys are not alike! The point of such a class is not simply to make precise clones of an animal, but to allow reasonable variance as well. For example, I might allow a user to change the eye color of a monkey, the tail thickness, the positioning of the arms, the direction of the face.
Specifically, you must define at least three new (and distinct) methods which are appropriate for customizing your chosen animal.
For someone else to know how to use your class, you must provide sufficient documentation. For this, we would like you to use docstrings, as described in earlier work. Specifically, please ensure that:
You provide a docstring to begin the class definition, which gives an overview of the class as a whole.
Any method which you create should begin with an appropriate docstring, giving an overview of the behavior, as well as explicit descriptions of any parameters or return values.
The constructor documentation should give sufficient explanation of the initial geometry so that a user could properly place on of these instances into a scene.
Here, the goal is to show how your class could be used by
another. So provide a construct of the form:
if __name__ == '__main__':
as the final thing in your source code, where the body of the
construct demonstrates the use of your class.
Your animation for this assignment does not need to correspond to the precise animation you created in the original Artist assignment. However, we would like your new animation to satisfy the following requirements:
Demonstrate the use of each new method introduced in your class.
Display at least four distinct animals from your new class, making sure that the properties vary among those animals.
You should create a single file, appropriately named, 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 40 points. Those points will be apportioned approximately as:
I'll know it when I see it.