From 6eac5c37be08b7fe9c87914dad1eb69df5fcbfc2 Mon Sep 17 00:00:00 2001 From: nick rothwell Date: Sat, 2 Jun 2012 21:54:30 +0100 Subject: [PATCH] Demo patchers. --- README.md | 28 ++++++++- patchers/GRIDSTATE.maxpat | 37 +++++++++--- patchers/INTERACTION.maxpat | 112 +++++++++++++++++++++++++++++++++--- patchers/set-only.clj | 10 +++- trails/4-STATE.md | 23 ++++---- 5 files changed, 180 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a2af6a8..bc8df6c 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ The file of patchers and Clojure script files (`maxmsp-clojure-expo74.zip`) goes into the `patches` folder for Max (or anywhere in Max's search path). -Downloads available under this GitHub project if you have an account; otherwise, all -available from [Dropbox][dropbox]. +Downloads available under this GitHub project if you have an account; +otherwise, all available from [Dropbox][dropbox]. ## Java @@ -27,12 +27,33 @@ Terminal window prompts to start the installation process. For Windows, Java is downloadable from [Oracle][java]. The JRE (Java Runtime) will probably work, but I tested with the JDK. +## Getting Started + +The directory `trails` contains README files for a set of tutorials; +corresponding patchers are in the directory `patchers`. The directory +`DONE` contains completed exercises. + +More advanced examples can be found in the +source [net.loadbang.clojure][nl-clojure] project. + ## Other Software * Windows text editor: [Notepad++][npp] - supports editing of Lisp source. * OS X text editor: [TextMate][tm] - supports bracket matching. * Either platform: [jEdit][jedit] - native Java application. +## Original Sources + +All the `net.loadbang` sources are on GitHub: + +* [net.loadbang.clojure][nl-clojure] +* [net.loadbang.scripting][nl-scripting] +* [net.loadbang.lib][nl-lib] + +The other dependent libraries (`log4j`, and Clojure itself) are pulled +in via Maven in the build process; sources are also available for +these. + ## Online Resources * [Lisp (Wikipedia)][wlisp]. @@ -47,3 +68,6 @@ Runtime) will probably work, but I tested with the JDK. [tm]: http://macromates.com [jedit]: http://www.jedit.org [dropbox]: http://dl.dropbox.com/u/2546860/expo74-clojure-all.zip +[nl-clojure]: https://github.com/cassiel/net.loadbang.clojure +[nl-scripting]: https://github.com/cassiel/net.loadbang.scripting +[nl-lib]: https://github.com/cassiel/net.loadbang.lib diff --git a/patchers/GRIDSTATE.maxpat b/patchers/GRIDSTATE.maxpat index 738f0b3..8111208 100644 --- a/patchers/GRIDSTATE.maxpat +++ b/patchers/GRIDSTATE.maxpat @@ -4,10 +4,10 @@ "appversion" : { "major" : 6, "minor" : 0, - "revision" : 3 + "revision" : 4 } , - "rect" : [ 25.0, 50.0, 809.0, 793.0 ], + "rect" : [ 43.0, 50.0, 694.0, 793.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -54,10 +54,10 @@ "appversion" : { "major" : 6, "minor" : 0, - "revision" : 3 + "revision" : 4 } , - "rect" : [ 729.0, 179.0, 396.0, 252.0 ], + "rect" : [ 546.0, 101.0, 558.0, 418.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -78,6 +78,20 @@ "tags" : "", "visible" : 1, "boxes" : [ { + "box" : { + "fontname" : "Anonymous Pro", + "fontsize" : 12.0, + "id" : "obj-3", + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 250.0, 70.0, 56.0, 16.0 ], + "text" : "(clear)" + } + + } +, { "box" : { "fontname" : "Anonymous Pro", "fontsize" : 12.0, @@ -152,6 +166,15 @@ "source" : [ "obj-2", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-11", 0 ], + "disabled" : 0, + "hidden" : 0, + "source" : [ "obj-3", 0 ] + } + } , { "patchline" : { @@ -252,21 +275,21 @@ ], "dependency_cache" : [ { "name" : "g64c.Grid.maxpat", - "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers", + "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers", "patcherrelativepath" : "", "type" : "JSON", "implicit" : 1 } , { "name" : "g64c.Column.maxpat", - "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers", + "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers", "patcherrelativepath" : "", "type" : "JSON", "implicit" : 1 } , { "name" : "g64c.Cell.maxpat", - "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers", + "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers", "patcherrelativepath" : "", "type" : "JSON", "implicit" : 1 diff --git a/patchers/INTERACTION.maxpat b/patchers/INTERACTION.maxpat index 305902f..94b822e 100644 --- a/patchers/INTERACTION.maxpat +++ b/patchers/INTERACTION.maxpat @@ -4,10 +4,10 @@ "appversion" : { "major" : 6, "minor" : 0, - "revision" : 3 + "revision" : 4 } , - "rect" : [ 110.0, 47.0, 694.0, 793.0 ], + "rect" : [ 39.0, 49.0, 694.0, 780.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -53,10 +53,10 @@ "appversion" : { "major" : 6, "minor" : 0, - "revision" : 3 + "revision" : 4 } , - "rect" : [ 509.0, 86.0, 775.0, 330.0 ], + "rect" : [ -18.0, 55.0, 1118.0, 478.0 ], "bglocked" : 0, "openinpresentation" : 0, "default_fontsize" : 12.0, @@ -75,7 +75,65 @@ "description" : "", "digest" : "", "tags" : "", + "visible" : 1, "boxes" : [ { + "box" : { + "fontname" : "Anonymous Pro", + "fontsize" : 12.0, + "id" : "obj-7", + "linecount" : 2, + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 115.0, 155.0, 653.0, 28.0 ], + "text" : "(defn click [cx cy] (fundraw (fn [x y] (or (and (= cx x) ( <= (Math/abs (- cy y )) 2)) (and (= cy y) ( <= (Math/abs (- cx x )) 2))))))" + } + + } +, { + "box" : { + "fontname" : "Anonymous Pro", + "fontsize" : 12.0, + "id" : "obj-5", + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 125.0, 120.0, 194.0, 16.0 ], + "text" : "(defn hover [hx hy how] nil)" + } + + } +, { + "box" : { + "fontname" : "Anonymous Pro", + "fontsize" : 12.0, + "id" : "obj-3", + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 95.0, 205.0, 568.0, 16.0 ], + "text" : "(defn click [cx cy] (fundraw (fn [x y] (= (Math/abs (- cx x)) (Math/abs (- cy y))))))" + } + + } +, { + "box" : { + "fontname" : "Anonymous Pro", + "fontsize" : 12.0, + "id" : "obj-2", + "maxclass" : "message", + "numinlets" : 2, + "numoutlets" : 1, + "outlettype" : [ "" ], + "patching_rect" : [ 45.0, 75.0, 378.0, 16.0 ], + "text" : "(defn hover [hx hy how] ( fundraw (fn [x y] (= hx x ))))" + } + + } +, { "box" : { "fontname" : "Anonymous Pro", "fontsize" : 12.0, @@ -84,7 +142,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 60.0, 130.0, 463.0, 16.0 ], + "patching_rect" : [ 70.0, 95.0, 463.0, 16.0 ], "text" : "(defn hover [hx hy how] (fundraw (fn [x y] (and (= hx x) (= hy y)))))" } @@ -98,7 +156,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 110.0, 60.0, 568.0, 16.0 ], + "patching_rect" : [ 130.0, 25.0, 568.0, 16.0 ], "text" : "(defn click [cx cy] (fundraw (fn [x y] (if (or (= x cx) (= y cy)) [1 0 0] [0 0 0]))))" } @@ -116,6 +174,24 @@ } ], "lines" : [ { + "patchline" : { + "destination" : [ "obj-11", 0 ], + "disabled" : 0, + "hidden" : 0, + "source" : [ "obj-2", 0 ] + } + + } +, { + "patchline" : { + "destination" : [ "obj-11", 0 ], + "disabled" : 0, + "hidden" : 0, + "source" : [ "obj-3", 0 ] + } + + } +, { "patchline" : { "destination" : [ "obj-11", 0 ], "disabled" : 0, @@ -123,6 +199,15 @@ "source" : [ "obj-4", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-11", 0 ], + "disabled" : 0, + "hidden" : 0, + "source" : [ "obj-5", 0 ] + } + } , { "patchline" : { @@ -132,6 +217,15 @@ "source" : [ "obj-6", 0 ] } + } +, { + "patchline" : { + "destination" : [ "obj-11", 0 ], + "disabled" : 0, + "hidden" : 0, + "source" : [ "obj-7", 0 ] + } + } ], "dependency_cache" : [ ] @@ -223,21 +317,21 @@ ], "dependency_cache" : [ { "name" : "g64c.Grid.maxpat", - "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers", + "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers", "patcherrelativepath" : "", "type" : "JSON", "implicit" : 1 } , { "name" : "g64c.Column.maxpat", - "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers", + "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers", "patcherrelativepath" : "", "type" : "JSON", "implicit" : 1 } , { "name" : "g64c.Cell.maxpat", - "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers", + "bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers", "patcherrelativepath" : "", "type" : "JSON", "implicit" : 1 diff --git a/patchers/set-only.clj b/patchers/set-only.clj index e6634d8..06068a2 100644 --- a/patchers/set-only.clj +++ b/patchers/set-only.clj @@ -7,5 +7,13 @@ (defn draw [state] (fundraw (fn [x y] (get state [x y])))) +(defn clear [] + (draw (swap! the-state (fn [old] { } )))) + +;(defn click [x y] +; (draw (swap! the-state (fn [old] (assoc old [x y] true))))) + (defn click [x y] - (draw (swap! the-state (fn [old] (assoc old [x y] true))))) + (draw (swap! the-state + (fn [old] (assoc (assoc old [x y] true) + [(- 7 x) y] true))))) diff --git a/trails/4-STATE.md b/trails/4-STATE.md index dce3cb2..b73b9ad 100644 --- a/trails/4-STATE.md +++ b/trails/4-STATE.md @@ -4,25 +4,26 @@ Clojure wants to be purely functional - "variables" cannot be updated. Updatable variables must be created specially as *atoms*: - (def the-state (atom 0)) + (def the-state (atom 0)) Atom values are accessed by *dereferencing* - (deref the-state) - @the-state + (deref the-state) + @the-state An atom's value is changed by applying a function to its old value: - (swap! the-state (fn [x] (* x 2))) - (swap! the-state inc) + (swap! the-state (fn [x] (* x 2))) + (swap! the-state inc) This is done as a *transaction*. -An atom can contain a complex data structure - and an update function can partially alter it. +An atom can contain a complex data structure - and an update function +can partially alter it. - (def the-state (atom [])) + (def the-state (atom [])) - (swap! the-state (fn [x] (conj x 2))) - (swap! the-state (fn [x] (conj x (rand)))) - (swap! the-state pop) - (swap! the-state (fn [x] (vec (map inc x)))) + (swap! the-state (fn [x] (conj x 2))) + (swap! the-state (fn [x] (conj x (rand)))) + (swap! the-state pop) + (swap! the-state (fn [x] (vec (map inc x))))