Skip to content

Instantly share code, notes, and snippets.

@JonathanSmith
Created October 11, 2009 01:58
Show Gist options
  • Save JonathanSmith/207321 to your computer and use it in GitHub Desktop.
Save JonathanSmith/207321 to your computer and use it in GitHub Desktop.
(defn mouse-click [[x y] state]
(let [ul (:upper-left state)
lr (:lower-right state)
coord (map / [x y] (:dim state))]
(update-bounds
(assoc state
:offset (map + ul (map * coord (map - lr ul)))))))
(defn key-press [key s]
(if-let [dispatch-fn ({:Z (fn [state]
(update-bounds
(assoc state
:zoom (* 2 (:zoom state)))))
:X (fn [state]
(update-bounds
(assoc state
:zoom (/ (:zoom state) 2))))} key)]
(dispatch-fn s)
s))
.
.
.
(start
{:init init, :reshape reshape, :update update, :display display, :key-press key-press :mouse-click mouse-click}
(reset-fractal {:upper-left [-2.0 1.0] :lower-right [1.0 -1.0] :zoom 1 :offset [-0.5 0]}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment