4 (import '(javax.swing JFrame JPanel)
5 '(java.awt Color Graphics)
6 '(java.awt.image BufferedImage))
8 ;; saving graph information
9 ;; record keeping for graphing propagators
11 (defmacro remember-prop [name in-cells out-cells]
15 {:in-cells (map (fn [x#] (name x#)) (quote ~in-cells))
16 :out-cells (map (fn [x#] (name x#)) (quote ~out-cells))})))
18 (defmacro propagator "Define a new propagator."
19 [name in-cells out-cells & body]
21 (remember-prop ~name ~in-cells ~out-cells)
22 (defn ~(with-meta name
24 :in-cells in-cells :out-cells out-cells))
26 (doseq [cell# ~in-cells] (add-neighbor cell# ~name))
34 (defn view "Display a graph generated by vijual" [img]
36 width (* (.getWidth img) mult)
37 height (* (.getHeight img) mult)
39 panel (doto (proxy [JPanel] []
41 (.drawImage g img offset offset nil))))]
42 (doto frame (.add panel) .pack (.setSize (+ offset width) (+ offset height)).show)))
44 (defn graph-propagators []
48 (let [hsh (get prop-graph key)]
50 (map #(vec (list % (name key))) (get hsh :in-cells))
51 (map #(vec (list (name key) %)) (get hsh :out-cells)))))
52 (keys prop-graph))))))
55 (view (draw-directed-graph-image (graph-propagators))))
57 (defn clear-network []
59 (def frame (JFrame.)))