Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Nov 10, 2019
1 parent 1af4641 commit 921ac18
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 59 deletions.
21 changes: 6 additions & 15 deletions src/erdos/lenart/common.cljs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
(ns erdos.lenart.common
(:require-macros
[erdos.lenart.macros
:refer [defatom= template]])
(:require
[goog.string] [goog.string.format]
[erdos.lenart.lang :as lang]
[erdos.lenart.math :as m :refer
[sin atan2 rad->deg
deg->rad unit clockwise?]]))

(:require-macros [erdos.lenart.macros :refer [template]])
(:require [goog.string] [goog.string.format]
[erdos.lenart.lang :as lang]
[erdos.lenart.math :as m]))

#_
(defn geo-cube []
(for [i [-1 0 1]
j [-1 0 1]
Expand All @@ -30,10 +25,7 @@
:point-color "orange"})

(def ^:dynamic *style* default-style)

(def ^:dynamic *zoom* 192.0)
;; (def ^:dynamic *rotation*) ;; not used yet.


(defn format [s & args]
(apply goog.string.format s args))
Expand All @@ -48,6 +40,7 @@
(re-seq #"\d+(?:\.\d+)?" c))] [r g b (or a 1.0)])))

(defonce color->rgba (memoize color->rgba-))

(defn mean [a b] (/ (+ a b) 2))

(defn mean2 [a b] (/ (+ a b b b b b) 6))
Expand Down Expand Up @@ -92,8 +85,6 @@
:stroke (:stroke *style* "black")
:stroke-width (:stroke-width *style* 3)}])

(defn third [x] (nth x 2 nil))

(defn arc [x0 y0, w h, ang, f0 f1, x1 y1]
[:path
{:d
Expand Down
82 changes: 38 additions & 44 deletions src/erdos/lenart/lang.cljc
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
(ns erdos.lenart.lang
(:require [erdos.lenart.geo :as geo])
#?(:cljs (:require-macros [erdos.lenart.macros
:refer [match-seq]])
:clj (:require [erdos.lenart.macros
:refer [match-seq]])))
#?(:cljs (:require-macros [erdos.lenart.macros :refer [match-seq]])
:clj (:require [erdos.lenart.macros :refer [match-seq]])))

(defn- deps [m x]
(let [mx (m x)]
(remove nil?
(list* (:from mx)
(:to mx)
(:a mx)
(:b mx)
(:origin mx)
(:on mx)
(concat (:pts mx))))))

(defn topsort
"Creates a processing order in the map"
Expand All @@ -29,40 +17,10 @@
(recur (into out kk) (reduce disj others kk)))
out))))

(declare parse-sentence)

(defn parse-sentence- [x]
(try (parse-sentence x)
#?(:cljs (catch :default e (.log js/console e))
:clj (catch Exception e (.printStackTrace e))) nil))


(defn parse-book [ls]
(let [ls (map #(.trim %) (.split ls "\n"))
xs (keep parse-sentence- ls)
m (zipmap (map :id xs) xs)
top (topsort deps m)]
(-> (reduce (fn [acc x]
(let [e (geo/eval-geo acc (m x))]
(assoc acc (:id e) e))) {} top)
(mapv top))))

(defn tokenize-sentence [s]
(assert (string? s))
(seq (.split s " ")))

(declare parse-construction)

(defn parse-sentence [s]
(let [s (if (vector? s) s (tokenize-sentence s))]
(match-seq s
[?id "is" "hidden" & ?xs]
(-> ?xs (parse-construction) (assoc :id ?id :hidden true))
[?id "is" & ?xs]
(-> ?xs (parse-construction) (assoc :id ?id :hidden false))
["draw" & ?xs]
(-> ?xs (parse-construction) (assoc :id (gensym) :hidden false)))))

(defn parse-style-item [s]
(assert (sequential? s))
(match-seq s
Expand Down Expand Up @@ -110,3 +68,39 @@
(-> rest parse-style (assoc :type :segment :from ?from :to ?to))
;;,,{:type :segment :from ?name1 :to ?name2}
(assert false (str "Not a construction: " s))))

(defn parse-sentence [s]
(let [s (if (vector? s) s (tokenize-sentence s))]
(match-seq s
[?id "is" "hidden" & ?xs]
(-> ?xs (parse-construction) (assoc :id ?id :hidden true))
[?id "is" & ?xs]
(-> ?xs (parse-construction) (assoc :id ?id :hidden false))
["draw" & ?xs]
(-> ?xs (parse-construction) (assoc :id (gensym) :hidden false)))))

(defn parse-sentence- [x]
(try (parse-sentence x)
#?(:cljs (catch :default e (.log js/console e))
:clj (catch Exception e (.printStackTrace e))) nil))

(defn- deps [m x]
(let [mx (m x)]
(remove nil?
(list* (:from mx)
(:to mx)
(:a mx)
(:b mx)
(:origin mx)
(:on mx)
(concat (:pts mx))))))

(defn parse-book [ls]
(let [ls (map #(.trim %) (.split ls "\n"))
xs (keep parse-sentence- ls)
m (zipmap (map :id xs) xs)
top (topsort deps m)]
(-> (reduce (fn [acc x]
(let [e (geo/eval-geo acc (m x))]
(assoc acc (:id e) e))) {} top)
(mapv top))))

0 comments on commit 921ac18

Please sign in to comment.