Life

ohshima at is.titech.ac.jp ohshima at is.titech.ac.jp
Mon Dec 6 14:53:59 UTC 1999


----Next_Part(Mon_Dec__6_23:53:55_1999)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


  Hi,

  I suppose many people around the world wrote similar
things, but I can't help to posting it here:-)

  Attached is the modified version of Life, which becomes
now Morph, and accepts any Morph to be dropped in.  If you
create the glider, shooter, etc. as an ImageMorph (or other
Morph), you can drop them into the LifeMorph.

  And don't forget to use MagnifierMorph.  you can see the
magnified cells in the magnifing glass!

  -- Yoshiki

----Next_Part(Mon_Dec__6_23:53:55_1999)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable


'From Squeak2.7alpha of 20 November 1999 [latest update: #1660] on 6 Dec=
ember 1999 at 11:06:07 pm'!=0DImageMorph subclass: #LifeMorph=0D	instanc=
eVariableNames: 'size nbr1 nbr2 nbr4 carry2 carry4 '=0D	classVariableNam=
es: ''=0D	poolDictionaries: ''=0D	category: 'Morphic-Demo'!=0D=0D!LifeMo=
rph methodsFor: 'event handling' stamp: 'yo 12/6/1999 22:08'!=0DacceptDr=
oppingMorph: aMorph event: evt=0D	| point form |=0D	point _ aMorph topLe=
ft - self topLeft.=0D	form _ aMorph imageForm asFormOfDepth: 1.=0D=0D	im=
age copy: form boundingBox from: form to: point rule: Form over.=0D	aMor=
ph delete.=0D! !=0D=0D!LifeMorph methodsFor: 'event handling' stamp: 'yo=
 12/6/1999 17:09'!=0Dclick: evt=0D	| point |=0D	point _ evt cursorPoint =
- self topLeft.=0D	image pixelValueAt: point put: 1.=0D=0D! !=0D=0D!Life=
Morph methodsFor: 'event handling' stamp: 'yo 12/6/1999 17:10'!=0Ddrag: =
evt=0D	| point |=0D	point _ evt cursorPoint - self topLeft.=0D	image pix=
elValueAt: point put: 1.=0D=0D! !=0D=0D!LifeMorph methodsFor: 'event han=
dling' stamp: 'yo 12/6/1999 16:48'!=0DhandlesMouseDown: evt=0D	^true! !=0D=
=0D!LifeMorph methodsFor: 'event handling' stamp: 'yo 12/6/1999 17:06'!=0D=
mouseDown: evt=0D=0D	evt hand waitForClicksOrDrag: self event: evt! !=0D=
=0D!LifeMorph methodsFor: 'event handling' stamp: 'yo 12/6/1999 21:27'!=0D=
wantsDroppedMorph: aMorph event: evt=0D	^true! !=0D=0D=0D!LifeMorph meth=
odsFor: 'general' stamp: 'yo 12/6/1999 17:35'!=0Dinitialize    "Initiali=
ze cells for random distribution"=0D	| rand |=0D	super initialize.=0D	se=
lf size: 400.=0D	rand _ Random new.=0D	1 to: size do:=0D    		[:i | imag=
e reverse: ((rand next * size)@(rand next * size) extent: size // 4).=0D=
		"self displayThisState"].=0D! !=0D=0D!LifeMorph methodsFor: 'general' =
stamp: 'yo 12/6/1999 17:36'!=0DnextLifeGeneration=0D	"Compute next gener=
ation by computing neighbor counts.=0D	These are tallied in nbr1, nbr2, =
nbr4."=0D	| all delta |=0D	all _ 0 at 0 extent: image extent.=0D	nbr1 fillW=
hite.  nbr2 fillWhite.  nbr4 fillWhite.=0D	1 to: 8 do:                  =
 "Three-bit add for each shift of cells"=0D		[:i | delta _ (i+4\\9//3 - =
1)@(i+4\\3 - 1).  "8 neighbor deltas"=0D		carry2 copy: all from: nbr1 to=
: 0 at 0 rule: Form over.=0D		carry2 copy: all from: image to: delta rule: =
Form and. "carry 2"=0D		nbr1 copy: all from: image to: delta rule: Form =
reverse.   "sum 1" "(reverse is xor)"=0D		carry4 copy: all from: nbr2 to=
: 0 at 0 rule: Form over.=0D		carry4 copy: all from: carry2 to: 0 at 0 rule: F=
orm and.  "carry 4"=0D		nbr2 copy: all from: carry2 to: 0 at 0 rule: Form r=
everse.    "sum 2"=0D		nbr4 copy: all from: carry4 to: 0 at 0 rule: Form re=
verse].    "sum 4"=0D	"Next gen =3D ((2s AND cells) OR (2s AND 1s)) AND =
(NOT 4s)"=0D	image copy: all from: nbr2 to: 0 at 0 rule: Form and.=0D	nbr1 =
copy: all from: nbr2 to: 0 at 0 rule: Form and.=0D	image copy: all from: nb=
r1 to: 0 at 0 rule: Form under.=0D	image copy: all from: nbr4 to: 0 at 0 rule:=
 Form erase.=0D	image borderWidth: 1 fillColor: Color white.  "trim edge=
s"! !=0D=0D!LifeMorph methodsFor: 'general' stamp: 'yo 12/6/1999 17:36'!=
=0Dsize: s    "Initialize for size of array."=0D	size _ s.=0D	image _ Fo=
rm extent: s at s.=0D	nbr1 _ Form extent: s at s.=0D	nbr2 _ Form extent: s at s.=0D=
	nbr4 _ Form extent: s at s.=0D	carry2 _ Form extent: s at s.=0D	carry4 _ Form=
 extent: s at s.=0D	self image: image.! !=0D=0D!LifeMorph methodsFor: 'gene=
ral' stamp: 'yo 12/6/1999 22:10'!=0Dstep=0D	self nextLifeGeneration.=0D	=
self changed.! !=0D=0D!LifeMorph methodsFor: 'general' stamp: 'yo 12/6/1=
999 18:05'!=0DstepTime=0D	^50=0D! !=0D=

----Next_Part(Mon_Dec__6_23:53:55_1999)----





More information about the Squeak-dev mailing list