[Pharo-project] Help with Rotating a Box

Andrew P. Black black at cs.pdx.edu
Fri Sep 25 18:52:13 EDT 2009

I've been playing with a Morphic implementation of "Joe the box" for  
an intro programming course.  It shouldn't be hard, right?

The problem is rotation.  It's easy to rotate a polygon morph, but I  
can't get a TextMorph (for the name) to rotate and stay centered.  My  
next attempt (attached), was to use a transformation morph.  This  
almost works, except that when rotating from a non-manhattan  
orientation, smurfs get left on the display.

The code is attached.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CS520-MorphicBoxes.st
Type: application/octet-stream
Size: 1571 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20090925/59b9eea0/attachment.st>
-------------- next part --------------

I try doing this in a workspace:

joe := NamedBoxMorph2 new.
joe name: 'Fred'.
joe openInWorld.
joe color: Color lightBlue.
joe turn: -45.
joe turn: 45.

Do the

	joe turn: +/- 45

a few times.  Bits of the rectangle are left on the display.  Is this  
a bug in morphic, or a bug in my code (more likely)?  Is tehre an easy  

The critical method from the filein is this one, I think:

BoxMorph2 >> initialize
	"initialize this BoxMorph so that it looks like a Box in BoxWorld"
	| rectangle b |
	super initialize.
	smoothing := 3.
	b := Rectangle origin: 85 @ 200 extent: 80 @ 80.
	rectangle := RectangleMorph new.
	rectangle bounds: b.
	rectangle color: Color transparent.
	rectangle borderWidth: 1.
	self addMorphCentered: rectangle.
	self bounds: b.

I tired making the bounds of the boxMorph a pixel or two bigger (in  
the last line): this didn't help.

Any ideas?


More information about the Pharo-dev mailing list