Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Animation/Clojure/animation.clj
Normal file
33
Task/Animation/Clojure/animation.clj
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(import '[javax.swing JFrame JLabel])
|
||||
(import '[java.awt.event MouseAdapter])
|
||||
|
||||
(def text "Hello World! ")
|
||||
(def text-ct (count text))
|
||||
(def rotations
|
||||
(vec
|
||||
(take text-ct
|
||||
(map #(apply str %)
|
||||
(partition text-ct 1 (cycle text))))))
|
||||
|
||||
(def pos (atom 0)) ;position in rotations vector being displayed
|
||||
(def dir (atom 1)) ;direction of next position (-1 or 1)
|
||||
|
||||
(def label (JLabel. text))
|
||||
|
||||
(.addMouseListener label
|
||||
(proxy [MouseAdapter] []
|
||||
(mouseClicked [evt] (swap! dir -))))
|
||||
|
||||
(defn animator []
|
||||
(while true
|
||||
(Thread/sleep 100)
|
||||
(swap! pos #(-> % (+ @dir) (mod text-ct)))
|
||||
(.setText label (rotations @pos))))
|
||||
|
||||
(doto (JFrame.)
|
||||
(.add label)
|
||||
(.pack)
|
||||
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
|
||||
(.setVisible true))
|
||||
|
||||
(future-call animator) ;simple way to run animator on a separate thread
|
||||
Loading…
Add table
Add a link
Reference in a new issue