                                         ; can't call s/load-image here because we're not in the dynamic scope for the *processing* binding
                                         (def images (assoc images id response)))})))  ; so just store the base64 image data in the map
 
+;; Sketch
+
+(defn setup []
+  (s/size (.-innerWidth js/window) (.-innerHeight js/window))
+  (s/text-font (s/create-font "Arial" 32)))
+   
+(defn draw []
+  (let [mx (s/mouse-x), my (s/mouse-y)]
+    (s/background 100)
+    
+    (draw-person mx my)
+    
+    (s/push-matrix)
+    (s/scale 2.0)
+    (if-let [img (load-image "logo-color-255x75.png")]
+      (s/image img 100 100))
+    (s/pop-matrix)
+    
+    (draw-cursor mx my)
+                  
+    (show-coords mx my)))
+
 (defn init []
-  (js/Processing.
-    (sel1 :#stage)
-    (s/sketch-init {:setup (fn []
-                             (s/size (.-innerWidth js/window) (.-innerHeight js/window))
-                             (s/text-font (s/create-font "Arial" 32)))
-                    
-                    :draw (fn []
-                            (let [mx (s/mouse-x), my (s/mouse-y)]
-                              (s/background 100)
-                              
-                              (draw-person mx my)
-                              
-                              (s/push-matrix)
-                              (s/scale 2.0)
-                              (if-let [img (load-image "logo-color-255x75.png")]
-                                (s/image img 100 100))
-                              (s/pop-matrix)
-                              
-                              (draw-cursor mx my)
-                              
-                              (show-coords mx my)))}))
-  
-  ; Use of "localhost" will only work for local development.
-  ; Change the port to match the :repl-listen-port.
+  (js/Processing. (sel1 :#stage) (s/sketch-init {:setup setup
+                                                 :draw draw}))
   (repl/connect "http://localhost:9000/repl"))

(defn draw-cursor
  "Draws a cursor at the specified coordinate"
  [x y]
  (draw :cursor x y
        (fn []
          (s/line (- cursor-size) 0, cursor-size 0)
          (s/line 0 (- cursor-size), 0 cursor-size))))

(def speech-balloon-properties {:offset 10
                                :point-width 20

  (set-text-box! [:div "x:" [:span.highlight x] ", y:" [:span.highlight y]]))


;; Draw

(defn draw-thing
  "Lookup and apply styles for named object, translate origin to given coordinate, and draw using supplied function"
  [name x y f]
  (s/push-style)
