Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

## Introduction

This project gives you some practice working with a number of skills you will need throughout this project: Squeak in general, Morphic, and basic simulations.

Ask questions here: Summer 2005 Milestone 1 Questions

## Requirements

Make a class FunkyMorph that is a subclass of Morph. Your morph must have the following features:

• It looks like this:
• The bars you see are animated, moving from left to right:
• Whenever the red button is pressed on your morph, the face in the middle of the morph moves and the rest of the morph is redrawn to account for this. like this:
• Whenever the yellow button is pressed on your morph, whether the morph's bars are moving should toggle. If they are moving, they should stop, and if they are stopped, they should start moving again. NOTE: This should be the only way to get the bars moving once they are stopped – other things like picking up the morph and dropping it, clicking to move the face, and resizing the morph, should not cause the bars to move around.
• It must implement a method numBars: that causes the number of revolving bars to change. This should work even if the bars are not currently moving.

All in all, you should implement the following methods:
• initialize - Set things up. Remember to call super initialize or you will really mess up your system! This method should put the face in the middle of the morph, set the number of bars to a reasonable default, and set the bars into motion.
• handlesMouseDown: and mouseDown: - handles moving the face around at toggling whether the bars are moving.
• barWidth - calculates the width of bars to draw
• startOfBar:afterMilliseconds: - calculates where the left edge of a specified bar should be after the specified number of milliseconds have passed. For example, this code:
`morph startOfBar: 2  afterMilliseconds: 2500`
asks where the left edge of bar 2 should be after 2500 milliseconds of bar motion
• step and stepTime - anything you need to happen over and over as time passes
• drawOn: - draw your morph

Finally, you should implement a test case for your bar computations. Write a class method named testBarComputations that tests all of the following and does "self error:" if there are any problems:
1. the barWidth changes depending on the number of bars and the size of the morph
2. the position of the bars changes over time, and as the morph change size and position, and as the number of bars changes.
TA's will check this method; if they break your code, then the test should stop working.

## Hints

DON'T PANIC! Do one step at a time. First get it to draw at all, then get it to redraw correctly when a different time is hard-coded, then get the time to increase slowly as time passes, etc.

The "Programming Morphs" tutorial can help you get started with morphic – it has everything you need to know. You can install it using a Universe browser ("open"... "Universes Browser")

You don't have to draw everything in drawOn:. You can, at your choice, stick other morphs in your morph (using addMorph:) and let them handle some of the drawing for you.

To draw the face, class EllipseMorph may be useful.

Any time you want the system to redraw your morph, you should do self changed.

The assignment does not tell you what instance variables to declare. You need to give your class one instance variable for each thing that the morph wants to "remember" over time...

step gets called at regular time intervals. If you want, you can use this to create your own clock that starts and stops as needed, and updates whenever step is called.

## For Full Credit

You'll get most of the points as long as your funky morph is close. But to get a 100:
1. Bars should not draw past the edge of the morph.
2. You should correctly handle the fractional bars at the left and right edge of the morph; bars shouldn't just disappear when they get close to the right edge, or appear out of nowhere at the left edge.
3. Give your class a class comment.
4. Put your methods into method categories; don't put them all in "as yet unclassified".
5. Give major methods a comment saying what they do. For long method, insert comments explaining what the code does.

• 80 functionality:
• 20 basic drawing
• 5 correct drawing when the morph is resized
• 5 correct drawing of bars at the edge of the morph
• 15 moving face around
• 10 motion of bars
• 10 toggling of bars motion
• 15 varying number of bars (numBars:)
• 10 test case
• 10 style