Permalink
Browse files

Bit of condensing

  • Loading branch information...
1 parent acf74b8 commit e3ba8aa97e391a80ba042b7ca00db6fe637b7ec8 @fffej committed Dec 31, 2008
Showing with 5 additions and 11 deletions.
  1. +5 −11 sortapp.clj
View
@@ -13,20 +13,18 @@
(take (count lst) (iterate bubble lst)))
(def maxval 100)
-
(def initial-list (take 100 (repeatedly (fn [] (rand-int maxval)))))
-
(def position (atom 0))
(def canvas (proxy [JPanel ActionListener] []
(paintComponent [g]
(proxy-super paintComponent g)
(.setColor g Color/RED)
- (let [width (.getWidth this) height (.getHeight this) barHeight (/ height (inc (count initial-list))) barWidthPerVal (/ width maxval)
+ (let [width (.getWidth this) height (.getHeight this) bar-height (/ height (inc (count initial-list))) val-width (/ width maxval)
bubble-sorted (bubble-sort initial-list)]
(doseq [val (into (sorted-map) (zipmap (range 0 (count initial-list)) (nth bubble-sorted @position)))]
- (let [y (int (* (first val) barHeight)) barWidth (int (* (second val) barWidthPerVal))]
- (.fillRect g 0 y barWidth barHeight)))))
+ (let [y (int (* (first val) bar-height)) barWidth (int (* (second val) val-width))]
+ (.fillRect g 0 y barWidth bar-height)))))
(actionPerformed [e] (swap! position inc) (compare-and-set! position (count initial-list) 0) (.repaint this))))
(let [x (Timer. 50 canvas)]
@@ -35,15 +33,11 @@
(defn is-running [] (.isRunning x)))
(defn sortapp []
- (let [frame (JFrame. "Sort Visualizer")
- algorithm-chooser (JComboBox.)
- run-button (JButton. "Go")]
+ (let [frame (JFrame. "Sort Visualizer")run-button (JButton. "Go")]
(.addActionListener run-button
(proxy [ActionListener] []
(actionPerformed [evt]
- (if (is-running)
- (stop-timer)
- (start-timer)))))
+ (if (is-running) (stop-timer) (start-timer)))))
(doto frame
(.setLayout (BorderLayout. 3 3))
(.add canvas (BorderLayout/CENTER))

0 comments on commit e3ba8aa

Please sign in to comment.