From c776ff1feb937ff64019eebcc6779a3f4b87291b Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 15 Apr 2010 20:39:59 -0600 Subject: [PATCH] adding functions for displaying graphs of propagator networks --- .gitignore | 1 + project.clj | 3 ++- propagator.org | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3ea2877..d21792f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # exported files *.html *.tex +*-source.org # tangled source file src/* diff --git a/project.clj b/project.clj index 59ddb7c..ea5dd08 100644 --- a/project.clj +++ b/project.clj @@ -1,5 +1,6 @@ (defproject propagator "1.0.0-SNAPSHOT" :description "Concurrent propagator system" :dependencies [[org.clojure/clojure "1.1.0-alpha-SNAPSHOT"] - [org.clojure/clojure-contrib "1.0-SNAPSHOT"]] + [org.clojure/clojure-contrib "1.0-SNAPSHOT"] + [vijual "0.1.0-SNAPSHOT"]] :dev-dependencies [[leiningen/lein-swank "1.0.0-SNAPSHOT"]]) \ No newline at end of file diff --git a/propagator.org b/propagator.org index dd2c93a..4821fdc 100644 --- a/propagator.org +++ b/propagator.org @@ -48,6 +48,28 @@ (agent nil :validator (fn [_#] (do (future (run-propagator ~neighbor)) true))) (fn [_# _#]))) #+end_src +* extensions +** graphs of the propagator network +#+begin_src clojure + (use 'vijual) + (import '(javax.swing JFrame JPanel) + '(java.awt Color Graphics) + '(java.awt.image BufferedImage)) + + (def dim [300 300]) + + (defn view "Display a graph generated by vijual" [img] + (let [mult 1.5 + width (* (.getWidth img) mult) + height (* (.getHeight img) mult) + offset 50 + frame (JFrame.) + panel (doto (proxy [JPanel] [] + (paint [g] + (.drawImage g img offset offset nil))))] + (doto frame (.add panel) .pack (.setSize (+ offset width) (+ offset height)).show))) +#+end_src + * usage ** doubling a number -- simplest #+begin_src clojure @@ -96,3 +118,4 @@ it should be possible to wrap these mutable items including in cells, so that the propagator system remains "pure" + -- 2.11.4.GIT