Browse Source

wrote step function (works); started on core.async functions

Brandon Wong 7 years ago
parent
commit
0f497d86cc
3 changed files with 22 additions and 12 deletions
  1. 2 1
      project.clj
  2. 4 4
      resources/public/css/style.css
  3. 16 7
      src/automata/core.cljs

+ 2 - 1
project.clj

@@ -31,7 +31,8 @@
                            ;; in the default browser once Figwheel has
                            ;; started and complied your application.
                            ;; Comment this out once it no longer serves you.
-                           :open-urls ["http://localhost:3449/index.html"]}
+                           ;:open-urls ["http://localhost:3449/index.html"]
+                           }
 
                 :compiler {:main automata.core
                            :asset-path "js/compiled/out"

+ 4 - 4
resources/public/css/style.css

@@ -8,10 +8,10 @@ table {
     border-collapse:collapse;
 }
 td {
-    min-width:40px;
-    min-height:40px;
-    width:40px;
-    height:40px;
+    min-width:10px;
+    min-height:10px;
+    width:10px;
+    height:10px;
     border:1px solid white;
 }
 

+ 16 - 7
src/automata/core.cljs

@@ -1,15 +1,19 @@
 (ns automata.core
   (:require [reagent.core :as reagent :refer [atom]]
             [automata.rules]
-            [automata.init]))
+            [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 "01101110"
+                          :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
@@ -18,7 +22,7 @@
                                   }
                           }))
 
-;(swap! app-state assoc :board [(automata.init.init-random 15)])
+;(swap! app-state assoc :board [(automata.init.init-random 55)])
 
 (defn Cell [row ind value]
   [:td
@@ -36,10 +40,15 @@
   [:table
    (map-indexed Row (@app-state :board))])
 
-(println "well?" (automata.rules.proc (last (@app-state :board)) (automata.rules.string-to-rule (automata.rules.preset-rules :110))))
-;; this is incorrect
-;(defn step []
-;  (swap! app-state update-in :board conj (automata.rules.proc (last (@app-state :board)) (automata.rules.string-to-rule (automata.rules.preset-rules :110)))))
+
+(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])