Guest User

Untitled

a guest
Sep 1st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn hyp [x y r]
  2.   (Math/sqrt (+ (Math/pow (Math/abs (- r x)) 2)
  3.                 (Math/pow (Math/abs (- r y)) 2))))
  4.  
  5. (defn dist [x y r] (Math/abs (- (hyp x y r) r)))
  6.  
  7. (defn circle [r]
  8.   (let [rep (for [x (range (inc (* r 2))) y (range (inc (* r 4)))]
  9.               {:x x :y y :val \ })
  10.         circle? (fn [c] (let [d (dist (:x c) (double (/ (:y c) 2)) r)]
  11.                           (cond (<= d 0.25) \#
  12.                                 (<= d 0.75) \=
  13.                                 (<= d 1.5) \-
  14.                                 :else \ )))]
  15.     (map circle? rep)))
  16.  
  17. (defn group [r c]
  18.   (let [tail (drop r c)]
  19.     (if (empty? tail)
  20.       [c]
  21.       (lazy-cat [(take r c)] (group r tail)))))
  22.  
  23. (defn get-rows [c] (map #(apply str %) c))
  24.  
  25. (defn echo-circle [c] (doall (map prn c)))
  26.  
  27. (defn simple-circle [r] (get-rows (group (inc (* r 4)) (circle r))))
  28.  
  29. ; IDEA:
  30. ; Given radius r,
  31. ;   iterate over 0 - r * 2 rows
  32. ;   Decide for 0 - r * 4 columns
  33. ; (Can be done in parallel ie multi-dim seq of agents)
  34. ; Just str the seq
  35.  
  36. (echo-circle (simple-circle 10))
Add Comment
Please, Sign In to add comment