<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Backspaces &#187; Hacks</title>
	<atom:link href="http://backspaces.net/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://backspaces.net</link>
	<description>Applied Complexity for the Rest of Us</description>
	<lastBuildDate>Sat, 17 Sep 2011 03:14:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SFX CS590, WebGL, and Shaders</title>
		<link>http://backspaces.net/54/sfx-cs590-webgl-and-shaders/</link>
		<comments>http://backspaces.net/54/sfx-cs590-webgl-and-shaders/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 03:05:49 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/?p=54</guid>
		<description><![CDATA[Note: this is just a quick overview of the SFX UNM CS590 course.  More in depth later! Just finished a nifty experimental educational stunt at the Santa Fe Complex (SFX): taking the UNM CS590 course taught by Ed Angel .. but given in Santa Fe at SFX to a group of folks interested in a [...]]]></description>
			<content:encoded><![CDATA[<p><em>Note: this is just a quick overview of the SFX UNM CS590 course.  More in depth later!</em></p>
<p>Just finished a nifty experimental educational stunt at the <a href="http://sfcomplex.org/">Santa Fe Complex</a> (SFX): taking the <a href="http://www.cs.unm.edu/~angel/BOOK/INTERACTIVE_COMPUTER_GRAPHICS/SIXTH_EDITION/">UNM CS590</a> course taught by <a title="Ed Angel @ UNM" href="https://www.cs.unm.edu/~angel/">Ed Angel</a> .. but given in Santa Fe at SFX to a group of folks interested in a wide variety of topics, from GPU programming to game programming to high performance parallel computation to ambient computing combining projectors and cameras to do computing in your spatial environment .. your whiteboards, rooms and domes.</p>
<p>Ed had just finished a <a title="Interactive Computer Graphics: A Top-Down Approach with Shader-Based OpenGL" href="http://www.pearsonhighered.com/educator/product/Interactive-Computer-Graphics-A-TopDown-Approach-with-ShaderBased-OpenGL/9780132545235.page">major rewrite of his textbook</a> to be <a title="GPU Shader Programs" href="http://en.wikipedia.org/wiki/Shader_(realtime,_logical)">Shader</a> based.  Shaders are programs running in your computer&#8217;s GPU chip with very fast matrix manipulations of huge number of vertices.  Not only were shaders a new addition to CS590, but <a href="http://www.khronos.org/opengl">OpenGL</a> itself had morphed considerably .. including not only the desktop C/C++ version, but also <a title="GLES for Embedded Systems " href="http://www.khronos.org/opengles/">GLES</a>, the Embedded Systems (phones and tablets, mainly) but the HTML5 <a title="WebGL" href="http://www.khronos.org/webgl/">WebGL</a> variant.  Within the class we had all versions being used.</p>
<p>I chose to use WebGL, mainly using Google Chrome, WebKit (Safari&#8217;s developer build), and Firefox .. all of which have most of HTML5 implemented.  The <a title="WebGL specs" href="http://www.khronos.org/registry/webgl/specs/latest/">documentation</a> was pretty raw but fortunately the <a href="http://learningwebgl.com/blog/">Learning WebGL</a> site is extraordinarily useful.</p>
<p>We had three fascinating homework assignments, plus a final project if taking the course for graduate school credits:</p>
<ul>
<li>Homework 1: <a title="Tessellation and OpenGL/WebGL practice." href="http://backspaces.net/CS591/hw1/hw1.html">Tessellation and Introduction to WebGL</a>.</li>
<li>Homework 2: <a title="Rubik’s Cube" href="http://backspaces.net/CS591/hw2/hw2.html">Rubik’s Cube</a></li>
<li>Homework 3: <a title="Maze Traversal" href="http://backspaces.net/CS591/hw3/hw3.html">Maze Traversal</a></li>
<li>Final Project: GPU Intensive Agent Based Model: <a href="http://backspaces.net/CS591/netlogo/netlogo0.html">Before</a> and <a href="http://backspaces.net/CS591/netlogo/netlogo1.html">After</a>.</li>
<li>Final Project Min Series: Several Minimal <a href="http://backspaces.net/CS591/min/">WebGL Experiments</a> for the final project.</li>
</ul>
<p>I kept stumbling over unsuspected surprises while doing these:</p>
<ul>
<li>Javascript: Holy cow, its Lisp without parens!  Closures etc.  Start with <a href="http://javascript.crockford.com/">Crockford</a> and <a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742">Good/Bad/Ugly</a>.</li>
<li>Self Documenting: Wow, WebGL is in a web page, I can do my <a href="http://backspaces.net/CS591/hw1/hw1.html">write-up next to the 3D model</a>!</li>
<li>HTML5: Not just 2D/3D Canvases but <a href="http://diveintohtml5.org/">way way more</a>!</li>
<li>GPU Programming: Thinking about 100&#8242;s of processors so dumb they can&#8217;t share data!</li>
<li>Interpreter: Because JS and all its libraries are just text, you can read the <a href="http://backspaces.net/CS591/hw1/hw1.html.txt">code</a> and <a href="http://backspaces.net/CS591/hw1/glx.js">libraries</a> easily.</li>
</ul>
<p>That&#8217;s all for now, just wanted to finally get this stuff posted.  All the source can be gotten from the <a href="http://backspaces.net/CS591/">CS591 directory</a>.  The zip files make downloads easy as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/54/sfx-cs590-webgl-and-shaders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing: .. with Jython</title>
		<link>http://backspaces.net/30/processing-with-jython/</link>
		<comments>http://backspaces.net/30/processing-with-jython/#comments</comments>
		<pubDate>Sun, 29 Oct 2006 18:08:50 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=30</guid>
		<description><![CDATA[	<p>Last article showed how we could use <a href="http://processing.org">Processing</a> with Eclipse and Java 1.5.  Heady with success, I decided to try to convert the near-trivial <a href="http://backspaces.net/models/RandBoxes/applet">RandBoxes</a> Processing demo to Jython.</p>

	<p>Why??  Well, our group uses Blender quite a bit, and Blender uses Python as its scripting language.  More generally, Python is quite popular within our scientific community.</p>

	<p><a href="http://www.jython.org/Project/index.html">Jython</a>, a Python implementation using the <span class="caps">JVM</span>, has been surprisingly successful,    having most of what we like about CPython.  And its Java integration made it a natural for Processing.  <a href="http://itmaurer.com/jython/htdocs/presentation.html">This presentation</a> is a good overview.</p>]]></description>
			<content:encoded><![CDATA[<p>Last article showed how we could use <a href="http://processing.org">Processing</a> with Eclipse and Java 1.5.  Heady with success, I decided to try to convert the near-trivial <a href="http://backspaces.net/models/RandBoxes/applet">RandBoxes</a> Processing demo to Jython.</p>
<p>Why??  Well, our group uses Blender quite a bit, and Blender uses Python as its scripting language.  More generally, Python is quite popular within our scientific community.</p>
<p><a href="http://www.jython.org/Project/index.html">Jython</a>, a Python implementation using the <span class="caps">JVM</span>, has been surprisingly successful,    having most of what we like about CPython.  And its Java integration made it a natural for Processing.  <a href="http://itmaurer.com/jython/htdocs/presentation.html">This presentation</a> is a good overview.</p>
<h3>Java</h3>
<p>Here’s the Java 1.4 code we’re starting with, the Processing .java file created when creating the applet above.  A few notes:</p>
<ol>
<li>The two methods setup() and draw() are required by PApplet.</li>
<li>Class Box is an inner class, as is usual for Processing, because:</li>
<li>Several utilities are in PApplet like color(), random() and all drawing methods.  Use of inner classes lets you “inherit” these.</li>
</ol>
<pre>public class RandBoxes extends PApplet {
  int numBoxes = 1000;
  ArrayList boxes = new ArrayList();

  public void setup() {
    size(600, 500, JAVA2D);
    while(boxes.size() &lt; numBoxes)
      boxes.add(new Box(random(width), random(height)));
    println("number of boxes = "+boxes.size());
  }
  public void draw() {
    background(128);
    for (int i = 0; i &lt; boxes.size(); i++)
      ((Box) boxes.get(i)).step();
    if (frameCount%10==0)
      println("frameRate="+frameRate+" frameCount="+frameCount);
  }

  class Box {
    int c = color(255, 255, 0);
    float x, y;
    Box(float x, float y) {
      this.x = x;
      this.y = y;
    }
    public void step() {
      x = max(min(x+random(-1, 1), width), 0);
      y = max(min(y+random(-1, 1), height), 0);
      paint();
    }
    public void paint() {
      noStroke();
      fill(c);
      rect(x-2, y-2, 5, 5);
    }
  }
}</pre>
<h3>Jython</h3>
<p>Here’s the Jython I eventually came up with.  Note this is not “pythonic” yet, but at least runs.  Goals:</p>
<ol>
<li>Be able to run as an applet if possible</li>
<li>Avoid a “proxy class” subclass of PApplet even though that’s a common stunt to make Jython usage simpler .. i.e. hide any Processing or Jython “warts”!  See the Thoughts for an example.</li>
<li>Run easily in the standard Jython environment</li>
</ol>
<p>To run,</p>
<p>export CLASSPATH=~/local/processing/lib/core.jar:.</p>
<p>then put this in any file <em>other than</em> RandBoxes.py (see notes).  I use RandBoxesTest.py :</p>
<pre>from javax.swing import JFrame
from processing.core import PApplet
from random import uniform

winWidth=600
winHeight=500
numBoxes = 1000
boxes = []

class RandBoxes (PApplet):
  def __init__(self):
    pass
  def setup(self):
    self.size(winWidth, winHeight, self.JAVA2D)
    while len(boxes)&lt;numBoxes:
      boxes.append(
        Box(self, uniform(0,winWidth),uniform(0,winHeight)))
    print "number of boxes = %d" % len(boxes)
  # rqd due to PApplet's using frameRate and frameRate(n) etc.
  def getField(self, name):
    return self.class.superclass.getDeclaredField(name).get(self)
  def draw(self):
    self.background(128)
    for b in boxes: b.step()
    if self.frameCount % 10 == 0:
      print "frameRate=%f frameCount=%i" %
      (self.getField('frameRate'), self.frameCount)

class Box(object):
  def __init__(self, p, x, y):
    self.p = p
    self.x = x
    self.y = y
    self.c = p.color(255,255,0)
  def step(self):
    self.x = max(min(self.x+uniform(-1,1),winWidth),0)
    self.y = max(min(self.y+uniform(-1,1),winHeight),0)
    self.paint()
  def paint(self):
    self.p.noStroke()
    self.p.fill(self.c)
    self.p.rect(self.x-2,self.y-2,5,5)

if __name__ == '__main__':
  frame = JFrame(title="Processing",
    resizable = 0,
    defaultCloseOperation=JFrame.EXIT_ON_CLOSE)
  panel = RandBoxes()
  frame.add(panel)
  panel.init()
  while panel.defaultSize and not panel.finished:
    pass
  frame.pack()
  frame.visible = 1</pre>
<h3>Notes:</h3>
<ul>
<li>My first try did not use the 4 “global” variables: winWidth, winHeight, .. but it was pointed out to me that its more pythonic to use globals like this, and avoids overuse of “self”.</li>
<li>Similarly, to avoid way too many uses of “self.random()” and so on, I migrated to using Python utilities for max, min, random.uniform, and so on.  You can tell I was beset with way, way too many uses of self.foo()!</li>
<li>I tried using inner-classes within Jython, but apparently that doesn’t work, even with __future__ nested_scope.  The <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409366"><span class="caps">ASPN</span> Cookbook</a> discusses solutions, but I decided simply to pass in the PApplet instance to the Box constructor.  Not sure what the most pythonic solution would be, but being explicit doesn’t hurt.</li>
<li>I chose to use JFrame for putting my PApplet subclass in an application even though PApplet has a main() that I could call.  (PApplet, like many Java Applets, has a main for running as an application).  I did this for three reasons: to learn Jython’s Java integration, to use the Python “if __name__” cliche, and to avoid having to use jythonc to create a .class file everytime I made a change.  The latter was a subtle point caused by the main() in PApplet actually running your class file.</li>
<li>The getField() utility was needed to disambiguate frameRate, a variable, and frameRate(), a method, both in PApplet.  This was a gift from Jeff Emanuel on the <a href="http://www.nabble.com/jython-users-f4123.html">jython-users list</a></li>
<li>I <em>did</em> succeed in building an Applet, see below.  This used jythonc to build a true Java .class file, and has facilities for including the Jython core libraries as well your Jython source.</li>
<li>The .py file cannot be RandBoxes.py due to a jythonc convention which creates a main() for the outermost Jython code.  This main throws an exception, which does not match the standard Java main() signature.  Because PApplet has its own standard Java main(), jython flags an error and stops.  And, yes, you can bet this took a <strong>long</strong> time to fine!</li>
</ul>
<h3>Applet</h3>
<p>To build the Applet, I used this jythonc command:</p>
<pre>jythonc -J-g:none --core --deep --jar RandBoxes.jar RandBoxesTest.py</pre>
<p>The applet tag looks like:</p>
<pre>  &lt;applet code="RandBoxesTest$RandBoxes"
         archive="RandBoxes.jar,core.jar"
         width=600 height=500&gt;
  &lt;/applet&gt;</pre>
<p>The Applet, and similar links, are here:</p>
<ul>
<li><a href="http://backspaces.net/models/RandBoxesPy/">The Jython Applet</a></li>
<li><a href="http://backspaces.net/models/RandBoxesPy/run.txt">The build shell script</a></li>
<li><a href="http://backspaces.net/models/RandBoxesPy/index.txt">index.html file</a></li>
<li><a href="http://backspaces.net/models/RandBoxesPy/RandBoxesTest.py">RandBoxesTest.py</a></li>
</ul>
<h3>Thoughts</h3>
<ul>
<li>Jython is for real:  It interoperates well with Java, implements a recent enough version of the Python language, has a good support forum and documentation.</li>
<li>This wasn’t easy, but was made possible due to the Jython community and website, and the Jython books (I used Jython for Java Programmers)</li>
<li>There is friction between Jython and Java, and is likely to remain there.  This will require Jython users trying to integrate with Java to smooth the way somehow.  Reflection, like in getField(), can help.  Also, Proxy classes are a very reasonable approach.  I used this initially, and then had the Jython code subclass PAppletProxy rather than PApplet :</li>
</ul>
<pre>        import processing.core.*;
        public class PAppletProxy extends PApplet {
          public float getFrameRate() {
            return frameRate;
          }
        }</pre>
<ul>
<li>Python: well, there’s good and bad.  Its a well crafted language, but I certainly made all the blunders newbies make: I got my indentation wrong, found myself using self.foo() way, way too much, and wished for standard lexical scoping.  But boy is the code clean.</li>
<li>Performance:  Java’s RandBoxes runs at about 40fps, while the Jython version runs at about 6-7fps, around 7 times slower, give or take.  This is really unfair in a way, I’m such a Jython newbie, and this is definitely a difficult task.  And for rapid prototyping, that sort of decrease may easily be acceptable.  I think if it were more like 2-3 times slower, that would be fine.  Any suggestions welcome!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/30/processing-with-jython/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Processing: .. with Eclipse</title>
		<link>http://backspaces.net/29/processing-with-eclipse/</link>
		<comments>http://backspaces.net/29/processing-with-eclipse/#comments</comments>
		<pubDate>Tue, 17 Oct 2006 22:49:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=29</guid>
		<description><![CDATA[	<p>We at <a href="http://redfish.com">Redfish</a> have been using <a href="http://processing.org">Processing.org&#8217;s</a> graphics system for models requiring fairly sophisticated 3D capabilities.  Here&#8217;s an example prototype of the <a href="http://backspaces.net/models/Stadium/applet/">Pittsburgh <span class="caps">PNC</span> Baseball Stadium</a> done with Processing.  (Note: Our Redfish site has more information on the <a href="http://www.redfish.com/stadium/">project page.</a></p>

	<p>Processing is more than a graphics library, it has a delightful <span class="caps">IDE</span> which makes Java much easier, especially for the Java novice.  The <span class="caps">IDE</span> has great tools such as a web-page builder with the project as an applet.  It also can build an application version for Mac, Windows and Linux.</p>

	<p>One difficulty we faced however, was that we wanted to commit to fairly complicated models that would benefit from Java 1.5 (Processing uses an earlier version) and an <span class="caps">IDE</span> familiar to Java programmers.  We also are interested in interfacing Java to other languages such as Groovy, Python/Jython, Ruby/JRuby, and even JavaScript/Rhino.</p>

	<p>So I decided to experiment with Processing, using Eclipse and Java 1.5.  To do this, I made two models: <a href="http://backspaces.net/models/RandBoxes/applet/">RandBoxes</a>, which is really simple .. just showing 1000 boxes and randomly jiggling them each step.  The second model, <a href="http://backspaces.net/models/RoadGrid/applet/">RoadGrid</a>, is more complicated: it draws a rectangular road grid and has &#8220;cars&#8221; (rectangles) moving along the roads.  At each intersection, the cars randomly chose a new road segment.</p>]]></description>
			<content:encoded><![CDATA[<p>We at <a href="http://redfish.com">Redfish</a> have been using <a href="http://processing.org">Processing.org’s</a> graphics system for models requiring fairly sophisticated 3D capabilities.  Here’s an example prototype of the <a href="http://backspaces.net/models/Stadium/applet/">Pittsburgh <span class="caps">PNC</span> Baseball Stadium</a> done with Processing.  (Note: Our Redfish site has more information on the <a href="http://www.redfish.com/stadium/">project page.</a></p>
<p>Processing is more than a graphics library, it has a delightful <span class="caps">IDE</span> which makes Java much easier, especially for the Java novice.  The <span class="caps">IDE</span> has great tools such as a web-page builder with the project as an applet.  It also can build an application version for Mac, Windows and Linux.</p>
<p>One difficulty we faced however, was that we wanted to commit to fairly complicated models that would benefit from Java 1.5 (Processing uses an earlier version) and an <span class="caps">IDE</span> familiar to Java programmers.  We also are interested in interfacing Java to other languages such as Groovy, Python/Jython, Ruby/JRuby, and even JavaScript/Rhino.</p>
<p>So I decided to experiment with Processing, using Eclipse and Java 1.5.  To do this, I made two models: <a href="http://backspaces.net/models/RandBoxes/applet/">RandBoxes</a>, which is really simple .. just showing 1000 boxes and randomly jiggling them each step.  The second model, <a href="http://backspaces.net/models/RoadGrid/applet/">RoadGrid</a>, is more complicated: it draws a rectangular road grid and has “cars” (rectangles) moving along the roads.  At each intersection, the cars randomly chose a new road segment.</p>
<p>By a very fortunate coincidence, the Processing team had just done a fairly <a href="http://tinyurl.com/me99h">major cleanup</a>, making their system work nicely in Eclipse.  So I built a new Eclipse project, including the Processing core.jar file and the Processing JavaDocs, and using the Java 1.5 <span class="caps">SDK</span>.</p>
<p>The Processing <span class="caps">IDE</span> puts its code fragments into .pde (Processing Development Environment) files which the web-page builder includes in the applets above.  Here’s the <a href="http://backspaces.net/models/RandBoxes/applet/RandBoxes.pde">RandBoxes .pde file.</a> Note that there is no Class defined, nor imports.  The Processing <span class="caps">IDE</span> handles that for you by generating a java file automatically.  Here’s the RandBoxes.java file <a href="http://backspaces.net/models/RandBoxes/applet/RandBoxes.java">before</a> and <a href="http://backspaces.net/models/RandBoxes/eclipse/RandBoxes.java">after</a> formatting by Eclipse.  Note how the <span class="caps">IDE</span> “wraps” the .pde file in a class and adds a Main(), as per the Java norm.  It also does other preprocessing like changing the “color” type to a Java “int”.</p>
<p>Well, imaging my surprise when after dumping the above file into Eclipse, although it had many warnings, it none the less compiled and ran, both as an applet and as an application!  Here’s what Eclipse looked like:<br />
<img title="Eclipse Processing Warnings" src="/images/3.png" alt="Eclipse Processing Warnings" /></p>
<p>The next step was to upgrade the .java file to be 1.5 savy: removing unnecessary imports, migrating to generics, using the for/in loop and so on.  This resulted in the <a href="http://backspaces.net/models/RandBoxes/eclipse/RandBoxes1.java">RandBoxes1.java file</a>.</p>
<h3>Some code examples:</h3>
<p>Using generics, this:</p>
<pre>ArrayList cars = new ArrayList();
for (int i = 0; i&lt;cars.size(); i++)
     ((Agent) cars.get(i)).step();</pre>
<p>.. converted to:</p>
<pre>ArrayList&lt;Agent&gt; cars = new ArrayList&lt;Agent&gt;();
for (Agent car : cars) car.step();</pre>
<p>Converting to the new printf() facility, using a “static import”, this:</p>
<pre>println("frameRate="+frameRate
        +" frameCount="+frameCount);</pre>
<p>.. converted to:</p>
<pre>import static java.lang.System.out; // NOTE Static Import
...
out.printf("frameRate=%.2f frameCount=%dn",
            frameRate, frameCount);</pre>
<p>Another nifty 1.5-ism was using Generic methods.  Their syntax is a bit odd, but it sure is great not having to use casts all over the place!  Here’s an example taken from the second demo, RoadGrid.  This old-style method:</p>
<pre>public Object randomOneOf(ArrayList a) {
    return a.get(randomInt(a.size()));
}</pre>
<p>now looks like:</p>
<pre>public &lt;T&gt; T randomOneOf(ArrayList&lt;T&gt; a) {
    return a.get(randomInt(a.size()));
}</pre>
<p>After “modernizing” to 1.5, Eclipse shows no warnings:<br />
<img title="Eclipse Processing Update to 1.5" src="/images/2.png" alt="Eclipse Processing Update to 1.5" /></p>
<p>So Processing with Eclipse is working like a charm, and lets us use the latest Java version, use the JavaDocs easily, and even browse the Processing code.  And with a little hand tweaking of Processing’s IDE-generated web page, we can even use the new Java 1.5 applet.</p>
<p>One downside: many browsers are not yet using 1.5 so will not be able to view the newer version.  But a solution is <a href="http://retroweaver.sourceforge.net/">RetroWeaver</a> which converts a 1.5 class back to its 1.4 format, thus potentially letting us use Eclipse, Java 1.5, Processing .. yet deploying for 1.4 browsers.</p>
<p>We’ll follow up shortly with some other experiments with Processing with other languages .. stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/29/processing-with-eclipse/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MOTH: My way Or The Highway</title>
		<link>http://backspaces.net/28/moth-my-way-or-the-highway/</link>
		<comments>http://backspaces.net/28/moth-my-way-or-the-highway/#comments</comments>
		<pubDate>Sat, 20 Aug 2005 02:17:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=28</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<p>Last year, Nick Thompson, Professor of Psychology and Ethology of Clark University, dropped by Santa Fe on Sabbatical.  Nick brought with him a puzzle relating to the <a href="http://en.wikipedia.org/wiki/Prisoner%27s_dilemma">Prisoner&#8217;s Dilemma</a>.</p>
<p>The core idea of the Prisoner&#8217;s Dilemma is a game where two folks choose to cooperate or not (defect).  The scoring is such that if you cooperate and your opponent defects, you (the &#8220;sucker&#8221;) get quite a low score.  If you both cooperate, however, you get a reasonable score but not as high as a defector gets against a cooperator.  This classic in game theory poses the paradox that your best move is to defect, even though if you both defect, you both get a very poor score.  Grim.</p>
<p><a href="http://www-personal.umich.edu/~axe/">Robert Axelrod</a> was puzzled by this, and suggested that if the game were repeated (iterated), the best outcome would could vary according to the strategy of the players.  This resulted in his now famous computer tournament pairing strategies against one another.  The sweet result was that a firm but friendly strategy, Tit for Tat, which cooperated initially, then simply repeated the opponent&#8217;s previous move from then on, was the overall winner.</p>
<p>Nick, looking at this, thought that it&#8217;d be nuts to stay in a series of Prisoner&#8217;s Dilemma games if the opponent was clearly no fun to work with.  Thus he introduced the idea of leaving the tournament.  <span class="caps">MOTH,</span> My way Or The Highway, builds a new suite of strategies which have the additional capability of leaving an unpleasant encounter.  This creates a pool of strategies without partners, so they are re-paired randomly, and the tournament continues.</p>
<p>The result is that Nick, along with several of our local <a href="http://friam.org">Friam group</a> here in Santa Fe, worked on a NetLogo model exploring this new approach.  This model expanded upon and validated <a href="http://aleph0.clarku.edu/%7Edjoyce/Moth/">earlier work</a> done by Nick and his colleagues David Joyce and John Kennison. This resulted in a paper delivered to the <a href="http://hcs.ucla.edu/arrowhead2005.htm">Lake Arrowhead Conference</a> on Human Complex Systems.</p>
<p>The <a href="/models/Moth.html">NetLogo Model</a> we created is viewable by you, gentle reader.  The explanation provided with the model presents considerable detail about the ideas behind the Moth strategy.</p>
<p>Not surprisingly, a quite successful strategy is a variation of Tit for Tat: play Tit for Tat and on the first defection by your opponent, leave the tournament to be paired with a (hopefully!) more cooperative player!</p>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/28/moth-my-way-or-the-highway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetLogo: Cruising Model</title>
		<link>http://backspaces.net/23/netlogo-cruising-model/</link>
		<comments>http://backspaces.net/23/netlogo-cruising-model/#comments</comments>
		<pubDate>Sat, 02 Oct 2004 01:28:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=23</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got an initial version of a NetLogo model with <a href="/models/cruise.html">cars cruising</a> on a map of Santa Fe, <span class="caps">NM. </span> This was done as a proof of concept with summer students working in the <a href="http://redfish.com">RedfishGroup</a>. </p>
<p>Their project included working with the Santa Fe police on understanding the dynamics of cruising around the plaza, a center of Santa Fe activities.</p>
<p>This model is somewhat unusual due to using tiny patches: 2&#215;2 pixels each!  Generally the patch size is considerably larger.  The challenge was to use a <span class="caps">GIS </span>generated map of the downtown area, and to import this into NetLogo so that the patches gave a feel of a map image.  This has been pushed to 1 pixel patches with no difficulty other than the time needed to import the image.</p>
<p>The <a href="/models/cruise.jpg">jpg image</a> was processed by converting it into the <a href="/models/cruise.ppm.txt"><span class="caps">PPM </span>image</a> (portable pix map) text graphics format, then using the NetLogo <a href="http://ccl.northwestern.edu/netlogo/docs/dictionary.html#rgb">rgb primitive</a> to convert that image to a format NetLogo could use.  It was then written back out to a <a href="/models/cruise.dat">data file</a> consisting of only the NetLogo integer color values used by the model&#8217;s patches.</p>
<p>The final hack was to literally cut &#38; paste the data file into the NetLogo program file (.nlogo file) as an array!  This avoided some Java security problems concerning file access that will go away with the current NetLogo beta.  But it works so well, we may just keep it for a bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/23/netlogo-cruising-model/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Textpattern 1.0rc1: Boy, that was easy!</title>
		<link>http://backspaces.net/22/textpattern-10rc1-boy-that-was-easy/</link>
		<comments>http://backspaces.net/22/textpattern-10rc1-boy-that-was-easy/#comments</comments>
		<pubDate>Fri, 01 Oct 2004 23:34:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=22</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<p>Being new to textpattern, I was delighted  to see how easy it was to update from g1.19 to 1.0rc1.  Deanload the bundle, unpack it, move the old &#8230;/textpattern to the side, replacing it with the deanload, and copy in my prior config.php file.</p>
<p>That&#8217;s it!  I keep a mirror of the site on my laptop, and both upgrades were that simple.</p>
<p>The new system has some sweet features such as separating the edit articles page from the articles themselves, making it easier to manage existing articles.  Also can specify how many articles show on a page .. nice for modem users I suspect.</p>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/22/textpattern-10rc1-boy-that-was-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Textile, Textpattern, and the Meaning of Life</title>
		<link>http://backspaces.net/21/textile-textpattern-and-the-meaning-of-life/</link>
		<comments>http://backspaces.net/21/textile-textpattern-and-the-meaning-of-life/#comments</comments>
		<pubDate>Wed, 29 Sep 2004 18:24:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=21</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<h3>Overview</h3>
<p>So what is all this.  First of all, recall from our earlier presentations, the New Web looks like:</p>
<ol>
<li><span class="caps">XHTML </span>and <span class="caps">CSS</span></li>
<li><span class="caps">PHP </span>and MySql</li>
<li>Site Management</li>
</ol>
<p>Textile and Textpattern address the third area.</p>
<h3>Installation</h3>
<ul>
<li><a href="http://textpattern.com/">Deannload textpattern</a></li>
<li><a href="/images/txp/mysqladmin.gif">Create textpattern MySql DB</a></li>
<li><a href="/images/txp/txpsetup.gif">Browser setup.php</a></li>
<li><a href="/images/txp/txpadmin.gif">Browser admin</a></li>
<li><a href="/index.php">Backspaces Home Page</a></li>
</ul>
<h3>.. lets take a <em>test drive</em>!</h3>
<h3>Links</h3>
<ul>
<li><a href="http://textism.com/tools/textile/">Textile</a></li>
<li><a href="http://forum.textpattern.com/">Textpattern Forum</a></li>
<li><a href="http://kusor.com/en/txptagmanual/">Txp Tags</a></li>
<li><a href="http://forum.textpattern.com/viewtopic.php?id=2193">Plugins</a>
<ul>
<li><a href="http://forum.textpattern.com/viewtopic.php?id=1043">Plugin template</a></li>
<li><a href="http://rise.lewander.com/textpattern/94/txp-global-variables">Plugin variables</a></li>
</ul>
</li>
<li><a href="http://mnorton.chaosnet.org/txp/53/textpattern-101">Txp 101</a></li>
<li><a href="http://www.jdueck.net/article/10/textpattern-semantics">Txp Semantics</a></li>
<li><a href="http://www.splatbang.com/personal/txp_diagram.png">Txp Diagram</a></li>
</ul>
<h3>Code Fragments</h3>
<p>First, here&#8217;s my modified index.php file.  This is the index file for anyone beaming into http://backspaces.net/.  It uses php to redirect folks to the http://complexityworkshop.com/ site and any other sites I co-host.  The last segment is the default php for textpattern itself.</p>
<pre>
// -------------------------------------------------------------
&lt;?php
    $server = $_SERVER['HTTP_HOST'];

    if (eregi(&quot;complexity&quot;, $server)) {
        header(&quot;Location: /cw/&quot;);
    } elseif (eregi(&quot;wireless&quot;, $server)) {
        header(&quot;Location: /sites/acequia/&quot;);
    } else {
        include 'textpattern/config.php';
        include $txpcfg['txpath'].'/publish.php';
        textpattern();
    }
?&gt;
</pre>
<p>Next, this is an example of the implementation of a Textpattern tag, in this case the <br />
<code>&lt;txp:linklist category=&quot;xxx&quot; /&gt;</code> <br />
tag used for displaying links like those in my default sidebars.</p>
<pre>
// -------------------------------------------------------------
    function linklist($atts) // possible atts: form, sort, category, limit, label
    {
        if(is_array($atts)) extract($atts);
        if(!isset($form)) $form = 'plainlinks';
        if(!isset($sort)) $sort = 'linksort';
        $Form = fetch('Form','txp_form','name',$form);
        $wraptag = (empty($wraptag)) ? '' : $wraptag;

        $qparts = array(
            (!empty($category)) ? &quot;category='$category'&quot; : '1',
            &quot;order by&quot;,
            $sort,
            (!empty($limit)) ? &quot;limit $limit&quot; : ''
        );

        $rs = safe_rows(&quot;*&quot;,&quot;txp_link&quot;,join(' ',$qparts));

        if ($rs) {
            $outlist = (!empty($label)) ? $label : '';

            foreach ($rs as $a) {
                extract($a);
                $linkname = str_replace(&quot;&#38; &quot;,&quot;&amp;#38; &quot;, $linkname);
                $link = '&lt;a href=&quot;'.$url.'&quot;&gt;'.$linkname.'&lt;/a&gt;';
                $linkdesctitle = '&lt;a href=&quot;'.$url.
                    '&quot; title=&quot;'.$description.'&quot;&gt;'.$linkname.'&lt;/a&gt;';

                $out = str_replace(&quot;&lt;txp:link /&gt;&quot;, $link, $Form);
                $out = str_replace(&quot;&lt;txp:linkdesctitle /&gt;&quot;, $linkdesctitle, $out);
                $out = str_replace(&quot;&lt;txp:link_description /&gt;&quot;, $description, $out);

                $outlist .= $out;
            }
        return ($wraptag) ? tag($outlist,$wraptag) : $outlist;
        }
        return false;
    }
</pre>
<p>Here is an example of the Textpattern utilities available to plugin developers.</p>
<pre>
// -------------------------------------------------------------
    function safe_query($q='',$debug='',$unbuf='')
    {
        global $DB,$txpcfg;
        $method = (!$unbuf) ? 'mysql_query' : 'mysql_unbuffered_query';
        if (!$q) return false;
        if ($debug) {
            dmp($q);
            dmp(mysql_error());
        }
        $result = $method($q,$DB-&gt;link);

        if(!$result) return false;
        return $result;
    }
// -------------------------------------------------------------
</pre>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/21/textile-textpattern-and-the-meaning-of-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetLogo Models</title>
		<link>http://backspaces.net/10/netlogo-models/</link>
		<comments>http://backspaces.net/10/netlogo-models/#comments</comments>
		<pubDate>Wed, 18 Aug 2004 18:00:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=10</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<p>Our hacks section contains several NetLogo models.  We&#8217;ll expand on the newer ones, explaining what we&#8217;re up to.  </p>
<p>In the mean time, click on the links to the models and you&#8217;ll find the netlogo standard page with the model in java applet form, followed by links to the netlogo site and the source code, and an explaination of the model. </p>
<ul>
<li><a href="/models/beergame.html">BeerGame</a></li>
<li><a href="/models/bounce.html">Bounce</a></li>
<li><a href="/models/buttons.html">Buttons</a></li>
<li><a href="/models/layout.html">Layout</a></li>
<li><a href="/models/peernet.html">PeerNet</a></li>
<li><a href="/models/sugarscape.html">SugarScape</a></li>
<li><a href="/models/ga.html">TSP GA</a></li>
<li><a href="/models/bucks.html">Economy</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/10/netlogo-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Layout Model</title>
		<link>http://backspaces.net/7/spring-layout-model/</link>
		<comments>http://backspaces.net/7/spring-layout-model/#comments</comments>
		<pubDate>Mon, 08 Dec 2003 18:00:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=7</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<p>This is a NetLogo dynamic <a href="/models/layout.html">graph layout model</a> using springs and repulsion forces to create a pleasing layout.</p>
<p>The purpose of the model is to let a graph evolve into a usable layout naturally.  You can grab the nodes and move them to help the system along!</p>
<p>As always, you can read more detailed notes in the model&#8217;s documentation included with the applet, and can read the source code there as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/7/spring-layout-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Misc Java Hacks</title>
		<link>http://backspaces.net/19/misc-java-hacks/</link>
		<comments>http://backspaces.net/19/misc-java-hacks/#comments</comments>
		<pubDate>Thu, 01 Jun 2000 06:00:00 +0000</pubDate>
		<dc:creator>backspaces</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://backspaces.net/wordpress/?p=19</guid>
		<description><![CDATA[

 ]]></description>
			<content:encoded><![CDATA[<p>Juse a couple of misc. Java applets.</p>
<ul>
<li>A very old, but still fun <a href="/sun/daleks/">Daleks game</a>.</li>
<li>A simple <a href="/sun/nodes/">physics applet</a> of weights on springs with gravity.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://backspaces.net/19/misc-java-hacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

