12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- (ns automata.core
- (:require [reagent.core :as reagent :refer [atom]]
- [automata.rules]
- [automata.init]
- [cljs.core.async :as async :refer [chan <! >! timeout put!]])
- (:require-macros [cljs.core.async.macros :refer [go alt!]]))
- (enable-console-print!)
- ;; define your app data so that it doesn't get over-written on reload
- (defonce app-state (atom {
- :text "Hello world!"
- :rule (automata.rules.string-to-rule (automata.rules.preset-rules :110))
- :board [(automata.init.init-random 15)]
- :interv 500
- :go false
- :style {
- :cell-size 40
- :border-thickness 0
- :active-color "red"
- :inactive-color "blue"
- }
- }))
- ;(swap! app-state assoc :board [(automata.init.init-random 55)])
- (defn Cell [row ind value]
- [:td
- {
- :style {:background-color (if value "red" "blue")}
- :key (str "r" row "c" ind)
- }])
- (defn Row [ind row]
- [:tr
- {:key (str "row" ind)}
- (map-indexed (partial Cell ind) row)])
- (defn Board []
- [:table
- (map-indexed Row (@app-state :board))])
- (defn step []
- (swap! app-state update-in [:board] conj (automata.rules.proc (last (@app-state :board)) (@app-state :rule))))
- ;(go (dotimes [n 100]
- ; (<! (timeout 1000))
- ; (println (str "beat" n))
- ; (step)))
- (defn App []
- [Board])
- (reagent/render-component [App]
- (. js/document (getElementById "app")))
- (defn on-js-reload []
- ;; optionally touch your app-state to force rerendering depending on
- ;; your application
- ;; (swap! app-state update-in [:__figwheel_counter] inc)
- )
|