Created
January 26, 2018 04:12
-
-
Save quoll/f61cbe8bcbe8e4104bb9d32b2f04f2c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn square [x] (* x x)) | |
(defn offset [x y] | |
(let [ms (max (Math/abs x) (Math/abs y)) | |
sq (dec (* 2 ms)) | |
base (square sq) | |
side (inc sq) | |
hside (/ side 2)] | |
(cond | |
(and (= x ms) (< y ms)) (- (+ base hside) y) | |
(= y (- ms)) (- (+ base side hside) x) | |
(= x (- ms)) (+ base (* 2 side) hside y) | |
(= y ms) (+ base (* 3 side) hside x)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment