Browse Source

created table and initialization functions for first row

Brandon Wong 7 years ago
parent
commit
b8ac183368
3 changed files with 60 additions and 3 deletions
  1. 17 1
      resources/public/css/style.css
  2. 33 2
      src/automata/core.cljs
  3. 10 0
      src/automata/init.cljs

+ 17 - 1
resources/public/css/style.css

@@ -1,2 +1,18 @@
-/* some style */
+
+body {
+    font-family:sans-serif;
+    overflow:scroll;
+}
+
+table {
+    border-collapse:collapse;
+}
+td {
+    min-width:40px;
+    min-height:40px;
+    width:40px;
+    height:40px;
+    border:1px solid white;
+}
+
 

+ 33 - 2
src/automata/core.cljs

@@ -1,6 +1,7 @@
 (ns automata.core
   (:require [reagent.core :as reagent :refer [atom]]
-            [automata.rules]))
+            [automata.rules]
+            [automata.init]))
 
 (enable-console-print!)
 
@@ -8,10 +9,40 @@
 (defonce app-state (atom {
                           :text "Hello world!"
                           :rule "01101110"
+                          :board [(automata.init.init-random 15)]
+                          :style {
+                                  :cell-size 40
+                                  :border-thickness 0
+                                  :active-color "red"
+                                  :inactive-color "blue"
+                                  }
                           }))
 
+;(swap! app-state assoc :board [(automata.init.init-random 15)])
+
+(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))])
+
+(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 App []
-  [:div "hi"])
+  [Board])
 
 (reagent/render-component [App]
                           (. js/document (getElementById "app")))

+ 10 - 0
src/automata/init.cljs

@@ -0,0 +1,10 @@
+(ns automata.init)
+
+(defn init-random [size]
+  (repeatedly size #(if (< 0.5 (js/Math.random)) false true)))
+
+(defn init-from-binary [string]
+  (map #(if (= % "1") true false) string))
+
+
+