0

Smalltalk: Move a Morph in circle using Squeak

Squeak Morph

aMorph := Morph new.
aMorph openInWorld.

x := 0.0.
y := 0.0.
th := 0.0.

1 to: 200 do: [:i | 
	
	th :=  i * (3.14 / 100).
	"Transcript show: th."
	x := th sin * 100 + 200.
	y := th cos * 100 + 200.
	aMorph position: x@y.
	Transcript show: (x printString) , ' - ' , (y printString).
	Transcript cr. 
	].

 

Explanation:

This is very simple. I created the new object with code “Morph new” and then made it visible with “aMorph openInWorld.” code. Once it was visible I moved it in circle, and to move Morph I used this “aMorph position: x@y.”. Very simple, very fun.

Note: You can download theย latest version of Squeak from http://squeak.org/. It is available for Windows, Mac and GNU/Linux

humayun