<?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>Code &#038; form &#187; Code</title>
	<atom:link href="http://workshop.evolutionzone.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://workshop.evolutionzone.com</link>
	<description>Computational aesthetics and programming for artists and designers.</description>
	<lastBuildDate>Sun, 04 Jul 2010 20:09:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code: Data saving class</title>
		<link>http://workshop.evolutionzone.com/2010/06/20/code-data-saving-class/</link>
		<comments>http://workshop.evolutionzone.com/2010/06/20/code-data-saving-class/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 15:19:12 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=383</guid>
		<description><![CDATA[I wrote a useful piece of code during the recent Shakerag workshop that makes it easy to save and load parameter data from text files. To celebrate the recent launch of the new Processing Wiki I have added it there, but for completeness I will also post it here.
Code: Data.pde
Use Data.beginSave() to initialize data string [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a useful piece of code during the recent <a href="http://workshop.evolutionzone.com/2010/04/20/shakerag-workshops-june-2010/">Shakerag workshop</a> that makes it easy to save and load parameter data from text files. To celebrate the recent launch of the new <a href="http://wiki.processing.org/w/Saving_data_to_text_files">Processing Wiki</a> I have added it there, but for completeness I will also post it here.</p>
<div class="mediumtitle">Code: Data.pde</div>
<p>Use Data.beginSave() to initialize data string collection, then add data with Data.add(). To write to file, use endSave(filename). I&#8217;ve included code for auto-incrementing filenames, it&#8217;s used in the example code.</p>
<p>To load data, call Data.load(filename), then use readInt(), readFloat(), readString() etc. to get values from the strings read from the text file. Used properly this should give you most of the flexibility you need for simple data saving.</p>
<p><span id="more-383"></span>
<pre name="code" class="java">// saveData.pde
// Marius Watz - http://workshop.evolutionzone.com

// Example showing how to use the Data utility
// class to save and load data from text files. 

float a=2.5,b=3.144;
int x=10,y=20;
boolean bool=true;
String s="This is a string.";

Data data;

void setup() {
  size(400,400);

  data=new Data();

  // SAVING
  data.beginSave();
  data.add(s);
  data.add(a);
  data.add(b);
  data.add(x);
  data.add(y);
  data.add(bool);
  data.endSave(
    data.getIncrementalFilename(
      sketchPath("save"+
        java.io.File.separator+
        "data ####.txt")));

  // LOADING
  data.load(sketchPath("save"+
    java.io.File.separator+
    "data 0000.txt"));

  s=data.readString();
  a=data.readFloat();
  b=data.readFloat();
  x=data.readInt();
  y=data.readInt();
  bool=data.readBoolean();
}

///////////////////////////
// DATA CLASS

class Data {
  ArrayList datalist;
  String filename,data[];
  int datalineId;

  // begin data saving
  void beginSave() {
    datalist=new ArrayList();
  }

  void add(String s) {
    datalist.add(s);
  }

  void add(float val) {
    datalist.add(""+val);
  }

  void add(int val) {
    datalist.add(""+val);
  }

  void add(boolean val) {
    datalist.add(""+val);
  }

  void endSave(String _filename) {
    filename=_filename;

    data=new String[datalist.size()];
    data=(String [])datalist.toArray(data);

    saveStrings(filename, data);
    println("Saved data to '"+filename+
      "', "+data.length+" lines.");
  }

  void load(String _filename) {
    filename=_filename;

    datalineId=0;
    data=loadStrings(filename);
    println("Loaded data from '"+filename+
      "', "+data.length+" lines.");
  }

  float readFloat() {
    return float(data[datalineId++]);
  }

  int readInt() {
    return int(data[datalineId++]);
  }

  boolean readBoolean() {
    return boolean(data[datalineId++]);
  }

  String readString() {
    return data[datalineId++];
  }

  // Utility function to auto-increment filenames
  // based on filename templates like "name-###.txt" 

  public String getIncrementalFilename(String templ) {
    String s="",prefix,suffix,padstr,numstr;
    int index=0,first,last,count;
    File f;
    boolean ok;

    first=templ.indexOf('#');
    last=templ.lastIndexOf('#');
    count=last-first+1;

    if( (first!=-1)&#038;&#038; (last-first>0)) {
      prefix=templ.substring(0, first);
      suffix=templ.substring(last+1);

      // Comment out if you want to use absolute paths
      // or if you're not using this inside PApplet
      if(sketchPath!=null) prefix=savePath(prefix);

      index=0;
      ok=false;

      do {
        padstr="";
        numstr=""+index;
        for(int i=0; i< count-numstr.length(); i++) padstr+="0";
        s=prefix+padstr+numstr+suffix;

        f=new File(s);
        ok=!f.exists();
        index++;

        // Provide a panic button. If index > 10000 chances are it's an
        // invalid filename.
        if(index>10000) ok=true;

      }
      while(!ok);

      // Panic button - comment out if you know what you're doing
      if(index> 10000) {
        println("getIncrementalFilename thinks there is a problem - "+
          "Is there  more than 10000 files already in the sequence "+
          " or is the filename invalid?");
        println("Returning "+prefix+"ERR"+suffix);
        return prefix+"ERR"+suffix;
      }
    }

    return s;
  }

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2010/06/20/code-data-saving-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data, data, data</title>
		<link>http://workshop.evolutionzone.com/2010/04/11/data-data-data/</link>
		<comments>http://workshop.evolutionzone.com/2010/04/11/data-data-data/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 19:41:56 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Open source]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[data sculpture]]></category>
		<category><![CDATA[david mccandless]]></category>
		<category><![CDATA[geo]]></category>
		<category><![CDATA[geonames]]></category>
		<category><![CDATA[infoviz]]></category>
		<category><![CDATA[jonathan harris]]></category>
		<category><![CDATA[manuel lima]]></category>
		<category><![CDATA[martin wattenberg]]></category>
		<category><![CDATA[opendata]]></category>
		<category><![CDATA[visualcomplexity]]></category>
		<category><![CDATA[visualization]]></category>
		<category><![CDATA[weather]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=347</guid>
		<description><![CDATA[
KBGAnimD01EB 0008, still from new sound visualization

Ever since doing Stockspace project it seems I am getting asked to do data-related work. This despite the fact that my personal interests diverge from such masters of insightful infographics as Martin Wattenberg, David McCandless or Jonathan Harris. 
Suffice to say that I am more concerned with exploring data [...]]]></description>
			<content:encoded><![CDATA[<div class="flickrImg"><a href="http://www.flickr.com/photos/watz/4480227292/" title="KBGAnimD01EB 0008 still by watz, on Flickr"><img src="http://farm3.static.flickr.com/2758/4480227292_cb94c63a68.jpg" width="500" height="281" alt="KBGAnimD01EB 0008 still" /></a></p>
<p><a href="http://www.flickr.com/photos/watz/4480227292/" title="KBGAnimD01EB 0008 still by watz, on Flickr">KBGAnimD01EB 0008, still from new sound visualization</a></p>
</div>
<p>Ever since doing <a href="http://www.flickr.com/photos/watz/sets/72157616153554806/">Stockspace</a> project it seems I am getting asked to do data-related work. This despite the fact that my personal interests diverge from such masters of insightful infographics as <a href="http://www.bewitched.com/">Martin Wattenberg</a>, <a href="http://www.davidmccandless.com/">David McCandless</a> or <a href="http://www.number27.org/">Jonathan Harris</a>. </p>
<p>Suffice to say that I am more concerned with exploring data structures as spaces than I am with providing new understandings of the information contained within them. Manuel Lima&#8217;s <a href="http://www.visualcomplexity.com/vc/blog/?p=644">Information Visualization Manifesto</a> calls for a seriousness on the topic of data treatments, while my projects remain comfortably frivolous.</p>
<p>Recently I&#8217;ve been working on a project that has required researching data sources and adapting them to illustrate a bigger idea, which has led to much Googling in the absence of good data from the client. Sometimes you find the right thing immediately, but sometimes data is hard to find in a format that is freely available and easily parsable. Since I have found some good sources I thought I&#8217;d share them here&#8230;</p>
<div class="mediumtitle">Miscellaneous free data</div>
<ul>
<li><a href="http://rredc.nrel.gov/solar/calculators/PVWATTS/version1/">PVWATSS calculator</a> from <a href="http://www.nrel.gov/rredc">Renewable Resource Data Center (RReDC)</a> provides theoretical calculations of yields (hour-by-hour, 365 days/yr) from photovoltaic solar panels for most international locations.</li>
<li><a href="http://www.halfgaar.net/localized-world-airport-codes">World airport codes with geo name data</a>, helpfully spidered by Wiebe Cazemier so you don&#8217;t have to.</li>
<li>Unattributed <a href="http://geolite.maxmind.com/download/">FTP depository of geo-related CSV files</a>, including postal and ZIP codes, world city info etc.</li>
<li><a href="http://www.programmableweb.com/api/weather-underground">Historical weather data from Weather Underground</a>, providing year-by-year hourly information for most cities in the world. (See also this list of <a href="http://blog.programmableweb.com/2009/04/15/5-weather-apis-from-weatherbug-to-weather-channel/">weather APIs</a>.)</li>
<li><a href="http://finance.yahoo.com/">Yahoo Finance</a> offers downloads of historical stock price data (CSV) for just about any stock symbol out there. Sadly I have yet to find an open intraday stock data source, due to the proprietary nature of that kind of information.</li>
<li><a href="http://www.guardian.co.uk/news/datablog">The Guardian&#8217;s Datablog</a> is a recent venture, and I have yet to use any of the data sets they provide. But I like their approach, which is clearly aimed at democratizing data with a view to public agenda.</li>
</ul>
<p>I would be interested in hearing tips about any great data sets out there, particularly interesting time series data. </p>
<p><a href="http://knapek.org/">Miska Knapek</a> recently sent me a link to a source of weather sensor data from Helsinki, including measurements of wind direction at the top of Helsinki&#8217;s Olympic Tower in 5-minute intervals. He has already made <a href="http://vimeo.com/9544834">some wind visualization videos</a> and some <a href="http://www.flickr.com/photos/miska_too/collections/72157619226259190/">fabricated wind data sculptures</a> based on this data.</p>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2010/04/11/data-data-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jer Thorp&#8217;s 7 Days of Code</title>
		<link>http://workshop.evolutionzone.com/2009/10/14/jer-thorps-7-days-of-code/</link>
		<comments>http://workshop.evolutionzone.com/2009/10/14/jer-thorps-7-days-of-code/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 21:27:22 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Jer Thorp]]></category>
		<category><![CDATA[L-system]]></category>
		<category><![CDATA[NY Times]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=298</guid>
		<description><![CDATA[
Jer Thorp: NY Times: 365/360
Processing visualization head Jer Thorp is putting his money where his mouth and publishing 7 pieces of code in 7 days, free to download and experiment with. Judging from the three that he&#8217;s released so far they&#8217;re not your standard 20-minute sketches either:

GoodMorning! is a Twitter vizualization, showing users around the [...]]]></description>
			<content:encoded><![CDATA[<div class="flickrImg"><a href="http://blog.blprnt.com/blog/blprnt/7-days-of-source-day-2-nytimes-36536"><img src="http://workshop.evolutionzone.com/wp-content/uploads/2009/10/zyqpe7lw.jpg" border="0" alt="Jer Thorp: NY Times visualization" title="Jer Thorp: NY Times visualization" width="500" height="220" class="size-full wp-image-301" /></a></p>
<p>Jer Thorp: <a href="http://blog.blprnt.com/blog/blprnt/7-days-of-source-day-2-nytimes-36536">NY Times: 365/360</a></div>
<p>Processing visualization head <a href="http://blog.blprnt.com/">Jer Thorp</a> is putting his money where his mouth and publishing <a href="http://blog.blprnt.com/blog/blprnt/a-thanksgiving-gift-7-days-of-source-code">7 pieces of code in 7 days</a>, free to download and experiment with. Judging from the three that he&#8217;s released so far they&#8217;re not your standard 20-minute sketches either:</p>
<ol>
<li><a href="http://blog.blprnt.com/blog/blprnt/7-days-of-source-day-1-goodmorning"><strong>GoodMorning!</strong></a> is a Twitter vizualization, showing users around the world popping up on a globe as they utter the magic words &#8220;good morning&#8221;. With a little geocoding and spherical mapping thrown in, this is a sweet sketch</li>
<li><a href="http://blog.blprnt.com/blog/blprnt/7-days-of-source-day-2-nytimes-36536"><strong>NY Times: 365/360</strong></a> uses the New York Times open data API to retrieve news stories for an entire year and draw connections between them. The results combine complexity with elegance for that true infoporn look.</li>
<li><a href="http://blog.blprnt.com/blog/blprnt/7-days-of-source-day-3-tree-growth"><strong>tree.growth</strong></a> revisits that old classic, the L-system tree. Thorp uses colors and abstract &#8220;leaves&#8221; to great effect.</li>
</ol>
<p>With such a strong start, one certainly looks forward to seeing the next four sketches to come. It&#8217;s not so common to find sketches of this complexity freely available, so they&#8217;re a great study for users who are on the threshold of making more complex applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2009/10/14/jer-thorps-7-days-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Minim 2.0.2 released</title>
		<link>http://workshop.evolutionzone.com/2009/10/05/minim-2-0-2-released/</link>
		<comments>http://workshop.evolutionzone.com/2009/10/05/minim-2-0-2-released/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 02:48:32 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[fft]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[processing.org]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=290</guid>
		<description><![CDATA[Good news for Processing heads who use sound: Damien de Fede has released a new major version of his excellent Minim library. Along with bug fixes, new features include:

added functions to FFT for doing forward transforms with an offset: forward(float[] samples, offset) and forward(AudioBuffer samples, offset)
added a freqToIndex(float freq) method to FFT for finding out [...]]]></description>
			<content:encoded><![CDATA[<p>Good news for Processing heads who use sound: Damien de Fede has <a href="http://code.compartmental.net/2009/10/04/minim-2-0-2-released/">released a new major version</a> of his excellent Minim library. Along with bug fixes, new features include:</p>
<ul>
<li>added functions to FFT for doing forward transforms with an offset: forward(float[] samples, offset) and forward(AudioBuffer samples, offset)</li>
<li>added a freqToIndex(float freq) method to FFT for finding out the index of the spectrum band that contains the passed in frequency.</li>
<li>added a stop() method to AudioSample, so that playing samples can be immediately silenced.</li>
<li>added setPanNoGlide(float pan) to Controller, which will snap the panning setting of a sound to the provided value.</li>
<li>added setInputMixer(Mixer) and setOutputMixer(Mixer), which allow you to specify which Java Mixer object should be used when obtaining inputs (AudioInput) and outputs (AudioOuput, AudioPlayer, AudioSnippet, AudioSample).</li>
</ul>
<p>Download from the <a href="http://code.compartmental.net/2009/10/04/minim-2-0-2-released/">Minim project page</a>. Read more about the development process on the <a href="http://code.compartmental.net/category/minim/">Compartmental blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2009/10/05/minim-2-0-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hack: Non-standard windows in Processing</title>
		<link>http://workshop.evolutionzone.com/2009/09/29/hack-non-standard-windows-in-processing/</link>
		<comments>http://workshop.evolutionzone.com/2009/09/29/hack-non-standard-windows-in-processing/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 00:34:33 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[awt]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=247</guid>
		<description><![CDATA[Processing does not provide any direct mechanism for manipulating the look of the sketch Window, but Java natively supports tricks like turning off the window chrome, explicitly setting window position and making a window &#8220;float&#8221; over all other UI elements. All of this can be accessed via PApplet&#8217;s internal &#8220;frame&#8221; field, which holds an instance [...]]]></description>
			<content:encoded><![CDATA[<p>Processing does not provide any direct mechanism for manipulating the look of the sketch Window, but Java natively supports tricks like turning off the window chrome, explicitly setting window position and making a window &#8220;float&#8221; over all other UI elements. All of this can be accessed via PApplet&#8217;s internal &#8220;frame&#8221; field, which holds an instance of a Frame object representing the window your sketch is running in. But even so, Java won&#8217;t let you have free reign without a little trickery.</p>
<p>The following hack demonstrates how to make a window that has no OS chrome, always stays on top of the UI and has an explicitly set screen position. You can even use the cursor keys to move the window around the screen.</p>
<p>Personally, what I like most about this hack is that it gets around Processing&#8217;s (or possibly Java&#8217;s) assumptions about a minimum window size of ~120&#215;120. If you specify a size that&#8217;s less than 120 on one side, Processing will be pad that side with grey pixels to reach the minimum. But with this hack you can have tiny windows that you can micro-manage to your heart&#8217;s delight. I use it to make debug dispays, small control panels and other useful things.</p>
<p><strong>Update:</strong> <a href="http://twitter.com/CedricKiefer/status/4466913316">@CedricKiefer</a> pointed out another Processing example that allows for <a href="http://www.visualinformation.org/2009/09/25/transparent-application-window-in-processing/">transparent and even irregularly shaped windows</a>. It&#8217;s Windows-only apparently, I bet this kind of thing is a major violation of Apple GUI laws anyhow.</p>
<p><strong>Update 2:</strong> <a href="http://twitter.com/ideoforms/status/4467523812">@ideoforms</a> took my post literally and made a <a href="http://www.erase.net/weblog/2009-09/hackpact-20090929-multiple-bouncing-windows-in-processing">sketch with multiple bouncing windows</a>. Nice.</p>
<div class="mediumtitle">Code: FloatingWindow.pde</div>
<p><span id="more-247"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// FloatingWindow.pde</span>
<span style="color: #666666; font-style: italic;">// Marius Watz - http://workshop.evolutionzone.com</span>
<span style="color: #666666; font-style: italic;">// </span>
<span style="color: #666666; font-style: italic;">// Provides a method for creating frame-less windows with smaller </span>
<span style="color: #666666; font-style: italic;">// than typical sizes. Also demonstrates how to set the precise</span>
<span style="color: #666666; font-style: italic;">// location of the window on screen, as well as make it float over</span>
<span style="color: #666666; font-style: italic;">// all other windows.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Can be useful if you'd like to make a persistent &quot;debug&quot; app of</span>
<span style="color: #666666; font-style: italic;">// some sort, or just because it's neat when things don't look like</span>
<span style="color: #666666; font-style: italic;">// your everyday operating system.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Works both with P2D and OPENGL.Uses a trick from this Processing hack:</span>
<span style="color: #666666; font-style: italic;">// http://processing.org/hacks/hacks:undecoratedframe</span>
&nbsp;
PFont fnt<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> W,H,PX,PY<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// W x H == desired size of frame. </span>
  <span style="color: #666666; font-style: italic;">// Normally, Processing will not create a frame smaller than ~120x120,</span>
  <span style="color: #666666; font-style: italic;">// but will pad the window with blank pixels.</span>
  W<span style="color: #339933;">=</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
  H<span style="color: #339933;">=</span><span style="color: #cc66cc;">40</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// initial position of frame</span>
  PX<span style="color: #339933;">=</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
  PY<span style="color: #339933;">=</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
  size<span style="color: #009900;">&#40;</span>W,H<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fnt<span style="color: #339933;">=</span>createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Arial&quot;</span>,<span style="color: #cc66cc;">12</span>,<span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// overriding PApplet.init() to add a hack of our own</span>
<span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// trick to make it possible to change the frame properties</span>
  frame.<span style="color: #006633;">removeNotify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #666666; font-style: italic;">// comment this out to turn OS chrome back on</span>
  frame.<span style="color: #006633;">setUndecorated</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #666666; font-style: italic;">// comment this out to not have the window &quot;float&quot;</span>
  frame.<span style="color: #006633;">setAlwaysOnTop</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  frame.<span style="color: #006633;">setResizable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  frame.<span style="color: #006633;">addNotify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  <span style="color: #666666; font-style: italic;">// making sure to call PApplet.init() so that things </span>
  <span style="color: #666666; font-style: italic;">// get  properly set up.</span>
  <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// resize and set initial location a few frames after sketch start. </span>
  <span style="color: #666666; font-style: italic;">// our window will now be tiny and located at position PX,PY.</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>frameCount<span style="color: #339933;">==</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    frame.<span style="color: #006633;">resize</span><span style="color: #009900;">&#40;</span>W,H<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    frame.<span style="color: #006633;">setLocation</span><span style="color: #009900;">&#40;</span>PX,PY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// draw window outline</span>
  noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>, width,height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>, width<span style="color: #339933;">-</span><span style="color: #cc66cc;">6</span>,height<span style="color: #339933;">-</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  textFont<span style="color: #009900;">&#40;</span>fnt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span>frameCount<span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #339933;">+</span>
    frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">+</span>
    frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">y</span>,<span style="color: #cc66cc;">16</span>,<span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// the cursor keys may be used to move the window around</span>
<span style="color: #000066; font-weight: bold;">void</span> keyPressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">==</span>CODED<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>keyCode<span style="color: #339933;">==</span>LEFT<span style="color: #009900;">&#41;</span> frame.<span style="color: #006633;">setLocation</span><span style="color: #009900;">&#40;</span>
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span>,
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>keyCode<span style="color: #339933;">==</span>RIGHT<span style="color: #009900;">&#41;</span> frame.<span style="color: #006633;">setLocation</span><span style="color: #009900;">&#40;</span>
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span>,
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>keyCode<span style="color: #339933;">==</span>UP<span style="color: #009900;">&#41;</span> frame.<span style="color: #006633;">setLocation</span><span style="color: #009900;">&#40;</span>
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">x</span>,
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">y</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>keyCode<span style="color: #339933;">==</span>DOWN<span style="color: #009900;">&#41;</span> frame.<span style="color: #006633;">setLocation</span><span style="color: #009900;">&#40;</span>
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">x</span>,
      frame.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">y</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>  
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2009/09/29/hack-non-standard-windows-in-processing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TileSaver broken &#8211; temporary hack</title>
		<link>http://workshop.evolutionzone.com/2009/08/18/tilesaver-broken-temporary-hack/</link>
		<comments>http://workshop.evolutionzone.com/2009/08/18/tilesaver-broken-temporary-hack/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 05:22:26 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[high-resolution]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[tilesaver]]></category>
		<category><![CDATA[unlekkerlib]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=244</guid>
		<description><![CDATA[As documented in this thread on the Processing forums the TileSaver class seems to be broken for current versions of Processing. Sadly I&#8217;m not sure what the problem is and I don&#8217;t have time to fix it right now.
However, I tried the original TileSaver code posted back in 2006 and miraculously that still works. This [...]]]></description>
			<content:encoded><![CDATA[<p>As documented in <a href="http://processing.org/discourse/yabb2/YaBB.pl?num=1248245155/0#10">this thread on the Processing forums</a> the TileSaver class seems to be broken for current versions of Processing. Sadly I&#8217;m not sure what the problem is and I don&#8217;t have time to fix it right now.</p>
<p>However, I tried the original TileSaver code posted back in 2006 and miraculously that still works. This would imply a larger issue with the unlekkerLib library and Processing 1.0, which I&#8217;ll have to address when I have the time.</p>
<p>For now, here is a link to a working Processing sketch using the old TileSaver code: <a href="http://workshop.evolutionzone.com/files/TileSaverTest.zip">TileSaverTest.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2009/08/18/tilesaver-broken-temporary-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unlekkerLib0003c: Now compatible with Processing 1.0</title>
		<link>http://workshop.evolutionzone.com/2009/04/16/unlekkerlib0003c-now-compatible-with-processing-10/</link>
		<comments>http://workshop.evolutionzone.com/2009/04/16/unlekkerlib0003c-now-compatible-with-processing-10/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 06:19:56 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[codeandform]]></category>
		<category><![CDATA[google code]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[tilesaver]]></category>
		<category><![CDATA[unlekkerlib]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=234</guid>
		<description><![CDATA[After several requests I&#8217;ve taken the time to make unlekkerLib  compatible with Processing 1.0. Apologies to anyone who&#8217;s been inconvenienced by the lack of a 1.0 version.
In particular, STL export should work again. However I haven&#8217;t had the chance to test the code very much, so please let me know if you find any [...]]]></description>
			<content:encoded><![CDATA[<p>After several requests I&#8217;ve taken the time to make <a href="http://workshop.evolutionzone.com/unlekkerlib/">unlekkerLib </a> compatible with Processing 1.0. Apologies to anyone who&#8217;s been inconvenienced by the lack of a 1.0 version.</p>
<p>In particular, STL export should work again. However I haven&#8217;t had the chance to test the code very much, so please let me know if you find any bugs.</p>
<div class="mediumtitle">Download</div>
<ul>
<li><a href="http://code.google.com/p/codeandform/downloads/detail?name=unlekkerLib0003c.zip&#038;can=2&#038;q=" title="unlekkerLib0003c">unlekkerLib0003c</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2009/04/16/unlekkerlib0003c-now-compatible-with-processing-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple JDIC browsers in Processing sketch</title>
		<link>http://workshop.evolutionzone.com/2008/09/06/multiple-jdic-browsers-in-processing-sketch/</link>
		<comments>http://workshop.evolutionzone.com/2008/09/06/multiple-jdic-browsers-in-processing-sketch/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 19:52:25 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Open source]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[awt]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[embedding]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdic]]></category>
		<category><![CDATA[pde]]></category>
		<category><![CDATA[processing.org]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=210</guid>
		<description><![CDATA[
Multiple JDIC browsers integrated into Processing sketch
A while back I posted a simple hack to open a web browser from Processing by using JDesktop Integration Components (JDIC). A recent discussion on the Processing forums asked about how to use it to open multiple browsers inside the actual Processing sketch window.
My original hack used an instance [...]]]></description>
			<content:encoded><![CDATA[<div class="flickrImg"><img src="http://workshop.evolutionzone.com/wp-content/uploads/2008/09/20080906_jdic_multiple.gif" alt="Multiple JDIC browsers in Processing sketch" title="Multiple JDIC browsers" width="500" height="388" class="alignnone size-full wp-image-209" /></p>
<p>Multiple JDIC browsers integrated into Processing sketch</a></div>
<p>A while back I posted a <a href="http://workshop.evolutionzone.com/2007/08/30/jdic-embedding-a-web-browser-in-java/">simple hack to open a web browser</a> from Processing by using JDesktop Integration Components (JDIC). A recent <a href="http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1220555122">discussion on the Processing forums</a> asked about how to use it to open multiple browsers inside the actual Processing sketch window.</p>
<p>My original hack used an instance of org.jdesktop.jdic.browser.WebBrowser integrated into a java.awt.Panel instance and laid out in a java.awt.Frame. That meant that the browser would open in an external window. The discussion on the Processing forum asked specifically about opening multiple browsers in the main sketch window, so I made the following quick hack. </p>
<div class="mediumtitle">Code &#8211; JDIC_multiple.pde</div>
<p><span id="more-210"></span>I&#8217;m posting the actual code below, but to run the example you should download the following ZIP file: <a href="http://workshop.evolutionzone.com/files/JDIC_multiple.zip">JDIC_multiple.zip</a>. It includes the JDIC binaries required to run it on Windows.</p>
<pre name="code" class="java">// JDIC_multiple.pde
// Marius Watz - http://workshop.evolutionzone.com

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.net.URL;
import java.net.MalformedURLException;
import org.jdesktop.jdic.browser.*;

aBrowser browser[];
long last;

void setup() {
  size(800,600);
  frame.setLayout(new GridLayout(2,2));

  browser=new aBrowser[4];
  for(int i=0; i<4; i++) {
    browser[i]=new aBrowser();
    browser[i].initPanel(400,300);

    if(i==0) browser[i].setURL("http://www.google.com/");
    if(i==1) browser[i].setURL("http://processing.org/");
    if(i==2) browser[i].setURL("http://ffffound.com/");
    if(i==3) browser[i].setURL("http://sojamo.tumblr.com/"); 

    frame.add(browser[i].panel);
  }
}

void draw() {

}

public class aBrowser {
  Panel panel;
  WebBrowser webBrowser;

  public aBrowser() {
    // Set engine to IE
    BrowserEngineManager mng=BrowserEngineManager.instance();
    mng.setActiveEngine(BrowserEngineManager.IE);
    webBrowser = new WebBrowser();
  }

  public void initPanel(int w,int h) {
    panel = new Panel();
    panel.setLayout(new BorderLayout());
    panel.setSize(w,h);
    webBrowser.setSize(w, h);
    panel.add(webBrowser, BorderLayout.CENTER);
  }

  public void setContent(String htmlContent) {
    webBrowser.setContent(htmlContent);
  }

  public void setURL(String url) {
    try {
      webBrowser.setURL(new URL(url));
      webBrowser.setDebug(false);
    }
    catch (MalformedURLException e) {
      System.out.println(e.getMessage());
      return;
    }
  }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2008/09/06/multiple-jdic-browsers-in-processing-sketch/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>unlekkerLib-0003: Fixed missing classes</title>
		<link>http://workshop.evolutionzone.com/2008/07/12/unlekkerlib-0003-fixed-missing-classes/</link>
		<comments>http://workshop.evolutionzone.com/2008/07/12/unlekkerlib-0003-fixed-missing-classes/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 18:51:37 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[codeandform]]></category>
		<category><![CDATA[google code]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[tilesaver]]></category>
		<category><![CDATA[unlekkerlib]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=205</guid>
		<description><![CDATA[I&#8217;ve uploaded a new version of my unlekkerLib library. For some inexplicable reason version 0002 was missing some classes that were needed for certain examples to function. As a result the TileSaver class was broken, which was a serious omission. 
You can download unlekkerLib-0003 from the <a href="http://code.google.com/p/codeandform/downloads/list" title="Code &#038; Form Google Code repository">Code &#038; Form Google Code repository</a>. I&#8217;ve added the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve uploaded a new version of my <a href="http://workshop.evolutionzone.com/unlekkerlib/">unlekkerLib library</a>. For some inexplicable reason version 0002 was missing some classes that were needed for certain examples to function. As a result the TileSaver class was broken, which was a serious omission. </p>
<p>You can download unlekkerLib-0003 from the <a href="http://code.google.com/p/codeandform/downloads/list" title="Code &#038; Form Google Code repository">Code &#038; Form Google Code repository</a>. I&#8217;ve added the missing classes, but otherwise the library is the same. If you still experience problems please report them here.</p>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2008/07/12/unlekkerlib-0003-fixed-missing-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code: Mesh library + demo</title>
		<link>http://workshop.evolutionzone.com/2008/06/01/mesh-library-demo/</link>
		<comments>http://workshop.evolutionzone.com/2008/06/01/mesh-library-demo/#comments</comments>
		<pubDate>Sat, 31 May 2008 22:23:35 +0000</pubDate>
		<dc:creator>marius watz</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Processing / Java]]></category>
		<category><![CDATA[convex hull]]></category>
		<category><![CDATA[delaunay]]></category>
		<category><![CDATA[Lee Byron]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[processing.org]]></category>
		<category><![CDATA[voronoi]]></category>

		<guid isPermaLink="false">http://workshop.evolutionzone.com/?p=203</guid>
		<description><![CDATA[
<a href="http://code.google.com/p/codeandform/downloads/detail?name=MeshLibDemo.zip&#038;can=2&#038;q=" title="MeshLibDemo.pde">MeshLibDemo.pde</a> &#8211; Demo of Lee Byron&#8217;s Mesh library
<a href="http://leebyron.com/" title="Lee Byron">Lee Byron</a> has written a neat little Processing library called <a href="http://leebyron.com/else/mesh/" title="Mesh">Mesh</a> which allows for easy calculation and display of Voronoi, Delaunay and Convex Hull diagrams. 
Given a set of points, these diagrams calculate the minimal regions around the points (Voronoi), an optimal triangulation of the points (Delaunay) or [...]]]></description>
			<content:encoded><![CDATA[<div class="flickrImg"><img src="http://workshop.evolutionzone.com/wp-content/uploads/2008/06/20080531_meshlibdemo.gif" alt="Demo of Lee Byron\&#039;s Mesh library" title="20080531_meshlibdemo" width="500" height="249" class="alignnone size-full wp-image-204" /></p>
<p><a href="http://code.google.com/p/codeandform/downloads/detail?name=MeshLibDemo.zip&#038;can=2&#038;q=" title="MeshLibDemo.pde">MeshLibDemo.pde</a> &#8211; Demo of Lee Byron&#8217;s Mesh library</p></div>
<p><a href="http://leebyron.com/" title="Lee Byron">Lee Byron</a> has written a neat little Processing library called <a href="http://leebyron.com/else/mesh/" title="Mesh">Mesh</a> which allows for easy calculation and display of Voronoi, Delaunay and Convex Hull diagrams. </p>
<p>Given a set of points, these diagrams calculate the minimal regions around the points (Voronoi), an optimal triangulation of the points (Delaunay) or the polygon shape that contains all the points (Convex Hull). So far the library only supports the 2D versions of the diagrams, but it is in part based on the <a href="http://www.cs.ubc.ca/~lloyd/java/quickhull3d.html" title="QuickHull3D java library">QuickHull3D java library</a> which also handles 3D hulls.</p>
<p>Byron didn&#8217;t include any code examples in the current release, so I hacked up a quick demo.</p>
<div class="mediumtitle">Code: MeshLibDemo.pde</div>
<p>To run this example, download <a href="http://code.google.com/p/codeandform/downloads/detail?name=MeshLibDemo.zip&#038;can=2&#038;q=" title="MeshLibDemo.zip">MeshLibDemo.zip</a> and unzip it inside your Processing sketches folder. The Mesh library is included in a &#8220;libraries&#8221; subfolder, but you&#8217;ll have to restart Processing for the library to be recognized.</p>
<p>I&#8217;m posting the full code below for easy reference.</p>
<p><span id="more-203"></span>
<pre name="code" class="java">// MeshLibDemo.pde - Demo of Lee Byron's Mesh library for
// calculating and drawing Voronoi, Delaunay and Convex Hull
// diagrams. 

// Uses a set of random points to calculate all
// three diagrams, with one point responding to the mouse
// position. Press space to reset points, press '1', '2' and
// '3' to toggle display of the different diagrams.
//
// The library is included in this sketch, see the "libraries"
// subfolder See http://leebyron.com/else/mesh/ for more
// information about the library.
//
// Marius Watz - http://workshop.evolutionzone.com/

import megamu.mesh.*;

Voronoi myVoronoi;
Delaunay myDelaunay;
Hull myHull;

float[][] points;
float[][] myEdges;
MPolygon myRegions[],myHullRegion;
int col[];

float startX,startY,endX,endY;
float[][] regionCoordinates;

boolean showVoronoi=true;
boolean showDelaunay=false;
boolean showHull=false;

void setup() {
  size(500,250);

  // initialize points and calculate diagrams
  initMesh();
  smooth();
}

void draw() {
  background(200);
  if(myRegions==null) return;

  // draw Voronoi
  if(showVoronoi) {
    strokeWeight(1);
    stroke(0);
    for(int i=0; i< myRegions.length; i++) {
      fill(col[i]); // use random color for each region
      regionCoordinates = myRegions[i].getCoords();
      myRegions[i].draw(this); // draw this shape
    }
  }

  // draw Voronoi as lines
  if(showDelaunay) {
    strokeWeight(2);
    stroke(255,0,0);
    for(int i=0; i< myEdges.length; i++) {
      startX = myEdges[i][0];
      startY = myEdges[i][1];
      endX = myEdges[i][2];
      endY = myEdges[i][3];
      line(startX, startY, endX, endY);
    }
  }

  // draw Hull in semi-transparent yellow
  if(showHull) {
    strokeWeight(1);
    stroke(0);
    fill(255,255,0, 150);
    myHullRegion.draw(this);
  }
}

void initMesh() {
  // is points array is null then initialize it
  if(points==null) initPoints();

  // save the current number of regions, so that
  // we can check if it's the same after the Voronoi
  // has been recalculated.
  int oldlength=0;
  if(myRegions!=null) oldlength=myRegions.length;

  myVoronoi = new Voronoi( points );
  myHull = new Hull( points );
  myDelaunay = new Delaunay( points );

  myRegions = myVoronoi.getRegions();
  myHullRegion = myHull.getRegion();
  myEdges = myDelaunay.getEdges();

  // if the number of regions is different than
  // before then recalculate the random colors
  if(oldlength!=myRegions.length) {
    col=new int[myRegions.length];
    for(int i=0; i< myRegions.length; i++) {
      float prob=random(100);
      if(prob>60) col[i]=color(random(30,100));
      else col[i]=color(random(200,255));
    }
    col[0]=color(255,0,0);
  }
}

void initPoints() {
    points = new float[(int)random(5,30)][2];

  for(int i=0; i< points.length; i++) {
    points[i][0] = random(width); // first point, x
    points[i][1] = random(height); // first point, y
  }

}

void keyPressed() {
  // reset points and mesh when spacebar is pressed
  if(key==' ') {
    initPoints();
    initMesh();
  }

  // use keys '1'-'3' to toggle display
  if(key=='1') showVoronoi=!showVoronoi;
  if(key=='2') showDelaunay=!showDelaunay;
  if(key=='3') showHull=!showHull;
}

void mouseMoved() {
  // if myRegions is null then mesh is not ready
  if(myRegions==null) return;

  // set first point to mouse position and recalculate
  points[0][0]=mouseX;
  points[0][1]=mouseY;
  initMesh();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://workshop.evolutionzone.com/2008/06/01/mesh-library-demo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
