 
 (set! (.-onmouseup overlay-canvas) handle-mouseup)
 
+(set! (.-onresize js/window) (fn [] (render-mandelbrot! @app-state)))
+
+(add-watch app-state :state-changed
+           (fn [_ _ old-state new-state]
+             (when-not (= (:rendering-data old-state)
+                          (:rendering-data new-state))
+               (render-mandelbrot! new-state))))
 
 (render-mandelbrot! @app-state)
 


(def initial-rendering-data
  {:scale          350 ; How many pixels a distance of 1 in the complex plane takes up
   :x0             -3
   :y0             1.2})

(defonce app-state (atom {:escape-radius 10000
                          :rendering-data initial-rendering-data}))

    (.putImageData context idata 0 0)

    (.log js/console "Done in: " (int (* 1000 (/ (* height width)  (- (.getTime (js/Date.)) start)))) "px/s")))

(defn add-overlay-rectangle!
  "Adds a rectangle to the overlay canvas (and optionally clears all other rectangles)"
