 
 ;; animation
 
-(defn now []
-  (System/currentTimeMillis))
-
-(defn animate! [reference value-address duration min-val max-val]
+
+(defn animate!
+  "Slowly alters reference at value-address, linearly
+   with time from min-val to max-val."
+  [reference value-address duration min-val max-val]
   (let [start-time (now)]
     (loop []
       (let [elapsed (- (now) start-time)

        panel (proxy [JPanel clojure.lang.IReference] []
                (paintComponent [^Graphics graphics]
                  (proxy-super paintComponent graphics)
                  (try
                    (draw graphics @reference)
                    (catch Throwable e (draw-error graphics e))))
                (alterMeta [alter args]
                  (apply swap! meta-atom alter args))
                (resetMeta [m]
                  (reset! meta-atom m))
                (meta []
                  @meta-atom))]
    (add-watch reference panel (fn [_ _ _ _]
                                 (.repaint panel)))
    (alter-meta! panel assoc ::data-source reference)
    panel))


       (match-shapes [x y])))

(defn handle-mouse-move [e reference canvas]
  ;(println "move" (now))
  (let [data @reference
        last-widgets-under-mouse ((meta canvas) ::last-widgets-under-mouse)
        widgets-under-mouse (set (map #(select-keys % [:mouse-in :mouse-out :shape])
                                      (mouse-is-over [(.getX e) (.getY e)] data)))
        in (clojure.set/difference widgets-under-mouse last-widgets-under-mouse)
        out (clojure.set/difference last-widgets-under-mouse widgets-under-mouse)]
    (alter-meta! canvas assoc ::last-widgets-under-mouse
