Newbie: help on Form

Dan Ingalls Dan at SqueakLand.org
Wed Nov 21 06:00:31 UTC 2001


Hsin-Hao Yu <hhyu at Cogsci.ucsd.edu> wrote...

> > If you want to use Forms, then go ahead, but you might find the
>> simplest way to do this is to make a morphic structure, and let the
>> system take care of displaying it.
>
>Thank you very much for the help! I wanted to use Morphs too, but I thought
>it could be much slower than Forms. Isn't it so?

Hsin-Hao  -

Well, judge for yourself.  Here is a really simple Morph to play with...
------------------
RectangleMorph subclass: #MorphExample
	instanceVariableNames: 'phase ball star '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Demo'!

initialize
	super initialize.
	phase := 1.
	self extent: 200 at 200.
	ball := EllipseMorph new extent: 30 at 30.
	self addMorph: ((star := StarMorph new extent: 150 at 150)
			center: self center)

step
	phase := phase\\8 + 1.
	phase = 1 ifTrue: [^ ball delete].
	phase = 4 ifTrue: [self addMorph: ball].
	ball align: ball center with: (star vertices atWrap: phase*2)
------------------

As I promised, 10-20 lines of code.  It does a really stupid thing:  shows a star for 3 seconds, and then moves a ball from one point to the next on the star for the next 5 seconds.  As a default it will get a step message every 1000ms, which makes the ellipse hop from point to point once per second.  You can make it run faster by defining a stepTime method to return, eg, 200 instead of 1000.

Copy this code to your browser, then execute...
	MorphExample new openInWorld.
in a Workspace.  It should appear at the top left of the screen and start running.  Pick it up.  Drag it around.  Make more of them.

>From here on you can add features, make it bigger, use different morphs, etc, and you should be able to tell whether Squeak on your machine will do what you want in Morphic.  I think it can.

Good luck

	- Dan




More information about the Squeak-dev mailing list