 (def tick-step (/ 1 100))
 (def render-step (/ 1 25))
 (def gravity-strength 300)
-(def ground-strength 100)
+(def ground-rebound-strength 200)
+(def ground-grip-strength 50)
+(def drag-factor 5)
 
 (defn print-to-log [v]
     (.log js/console v))

            (. tick-timer (start))
            (. render-timer (start))
            (dorun (map (partial apply events/listen) [
                [button EventType/CLICK (partial input-event input-state-ref)]
                [document.body EventType/KEYDOWN (partial input-event input-state-ref) true]
                [document.body EventType/KEYUP (partial input-event input-state-ref) true]
                [tick-timer Timer/TICK #(tick game-state-ref (deref input-state-ref))]
                [render-timer Timer/TICK #(rerender canvas (deref game-state-ref))]]))
            (dom/appendChild document.body (dom/createDom "div" {}
                (dom/createDom "h1" {} "Work in progress..")
                (dom/createDom "div" {} "Try clicking the button, or pressing keys.")
                (dom/createDom "div" {}
                    (dom/createTextNode "My code lives here: ")
                    (dom/createDom "a" (.strobj {"href" my-code-url}) my-code-url))

            hinges)))

(defn calculate-gravity-forces [nodes]
    (zipmap (keys nodes)
        (map (fn [{m :mass}]
            [0 (- (* gravity-strength m))])
            (vals nodes))))

(defn calculate-ground-forces [nodes]
    (zipmap (keys nodes)
        (map (fn [{[ x y ] :pos [ xv yv ] :vel }]
            (if (< y 0)
                (vec+
                    (vec* [(- xv) (Math/max 0 (- yv))] ground-grip-strength)
                    (vec* [0 (- y)] ground-rebound-strength))
                [0 0])) (vals nodes))))

(defn calculate-drag-forces [nodes]
    (zipmap (keys nodes)
        (map (fn [{v :vel m :mass}] (vec* v (- (* m drag-factor))))
            (vals nodes))))

(defn calculate-all-node-forces [{:keys [nodes springs hinges]}]
    (merge-with vec+
        (calculate-spring-forces nodes springs)
        (calculate-hinge-forces nodes hinges)
        (calculate-gravity-forces nodes)
        (calculate-ground-forces nodes)
        (calculate-drag-forces nodes)))

(defn update-node-velocities [nodes forces time-step]
    (merge-with (fn [n f]
        (assoc n
            :vel (vec+ (:vel n) (vec* f (/ time-step (:mass n))))))
        nodes
        forces))

