Ver código fonte

added start/stop/step/reset actions

Brandon Wong 7 anos atrás
pai
commit
d1864c4f48
1 arquivos alterados com 14 adições e 3 exclusões
  1. 14 3
      src/automata/core.cljs

+ 14 - 3
src/automata/core.cljs

@@ -27,7 +27,7 @@
 (defn Cell [row ind value]
   [:td
    {
-    :style {:background-color (if value "red" "blue")}
+    :style {:background-color (if value "blue" "lightblue")}
     :key (str "r" row "c" ind)
     }])
 
@@ -38,7 +38,8 @@
 
 (defn Board []
   [:table
-   (map-indexed Row (@app-state :board))])
+   [:tbody
+    (map-indexed Row (@app-state :board))]])
 
 
 (defn step []
@@ -49,9 +50,19 @@
 ;      (<! (timeout 1000))
 ;      (println (str "beat" n))
 ;      (step)))
+(defn start-stepping []
+  (go
+    (while (@app-state :go)
+      (step)
+      (<! (timeout 100)))))
 
 (defn App []
-  [Board])
+  [:div
+   [:button {:on-click (fn [] (swap! app-state update-in [:go] not) (start-stepping))} (if (@app-state :go) "stop" "go")]
+   [:button {:on-click (fn [] (step))} "step"]
+   [:button {:on-click (fn [] (swap! app-state assoc :board [(automata.init.init-random 55)]))} "reset"]
+   [Board]
+   ])
 
 (reagent/render-component [App]
                           (. js/document (getElementById "app")))