update-grid ( gadget -- )


Vocabulary
game-of-life

Inputs
gadgetan object


Outputs
None

Definition


:: update-grid ( gadget -- )
gadget dim>> first2 :> ( w h ) gadget size>> :> size h w
[ size /i ] bi@
:> ( new-rows new-cols ) gadget grid>> :> grid grid grid-dim
:> ( rows cols ) rows new-rows = not cols new-cols = not or
[
new-rows new-cols make-grid
:> new-grid rows new-rows min <iota> [| j |
cols new-cols min <iota> [| i |
i j grid nth-unsafe nth-unsafe
i j new-grid nth-unsafe set-nth-unsafe
] each
] each new-grid gadget grid<<
] when ;