 ; :mode=clojure:
 
 (ns hello
-    (:use
-        [goog.dom :only [appendChild createDom createTextNode removeChildren]]
-        [goog.events :only [listen]]
-        [goog.events.EventType :only [CLICK]]
-        [goog.graphics :only [createGraphics Stroke SolidFill Path]]
-        [goog :only [Timer]]
+    (:require
+        [goog.Timer :as Timer]
+        [goog.dom :as dom]
+        [goog.events :as events]
+        [goog.events.EventType :as EventType]
+        [goog.events.KeyCodes :as KeyCodes]
+        [goog.graphics :as graphics]
+        [goog.graphics.Stroke :as Stroke]
+        [goog.graphics.SolidFill :as SolidFill]
+        [goog.graphics.Path :as Path]
         ))
 
 (def my-code-url "https://github.com/pauldoo/scratch/blob/master/ClojureScript/hello.cljs")

        (fn [{keys :keys}]
            {:keys
                (cond
                    (= (.type event) goog.events.EventType/KEYUP)
                        (disj keys (.keyCode event))
                    (= (.type event) goog.events.EventType/KEYDOWN)
                        (conj keys (.keyCode event))
                    :else keys)})))

(defn tick-imp [state tick-step]
    (assoc state :nodes
        (update-node-positions
            (update-node-velocities
                (:nodes state)
                (calculate-all-node-forces (:nodes state) (:springs state))
                tick-step)
            tick-step)))

(defn tick [game-state-ref input-state] (do
    (swap! game-state-ref #(tick-imp % tick-step))))

(defn world-to-screen [[x y]]
    [x (- 275 y)])

(defn draw-line [g x1 y1 x2 y2]
    (.drawPath g
        (let [p (Path.)] (do
            (.moveTo p x1 y1)
            (.lineTo p x2 y2)
            p))
        (Stroke. 1 "green") nil))

(defn rerender [canvas-element game-state]
    (let [
        graphics (goog.graphics/createGraphics 400 300)
        {nodes :nodes springs :springs} game-state]
        (do
            (apply draw-line graphics (apply concat (map world-to-screen [[0 0] [400 0]])))

                        (draw-line graphics x1 y1 x2 y2))) springs))
            (dorun (map
                (fn [{p :pos}] (let [[x y] (world-to-screen p)]
                    (.drawCircle graphics x y 3 (goog.graphics.Stroke. 2 "green") (goog.graphics.SolidFill. "yellow"))))
                (vals nodes)))
            (dom/removeChildren canvas-element)
            (.render graphics canvas-element)
            )))

