             [dommy.core :as dommy :refer-macros [sel1]]
             [quil.core :as q :include-macros true]
             [quil.middleware :as m]))
-            ;; [jackal.common :as common :refer-macros [mandelbrot-set-iterations]]))
-
 
 (enable-console-print!)
 
+(def range-min -3)
+(def range-max 3)
+(def screen-width (.-innerWidth js/window))
+(def screen-height (.-innerHeight js/window))
 (def max-iterations 50)
-(def scaling-factor 200)
+(def scaling-factor (/ screen-width (- range-max range-min)))
 (def range-step-size (/ 1 scaling-factor))
 (def rect-size 1)
-(def pixel-offset-x 600)
-(def pixel-offset-y 400)
-(def range-min -2)
-(def range-max 2)
+(def pixel-offset-x (/ screen-width 2))
+(def pixel-offset-y (/ screen-height 2))
 (def canvas-name "fractal-canvas")
-
+(def actual-range (range range-min range-max range-step-size))
 
 (defn offset-pixel-coordinate-x
   [x]

  (+ pixel-offset-y y))

(defn scale-pixel-coordinate
  [x]
  (* scaling-factor x))

(defn add-canvas
  []
  (let [canvas-element (dommy/create-element :canvas)]
    (dommy/append!
     (sel1 :body)
     (dommy/set-attr! canvas-element :id canvas-name :width 1200 :height 750))))

(defn setup []
  (q/frame-rate 60)


(defn draw
  []
  (doseq [x (range range-min range-max range-step-size)
          y (range 0 range-max range-step-size)]
    (let [scaled-x (* scaling-factor x)
          scaled-y (* scaling-factor y)
          offset-scaled-x (+ pixel-offset-x scaled-x)
          offset-scaled-y (+ pixel-offset-y scaled-y)
          y-inv (q/floor (+ (* -1 scaled-y) pixel-offset-y))
          iterations (numerics/mandelbrot-set-iterations x y max-iterations)
          col (mod (+ iterations 128) 255)]
      (q/fill col 255 (if (= iterations max-iterations) 0 255))
      (q/rect offset-scaled-x y-inv rect-size rect-size)
      (q/rect offset-scaled-x offset-scaled-y rect-size rect-size)))
  (q/no-loop))

(init-canvas)

(q/defsketch mandlebrot-set
  :host canvas-name
  :title "The Mandelbrot Set"
  :setup setup
  :draw draw
  :size [screen-width screen-height]
  :middleware [m/fun-mode])

(println "hello world.")
