Last active
July 2, 2024 01:56
-
-
Save CFiggers/a2963a7bcd50a25a42bf83d0598c697f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import jaylib) | |
(def width 1920) | |
(def height 1280) | |
(def cells 255) | |
(def rule-30 | |
{[0 0 1] 1 | |
[0 1 0] 1 | |
[0 1 1] 1 | |
[1 0 0] 1}) | |
(defn update-board [board] | |
(def board-copy (array/slice board)) | |
(for i 0 (length board) | |
(let [lookup (freeze (seq [j :range [(- i 1) (+ i 2)]] (get board-copy j)))] | |
(set (board i) (get rule-30 lookup 0))))) | |
(defn main [& args] | |
(jaylib/init-window width height "Template") | |
(jaylib/set-target-fps 60) | |
(def board (array/new-filled cells 0)) | |
(set (board (math/ceil (/ cells 2))) 1) | |
(def square-size (/ width cells)) | |
(var iteration 0) | |
(var notified false) | |
(jaylib/clear-background 0x181818FF) | |
(while (not (jaylib/window-should-close)) | |
(defer (jaylib/end-drawing) | |
(jaylib/begin-drawing) | |
(if (<= iteration (/ height square-size)) | |
(do (eachp [i square] board | |
(unless (= 0 square) | |
(jaylib/draw-rectangle | |
(math/floor (* i square-size)) | |
(math/floor (* iteration square-size)) | |
(math/floor square-size) (math/floor square-size) :white) | |
(jaylib/draw-rectangle-lines | |
(math/floor (* i square-size)) | |
(math/floor (* iteration square-size)) | |
(math/floor square-size) (math/floor square-size) :blue))) | |
(update-board board) | |
(++ iteration)) | |
(when (not notified) | |
(print "Done calculating!") | |
(toggle notified))))) | |
(jaylib/close-window)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To try this, install Janet and jpm. Install jaylib:
$ jpm install jaylib
Then run:
janet cellular-automata.janet