[Vm-dev] Tangential: A Lisp Interpreter Implemented in Conway's Game of Life
Stéphane Rollandin
lecteur at zogotounga.net
Thu Jan 19 10:37:45 UTC 2023
> Here's one that does work.
This one has some spurious activity at the right border. See the
attached version for a fix (which I am not able to explain BTW).
Stef
-------------- next part --------------
'From Squeak6.0 of 5 July 2022 [latest update: #22104] on 19 January 2023 at 11:33:58 am'!
!Form methodsFor: 'processing' stamp: 'spfa 1/19/2023 11:33'!
nextGeneration
"Dan Ingalls Game of Life in BitBlt from Byte81 issue, see https://archive.org/details/byte-magazine-1981-08/page/n181/mode/2up and the following pages. "
"
|life|
life := Form extent: 200 at 200.
10000 timesRepeat: [life colorAt: 200 atRandom @ 200 atRandom put: Color black].
[Sensor noButtonPressed] whileTrue: [
life nextGeneration.
(life magnifyBy: 4) displayAt: 10 at 50].
Display restore.
"
| ext carry2 carry4 nbr1 nbr2 nbr4 all n8 |
ext := self extent + (2 at 2).
nbr1 := Form extent: ext. "ones bit of count"
nbr2 := Form extent: ext. "twos bit of count"
nbr4 := Form extent: ext. "fours bit of count"
carry2 := Form extent: ext. "carry ones overflow into twos"
carry4 := Form extent: ext. "carry twos overflow into fours"
all := 0 at 0 corner: ext.
n8 := {-2@ -1 . -2@ -2 . -1 at 0 . -2 at 0 . 0@ -1 . 0 at 0 . -1@ -2 . 0@ -2} .
n8 do: [:offset |
"c2 := 1s & self"
carry2 copy: all from: 0 at 0 in: nbr1 rule: Form over.
carry2 copy: all from: offset in: self rule: Form and.
"c4 := 2s & c2"
carry4 copy: all from: 0 at 0 in: nbr2 rule: Form over.
carry4 copy: all from: 0 at 0 in: carry2 rule: Form and.
"1s ^= self"
nbr1 copy: all from: offset in: self rule: Form reverse.
1 to: ext y do: [:h | nbr1 colorAt: 1 @ h put: Color black].
"2s ^= c2"
nbr2 copy: all from: 0 at 0 in: carry2 rule: Form reverse.
"4s ^= c4"
nbr4 copy: all from: 0 at 0 in: carry4 rule: Form reverse.
].
"1s &= 2s"
nbr1 copy: all from: 0 at 0 in: nbr2 rule: Form and.
"self &= 2s"
self copy: all from: 1 at 1 in: nbr2 rule: Form and.
"self |= (1s & 2s)"
self copy: all from: 1 at 1 in: nbr1 rule: Form under.
"self &= !!4s"
self copy: all from: 1 at 1 in: nbr4 rule: 4.
! !
More information about the Vm-dev
mailing list