This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
174 additions
and
36 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,16 @@ | ||
|
||
(use 'thor.lang) | ||
(use '(incanter core stats charts)) | ||
|
||
(defduration 100) | ||
|
||
(simulation-init) | ||
|
||
(def mt (atom ())) | ||
|
||
(at 10 | ||
(println "test " (get-current-time))) | ||
|
||
(at 20 | ||
(println "test2 " (get-current-time))) | ||
|
||
(every 5 | ||
(println "clock " (get-current-time) )) | ||
|
||
(at 15 | ||
(every 10 | ||
(println "clock2 " (get-current-time)) | ||
)) | ||
(every 1 (do | ||
(println "adding") | ||
(swap! mt concat (list (* (get-current-time) 2))))) | ||
|
||
(swap! mt conj | ||
(* (get-current-time) | ||
2)))) | ||
(at 100 | ||
(let [x (range 1 101) | ||
x_2 @mt] | ||
(view (bar-chart x x_2)))) | ||
|
||
x_2 (reverse @mt)] | ||
(view (bar-chart x x_2 :y-label "2*x")))) | ||
(simulation-run) |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
(ns | ||
thor.ui.node-viewer | ||
(:import [javax.swing JFrame JList JButton BoxLayout JPanel DefaultListModel BoxLayout ListSelectionModel JScrollPane ScrollPaneConstants ] | ||
[java.awt Dimension GridBagLayout BorderLayout] | ||
|
||
[javax.swing.event ListSelectionListener] | ||
)) | ||
|
||
(use '[incanter core processing io]) | ||
(def frame | ||
(doto (JFrame. "Project Thor") | ||
(.setDefaultCloseOperation (JFrame/EXIT_ON_CLOSE)) | ||
(.setSize (Dimension. 500 500)) | ||
)) | ||
|
||
(def radius 100) | ||
(def textValue (atom 0)) | ||
(def nodelist (atom ())) | ||
|
||
; keep a record of states to replay later | ||
(def states (atom {})) | ||
|
||
(def statesListModel (DefaultListModel.)) | ||
(def statesList (let [stateList (doto (JList. | ||
statesListModel) | ||
(.setSelectionMode ListSelectionModel/SINGLE_SELECTION) | ||
(.setFixedCellWidth 200) | ||
|
||
) | ||
] | ||
(doto stateList | ||
|
||
(.addListSelectionListener | ||
(proxy [ListSelectionListener] [] | ||
|
||
(valueChanged [evt] | ||
(let [selected (.getSelectedValue stateList)] | ||
(println "selected " selected ) | ||
(apply-state selected) | ||
) | ||
) | ||
) | ||
) | ||
|
||
) | ||
|
||
(JScrollPane. stateList ScrollPaneConstants/VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants/HORIZONTAL_SCROLLBAR_AS_NEEDED | ||
))) | ||
|
||
(defn add-states-to-list [model elements] | ||
(doseq [elem elements] | ||
(.addElement model elem) | ||
) | ||
) | ||
|
||
(defn get-sketch [] | ||
|
||
|
||
(sketch | ||
|
||
(setup [] | ||
(doto this | ||
|
||
(framerate 15) | ||
(size 500 500) | ||
(stroke-weight 1) | ||
) | ||
) | ||
(draw [] | ||
(doto this | ||
(background 255) | ||
(smooth) | ||
(fill 0) | ||
|
||
(text (format "Test:%d" @textValue) 0 16 )) | ||
|
||
(doseq [n @nodelist] | ||
(let [loc (-> n :location)] | ||
(doto this | ||
(fill 0) | ||
(ellipse (:x loc) (:y loc) 20 20) | ||
(fill 64 187 128 100) | ||
;(println loc) | ||
(ellipse (:x loc) (:y loc) radius radius) | ||
(fill 0) | ||
(text (format "Node %d" (:id n)) (:x loc) (:y loc)) | ||
)) | ||
|
||
))) | ||
|
||
) | ||
|
||
|
||
(def sktch (get-sketch)) | ||
|
||
(defn init-window [] | ||
|
||
(doto frame | ||
|
||
(.setLayout (BoxLayout. (.getContentPane frame) | ||
BoxLayout/X_AXIS | ||
)) | ||
(.add sktch) | ||
(.add statesList) | ||
(.setVisible true) | ||
) | ||
(.init sktch) | ||
) | ||
|
||
(defn apply-state [time] | ||
(let [state (get @states time)] | ||
(reset! textValue (:textValue state)) | ||
(reset! nodelist (:nodelist state)) | ||
)) | ||
|
||
(defn set-state [time {:keys [t nodes]}] | ||
(println "set-state") | ||
(swap! states assoc time | ||
{:textValue t | ||
:nodelist nodes | ||
} | ||
) | ||
(add-states-to-list | ||
statesListModel | ||
(list time)) | ||
(apply-state time) | ||
) | ||
|
||
(defn add-nodes [time {:keys [text nodes]}] | ||
(println nodes) | ||
(set-state time | ||
{:t text | ||
:nodes nodes}) | ||
|
||
;(reset! t tval) | ||
) |
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