Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Fractal-tree/Clojure/fractal-tree.clj
Normal file
26
Task/Fractal-tree/Clojure/fractal-tree.clj
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(import '[java.awt Color Graphics]
|
||||
'javax.swing.JFrame)
|
||||
|
||||
(defn deg-to-radian [deg] (* deg Math/PI 1/180))
|
||||
(defn cos-deg [angle] (Math/cos (deg-to-radian angle)))
|
||||
(defn sin-deg [angle] (Math/sin (deg-to-radian angle)))
|
||||
|
||||
(defn draw-tree [^Graphics g, x y angle depth]
|
||||
(when (pos? depth)
|
||||
(let [x2 (+ x (int (* depth 10 (cos-deg angle))))
|
||||
y2 (+ y (int (* depth 10 (sin-deg angle))))]
|
||||
(.drawLine g x y x2 y2)
|
||||
(draw-tree g x2 y2 (- angle 20) (dec depth))
|
||||
(recur g x2 y2 (+ angle 20) (dec depth)))))
|
||||
|
||||
(defn fractal-tree [depth]
|
||||
(doto (proxy [JFrame] []
|
||||
(paint [g]
|
||||
(.setColor g Color/BLACK)
|
||||
(draw-tree g 400 500 -90 depth)))
|
||||
(.setBounds 100 100 800 600)
|
||||
(.setResizable false)
|
||||
(.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
|
||||
(.show)))
|
||||
|
||||
(fractal-tree 9)
|
||||
Loading…
Add table
Add a link
Reference in a new issue