disastrs :: present! :: notes

Here lies the afternoon for 2024-12-20, happily spent.

?(?-) (An implementation of conway's game of life.)
?(?-) (I have the sense that I'm dancing around some very simple thing here, which is why there's so much.)
?(?-) (Applicative order rules)
<> ((?x) (?y) <=!=>) (<> ?x ?y)
<> ((?x) ?. <=!=>) (<> ?x (?.))
<> (?x ?y <=!=>) (<> ?x ?y)
<> (<!> ?x ?y) ((?x) (?y) ?(?x ?x) <=!=>)
?(?-) (Evaluate left-hand-side of rule only)
<> ((?x) <=!=< (?y)) (<> ?x ?y)
<> ((?x) <=!=< ?. ) (<> ?x (?.))
<> (?x <=!=< ?y) (<> ?x ?y)
<> (<!< ?x ?y) ((?x) ?(?x ?x) <=!=< (?y))
?(?-) (Applicative-order lambdas)
<> ((?l ?r) ?. <=!@=>) (?(?l ?r) ?.)
<> (<!@> (?l ?r) ?x) ((?l ?r) ?x ?(?z ?z) <=!@=>)
?(?-) (Function application)
<> (?. <=$=> ?f) (?f ?.)
<> ((?a) <=$=> ?f) (?f ?a)
<> (<$> ?f ?a) (?a ?(?x ?x) <=$=> ?f)
<> $board-offset ((4))
<> $board-size ((24))
<!> $screen-size (($board-size ($board-offset (2) `*) `+))
 
<> $live-color ((#ffffff))
<> $dead-color ((#000000))
?(?-) (Utils)
<> (!random) (?((?: ?0 ?1) ?:) rand 0 2)
<> ((?0) (?1) `?:) ?:
<> (?x -1) ((?x) (1) `-)
<> (?x +1) ((?x) (1) `+)
<> (read ?: (point ?0 ?1) (?2)) ?:
<> (read ?: (?0 ?1) (?2)) ?:
<> (draw ?: (point ?0 ?1) (?2)) ?:
?(?-) (Initialize the game board)
<!> (?p (.) cell) (draw pixel ?p $dead-color)
<!> (?p (#) cell) (draw pixel ?p $live-color)
<!> (?p (0) cell) (draw pixel ?p $dead-color)
<!> (?p (1) cell) (draw pixel ?p $live-color)
<> (handle-event (Tic ?x)) (Conway)
<> (handle-event ?x) (?(?: ?:) (print (Unknown event: ?x \n)))
<> (on-event ?~) (handle-event ?~ on-event Any)
<!< ($board-offset $board-offset init) ()
<!< ($board-offset (?j) init) ($board-size ((?j) (1) `-) init)
<> ((?i) (?j) init) (
  (point ?i ?j) ((0) (2) `rand) cell
  ((?i) (1) `-) (?j) init
)
?(?-) (Conway stuff. We can do standard arithmetic on hexadecimal values.)
<!> (judge $live-color ($live-color (#000002) `*)) $live-color
<!> (judge $live-color ($live-color (#000003) `*)) $live-color
<!> (judge $dead-color ($live-color (#000003) `*)) $live-color
<!> (judge (?c) (?d)) $dead-color
?(?-) (Let's get an incorrect version going first)
<> (Conway) ($screen-size (0) copy-row $board-size $board-size Iterate)
<!< ($board-offset $board-offset Iterate) ()
<!< ($board-offset (?y) Iterate) ((1) (0) copy-row ((?y) (1) `-) (1) copy-row $board-size ((?y) (1) `-) Iterate)
<> ((?x) (?y) Iterate) (
  (0 1) (0 0) copy
  (?x ?y) (0 1) copy
  draw pixel (point ?x ?y) (judge (read @pixel (?x ?y) (@000000)) (sum-neighbors-of ?x ?y))
  ((?x) (1) `-) (?y) Iterate
)
?(?-) (Operations)
<> (``?: (?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7)) ?:
<> (sum-neighbors-of ?x ?y) (
    ``+
    (read @pixel ((?x) (1) `- (?y) (1) `-) (#000000)
     read @pixel ( ?x         (?y) (1) `-) (#000000)
     read @pixel ((?x) (1) `+ (?y) (1) `-) (#000000)
     read @pixel ((?x) (1) `- ?y) (#000000)
     read @pixel (0 0) (#0)
     read @pixel ((?x) (1) `- 0) (#000000)
     read @pixel ( ?x         0) (#000000)
     read @pixel ((?x) (1) `+ 0) (#000000))
)
<> ((?a ?b) (?c ?d) copy) ( draw pixel (point ?c ?d) (read @pixel (?a ?b) (#000000)))
<!< ($board-offset ?a ?b copy-row-step) ()
<> ((?x) ?a ?b copy-row-step) ((?x ?a) (?x ?b) copy ((?x) (1) `-) ?a ?b copy-row-step)
<> ((?a) (?b) copy-row) ($board-size ?a ?b copy-row-step) 
<!@> (((?0) (?1) ?:) ?:) ($screen-size $screen-size size)
<> ((?x) (?y) () init-board-step) ()
<!< (($board-size $board-offset `+) ($board-size $board-offset `+) ?s init-board-step) ()
<!< (($board-size $board-offset `+) (?y) ?s init-board-step) ($board-offset ((?y) (1) `+) ?s init-board-step)
<> ((?x) (?y) (?a ?s) init-board-step) ((point ?x ?y) (?a) cell ((?x) (1) `+) (?y) ?s init-board-step)
<> (init-board ?*) ($board-offset $board-offset (?*) init-board-step)
?(?-) (I've noticed strange behavior at the edges of the game-board.)
?(?-) (
Gosper gun. 
Requires a board size of 39
For some reason, my program draws the rightmost block as a zig-zag
So, the gosper gun blows up. Oh well!
init-board (
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . . .  
. . . . . . . . . . . . . # # . . . . . . # # . . . . . . . . . . . . # # . .  
. . . . . . . . . . . . # . . . # . . . . # # . . . . . . . . . . . . # # . .  
. # # . . . . . . . . # . . . . . # . . . # # . . . . . . . . . . . . . . . .  
. # # . . . . . . . . # . . . # . # # . . . . # . # . . . . . . . . . . . . .  
. . . . . . . . . . . # . . . . . # . . . . . . . # . . . . . . . . . . . . .  
. . . . . . . . . . . . # . . . # . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . # # . . . . . . . . . . . . . . . . . . . . . . . .  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
)
)
?(?-) (Requires a board-size of 20
init-board (
. . . . . . . . . . . . . . . . . . . .
. . . . . # # # . . . # # # . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . # . . . . # . # . . . . # . . . .
. . . # . . . . # . # . . . . # . . . .
. . . # . . . . # . # . . . . # . . . .
. . . . . # # # . . . # # # . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . # # # . . . # # # . . . . . .
. . . # . . . . # . # . . . . # . . . .
. . . # . . . . # . # . . . . # . . . .
. . . # . . . . # . # . . . . # . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . # # # . . . # # # . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
)
)
?(?-) (Randomize board)
$board-size $board-size init
on-event Any