 (enable-console-print!)
 
 (def initial-rendering-data
-  {:scale          (/ (.-innerWidth js/window) 4) ; How many pixels a distance of 1 in the complex plane takes up
-   :x0             -3 ; the x co-ordinate of the top-left pixel in the canvase
-   :y0             1.2 ; the y co-ordinate of the top-left pixel in the canvase
+  "Defines a rectangle (not necessarily of the same aspect ratio as the screen)
+  in the complex plane to be displayed. This will then be centred on the screen
+  using advanced maths."
+  {:x0             -3
+   :y0             1
+   :width          4
+   :height         2
    })
 
 (defonce app-state (atom {:canvas         (.getElementById js/document "canvas")


    (.putImageData context idata 0 0)

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

(defn re-render!
  "Adds a green semi-transparent overlay to the screen, then

  (.setTimeout js/window #(render-mandelbrot! new-state) 50))


(defn handle-mouseup
  "On mouseup, we zoom the mandelbrot to the specified box and remove the
   :mousedown-event key from the app-state"
  [e]
  (swap!
   app-state
   (fn [{:as old-state :keys [mousedown-event canvas rendered-rectangle]}]

     (let [{:keys [x0 y0 scale]}        rendered-rectangle

           x*1                           (+ x0 (/ (aget e "pageX") scale))
           y*1                           (- y0 (/ (aget e "pageY") scale))

           x*0                           (+ x0 (/ (aget mousedown-event "pageX") scale))
           y*0                           (- y0 (/ (aget mousedown-event "pageY") scale))]

       (-> old-state
           (dissoc :mousedown-event)
           (assoc :rendering-data {:x0     x*0
                                   :y0     y*0
                                   :width  (- x*1 x*0)
                                   :height (- y*0 y*1)}))))))

(defn handle-state-change!
  [_ _ old-state new-state]
