<?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>Ex Nihilo</title>
	<atom:link href="http://exnihilo.mezzoblue.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://exnihilo.mezzoblue.com</link>
	<description>A Processing Sketch Blog</description>
	<lastBuildDate>Sun, 22 Nov 2009 07:40:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GPS to Mercator Projection</title>
		<link>http://exnihilo.mezzoblue.com/2009/11/projection/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/11/projection/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 00:40:21 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Maps]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=266</guid>
		<description><![CDATA[A geography issue I&#8217;ve been struggling with over the past little while is correcting my assumptions about how latitude / longitude coordinates work. When I originally built Elevation I decided to take a shortcut and ignore Earth curvature, treating my GPS points as a Cartesian grid. 
And it worked, sort of. It gave me land [...]]]></description>
			<content:encoded><![CDATA[<p>A geography issue I&#8217;ve been struggling with over the past little while is correcting my assumptions about how latitude / longitude coordinates work. When I originally built <a href="/elevation/">Elevation</a> I decided to take a shortcut and ignore Earth curvature, treating my GPS points as a Cartesian grid. </p>
<p>And it worked, sort of. It gave me land forms that come close to representing the actual terrain. In hindsight it&#8217;s pretty obvious how distorted they were, but for the first few iterations of the program they were good enough.</p>
<p>I&#8217;ve now started looking into representing paths with more accuracy. At the moment Elevation&#8217;s speed scale is totally relative to the data, but I&#8217;d like to peg actual km/h values to it. I&#8217;d also like to indicate the scale of the map with sliding meter/kilometer markers that adjust based on zoom level. As I started going down this road I quickly realized the math needed a closer look.</p>
<p>Without a clue where to begin, I turned to Wikipedia and various open source Java/Javascript libraries to see if they could offer a clue about converting my GPS coordinates into a proper grid. Long story short, what I needed was a <a href="http://en.wikipedia.org/wiki/Map_projection">map projection system</a>.</p>
<p>Mercator is probably the most familiar projection out there, and it&#8217;s the same one Google, Yahoo, Microsoft etc. use for their online mapping services. While it seriously distorts extreme high and low latitudes (Greenland isn&#8217;t really the same size as Africa, after all), it has the advantage of treating smaller local areas more uniformly. Mercator won&#8217;t work at the North Pole or in the Antarctic, but at a regional level like city or state/province it&#8217;s a fairly uniform distortion so the maps just look right; since Elevation is intended for those smaller areas, that&#8217;s perfect for my needs.</p>
<p>So, how does one go about converting GPS lat/long coordinates to actual meters? That&#8217;s where the math comes in, and Wikipedia handily <a href="http://en.wikipedia.org/wiki/Mercator_projection#Mathematics_of_the_projection">lists a few formulas</a> for it. Processing doesn&#8217;t have <code>sinh</code>, <code>cosh</code>, or <code>sec</code> functions, so only the first two functions for <code>y</code> will work; I chose the second:</p>
<pre><code>
x = λ - λo

y = 0.5 * ln * ((1 + sin(φ)) / (1 - sin(φ)))</code></pre>
<p>The <code>x</code> value basically ends up being your raw longitude coordinate, though it&#8217;s handy to offset it from the central <code>x</code> axis of your map. The <code>y</code> value requires a bit more heavy lifting. In Processing, the above functions end up looking something like this:</p>
<pre><code>
float lambda = gpsLong - (mapWidth / 2);

float phi = radians(gpsLat);
float adjustedPhi = degrees(0.5 * log((1 + sin(phi)) / (1 - sin(phi))));</code></pre>
<p>While Wikipedia doesn&#8217;t explicitly say anything about radians, I found it necessary to convert <code>y</code> before the math would work in Processing, then convert the result back to degrees.</p>
<p>The resulting values still don&#8217;t represent real units on the surface of the globe; to get that you have to multiply each by the <a href="http://en.wikipedia.org/wiki/Latitude#Degree_length">degree length</a>, a variable value that corresponds to the surface distance between a single degree change in latitude. At the equator there are <a href="http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy">approximately 111km</a> between degrees, but this number shrinks the closer you get to the poles.</p>
<p>Solving this problem is something I&#8217;m currently working on. An unfortunate red herring was that the degree length in Vancouver appears to be almost exactly 1.6 times less than the value at the equator, which looked for all the world like a flubbed imperial/metric conversion. If I were to start with the equator distance and divide by 1.6:</p>
<pre><code>
x = (adjustedPhi * 111319.9) / 1.6;

y =(lambda * 111319.9) / 1.6;</code></pre>
<p>I would get values that look fairly darn close to accurate in Vancouver. I thought that had solved it, but I now suspect the math at different latitudes is still very much wrong. I&#8217;ll update this post once I know more.</p>
<p><ins datetime="2009-11-22T07:22:06+00:00">Update:</ins> Thanks Microsoft, for publishing <a href="http://msdn.microsoft.com/en-us/library/bb259689.aspx">this piece</a> on MSDN about how your Bing Maps tile system works. This bit in particular seems like it contains what I&#8217;m looking for:</p>
<blockquote>
<p>The ground resolution indicates the distance on the ground that’s represented by a single pixel in the map. For example, at a ground resolution of 10 meters/pixel, each pixel represents a ground distance of 10 meters. The ground resolution varies depending on the level of detail and the latitude at which it’s measured. Using an earth radius of 6378137 meters, the ground resolution (in meters per pixel) can be calculated as:</p>
<pre><code>
ground resolution = cos(latitude * pi/180) * earth circumference / map width

= (cos(latitude * pi/180) * 2 * pi * 6378137 meters) / (256 * 2^level pixels)</code></pre>
<p>The map scale indicates the ratio between map distance and ground distance, when measured in the same units. For instance, at a map scale of 1 : 100,000, each inch on the map represents a ground distance of 100,000 inches. Like the ground resolution, the map scale varies with the level of detail and the latitude of measurement. It can be calculated from the ground resolution as follows, given the screen resolution in dots per inch, typically 96 dpi:</p>
<pre><code>
map scale = 1 : ground resolution * screen dpi / 0.0254 meters/inch

= 1 : (cos(latitude * pi/180) * 2 * pi * 6378137 * screen dpi)
         / (256 * 2^level * 0.0254)
</code></pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/11/projection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPU Usage in Processing</title>
		<link>http://exnihilo.mezzoblue.com/2009/11/cpu-usage-in-processing/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/11/cpu-usage-in-processing/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 18:16:17 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=258</guid>
		<description><![CDATA[I&#8217;ve known for a while now that Processing &#8212; and Elevation in particular &#8212; is a bit of a CPU hog, as evidenced by the hum of the CPU fan frantically spinning every time I run a sketch. I had a vague idea of what the culprit might be, so it&#8217;s an issue I&#8217;ve meant [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve known for a while now that Processing &#8212; and <a href="/elevation/">Elevation</a> in particular &#8212; is a bit of a CPU hog, as evidenced by the hum of the CPU fan frantically spinning every time I run a sketch. I had a vague idea of what the culprit might be, so it&#8217;s an issue I&#8217;ve meant to look into.</p>
<p>Let&#8217;s back up about 13 years for a second; in the mid 90&#8217;s I spent a lot of time cutting my teeth on programming in Basic, a popular beginner&#8217;s languages at the time. I was building fairly simple GUIs for applications and games, but even those were taxing what little processor speed I had available. Back then I stumbled across what I&#8217;d imagine to be a fairly core tenet of any sort of programming that involves drawing to the screen: don&#8217;t, if you can help it.</p>
<p>When you&#8217;re just starting out, you don&#8217;t really consider the work involved in throwing thousands of pixels at the screen every iteration, so you default to simply redrawing the screen during every cycle of your application loop. In the 90&#8217;s this was significantly more of a problem since the CPU just couldn&#8217;t keep up, and we had to learn to selectively redraw only when it was necessary. These days the processor speed is less of a barrier, so the temptation is there to use the extra power we have available. This is fine for learning, but when you&#8217;re producing something people are going to use, your application needs to be more responsible about how much of the CPU&#8217;s time it actually needs.</p>
<p>By the very nature of the <code>draw</code> loop, Processing isn&#8217;t really set up for optimization. The default mode is simply to draw, and redraw, and keep doing it over and over again. When you can take it for granted that the screen will be wiped every cycle, you don&#8217;t necessarily have to think about things like cleaning up old pixels before placing new ones. It&#8217;s convenient, but it comes at a price. Currently an instance of Elevation will run at something like 99% of CPU time, all the time, until it&#8217;s closed. This is a problem.</p>
<p>So last night I started digging into the problem to see if I couldn&#8217;t knock that down a little. The updated code is only available from the <a href="http://github.com/mezzoblue/Elevation/commits/master">GitHub repo</a> so far, but it&#8217;ll likely be rolled into the next version of the app. </p>
<p>I started by adding a global <code>refresh</code> variable that gets set to false, and then wrapped most of the <code>draw</code> loop contents in an <code>if</code> statement that checks to see if it&#8217;s been switched to true. Then just before the loop closes, I make sure to reset it back to false so the next loop won&#8217;t also redraw.</p>
<pre><code>void draw() {

  if (scene.refresh == true) {
    // perform the redraw
  };

  // reset the refresh switch for each loop so we don't peg the CPU
  scene.refresh = false;
};</code></pre>
<p>The question now becomes, when is it appropriate to set <code>refresh</code> to true? That&#8217;s something I&#8217;m still working through; if I simply switch it back on in response to keyboard and mouse event handlers, that&#8217;s a start; but in Elevation I also have on-screen form controls that glow on hover, and switch images between when they&#8217;re selected and when they&#8217;re not. I now have to rework some of the assumptions those controls were making about the <code>draw</code> loop and code them to be a bit smarter about when they actually need to redraw.</p>
<p>Still, just these basic steps were a great start. Manipulating the scene with the mouse and zooming in and out will still tax the CPU, but as soon as you take your hands off the controls usage drops down from 99% to a more reasonable 4% or 5%. That&#8217;s progress.</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/11/cpu-usage-in-processing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Project: Elevation</title>
		<link>http://exnihilo.mezzoblue.com/2009/10/new-project-elevation/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/10/new-project-elevation/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 20:34:42 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[elevation]]></category>
		<category><![CDATA[geodata]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=230</guid>
		<description><![CDATA[As hinted in the comments in my last post, I&#8217;ve cleaned up my 3D elevation code and released it as a project, source and all. Go check out Elevation to grab Mac and Windows executables, or hit up GitHub to grab the source.

This project was a too-perfect alignment of things relevant to my interests. I [...]]]></description>
			<content:encoded><![CDATA[<p>As hinted in the comments in my <a href="http://exnihilo.mezzoblue.com/2009/09/manual-geodata/">last post</a>, I&#8217;ve cleaned up my 3D elevation code and released it as a project, source and all. Go check out <a href="http://exnihilo.mezzoblue.com/elevation/">Elevation</a> to grab Mac and Windows executables, or hit up <a href="http://github.com/mezzoblue/Elevation/">GitHub</a> to grab the source.</p>
<p><a href="http://exnihilo.mezzoblue.com/elevation/"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/10/elevation-icon.png" alt="elevation-icon" title="elevation-icon" width="255" height="254" class="aligncenter size-full wp-image-236" /></a></p>
<p>This project was a too-perfect alignment of things relevant to my interests. I got a chance to really stretch my legs with Processing, had an excuse to tinker with GitHub finally, spent some serious design time in Photoshop thinking through the site and app UI visuals, designed a high-res app icon, got to play with mapping and GPS software, and it all gave me the motivation to go out and pedal around this beautiful city to create my route data in the first place. Spending a month coding while racking up over 400km on the bike seems like a fairly healthy work/play balance.</p>
<p>And happily there&#8217;s plenty of fodder in here for future posts, from parsing differing XML formats to building a functional GUI. More on those soon.</p>
<p>Thanks for the link love to: <a href="http://www.creativeapplications.net/mac/elevation-mac-windows-processing/">CreativeApplications</a>, <a href="https://twitter.com/blprnt/status/4816602502">blprnt</a>, <a href="http://www.rubbishcorp.com/elevation-3d-spacial-gps-rendering/">Rubbishcorp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/10/new-project-elevation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manual Geodata</title>
		<link>http://exnihilo.mezzoblue.com/2009/09/manual-geodata/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/09/manual-geodata/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 16:07:29 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[3D]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=195</guid>
		<description><![CDATA[So if you&#8217;ve recently gotten into a visual programming language, and you also recently bought a bike, what&#8217;s the logical next step? Merge the two pursuits of course.
There&#8217;s an app called RunKeeper for the iPhone 3G/3GS that uses the phone&#8217;s GPS to track your route / elevation / time as you&#8217;re out being active. If [...]]]></description>
			<content:encoded><![CDATA[<p>So if you&#8217;ve recently gotten into a visual programming language, and you also recently bought a bike, what&#8217;s the logical next step? Merge the two pursuits of course.</p>
<p>There&#8217;s an app called <a href="http://www.runkeeper.com/">RunKeeper</a> for the iPhone 3G/3GS that uses the phone&#8217;s GPS to track your route / elevation / time as you&#8217;re out being active. If you upload your routes to the web site, you can get the data back out in a couple of XML formats. (Google&#8217;s <a href="http://code.google.com/apis/kml/documentation/">KML</a> kind of sucks, it turns out; I&#8217;ve been finding <a href="http://www.topografix.com/gpx.asp">GPX</a> files easier to use. RunKeeper&#8217;s web app exports both.)</p>
<p>I&#8217;ve started hacking up an app to plot the data in 3D space. Very early stages, but it&#8217;s working quite well so far. Here&#8217;s a quick video:</p>
<div class="video">
<div class="flvPlayer">				<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="600" height="392"><param name="movie" value="https://media.dreamhost.com/mediaplayer.swf?file=http://exnihilo.mezzoblue.com/wp-content/uploads/2009/09/Elevation.mov&amp;autoStart=false;" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="https://media.dreamhost.com/mediaplayer.swf?file=http://exnihilo.mezzoblue.com/wp-content/uploads/2009/09/Elevation.mov&amp;autoStart=false;" quality="high" wmode="transparent" width="600" height="392" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
				</object></div>
</div>
<p>Make sure to wait for the shift in plotting modes through the movie; I&#8217;ve built three so far: lines, points, and colour-coded points that indicate elevation (blue in the low areas, red in the high areas)</p>
<p>You&#8217;re seeing 7 routes I&#8217;ve ridden over the past couple of days. I&#8217;m already seeing outlines of Vancouver&#8217;s city features forming: the distinctive duck&#8217;s head outline of Stanley Park, the south downtown seawall, the massive hill heading out to UBC, etc.</p>
<p>What&#8217;s obvious is that some of the elevation data, particularly around Stanley Park, is seriously whacked. I think the cliffs obscure the GPS signal or something, because it should be more or less sea level all the way around. (In line view this is most obvious: it&#8217;s a series of jagged peaks and valleys, which strikes me as physically impossible). Hard to say whether it&#8217;s the app or the phone&#8217;s GPS to blame here, but my guess is the latter.</p>
<p>Next step: adding speed indicators, once I figure out how to work with ISO time stamps in Processing. (And going out and biking more paths this weekend to start fleshing out the terrain a bit more. Nice way to stay motivated.)</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/09/manual-geodata/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
<enclosure url="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/09/Elevation.mov" length="2877641" type="video/quicktime" />
		</item>
		<item>
		<title>Generated Palettes from Photos</title>
		<link>http://exnihilo.mezzoblue.com/2009/09/generated-palettes-from-photos/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/09/generated-palettes-from-photos/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 18:09:21 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Palettes]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=190</guid>
		<description><![CDATA[I&#8217;ve had a few requests now to share my code for grabbing generative palettes from photos. So as basic as it is, here&#8217;s my trick.
First I throw a set of photos into the sketch&#8217;s data folder, sequentially named 1.jpg through x.jpg (though I&#8217;ve since discovered Daniel Shiffman&#8217;s excellent directory listing functions that wouldn&#8217;t require me [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a few requests now to share my code for grabbing generative palettes from photos. So as basic as it is, here&#8217;s my trick.</p>
<p>First I throw a set of photos into the sketch&#8217;s data folder, sequentially named 1.jpg through x.jpg (though I&#8217;ve since discovered Daniel Shiffman&#8217;s excellent <a href="http://processing.org/learning/topics/directorylist.html">directory listing</a> functions that wouldn&#8217;t require me to touch the photo filenames). I choose a random image from this folder and load it into an off-screen buffer, then choose random pixels and load their colour values into a palette array.</p>
<pre><code>
// create buffer and setup palette variables
PGraphics buffer;
PImage paletteSource;
color[] palette;
int palettePhotos = 9;
int paletteCount = 24;

void setup() {
  loadPalette(paletteCount);
};

void loadPalette(int paletteCount) {

  // load in an image
  paletteSource = loadImage(int(random(1, palettePhotos)) + ".jpg");

  palette = new color[paletteCount];

  // load the image into the buffer
  buffer.beginDraw();
  buffer.image(paletteSource, 0, 0);
  buffer.endDraw();

  for (int i = 0; i < paletteCount; i++) {
    int colorX = int(random(0, 300));
    int colorY = int(random(0, 300));
    color pick = buffer.get(colorX, colorY);
    palette[i] = pick;
  };

};
</code></pre>
<p>That's it. Stupidly simple, but all the interesting colour combos I've posted on here in the past have been a direct result of this. Not every palette looks great, but if you're using interesting photos as the source, 7 or 8 times out of ten you get something workable.</p>
<p>A bit of code documentation: since I use both portrait and landscape photos, I decided to constrain the area I grab pixels from to a top left square of 300x300 pixels. You can adjust those values to suit, if needed.</p>
<p>You can control the number of colours you load in with the <code>paletteCount</code> variable, and the values ultimately end up in an array called <code>palette[]</code>, which you can use sequentially:</p>
<pre><code>
 background(palette[0]);
</code></pre>
<p>or randomly:</p>
<pre><code>
 int paletteValue = int(random(1, paletteCount));
 obj.R = red(palette[paletteValue]);
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/09/generated-palettes-from-photos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quicktime X = no love for Processing</title>
		<link>http://exnihilo.mezzoblue.com/2009/08/quicktime-x-no-love-for-processing/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/08/quicktime-x-no-love-for-processing/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 22:52:48 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=181</guid>
		<description><![CDATA[Today saw a bit of a setback in my latest project. I jumped the gun and installed a shiny new copy of Snow Leopard on one of my computers, the main one I&#8217;ve been using for all my Processing tinkering. I knew in advance which apps would be affected, but didn&#8217;t really think of the [...]]]></description>
			<content:encoded><![CDATA[<p>Today saw a bit of a setback in my latest project. I jumped the gun and installed a shiny new copy of Snow Leopard on one of my computers, the main one I&#8217;ve been using for all my Processing tinkering. I knew in advance which apps would be affected, but didn&#8217;t really think of the implications of the new Quicktime X update.</p>
<p>Turns out the QTJava library that sites between Processing and the Quicktime codecs that allow it to output video has been <a href="http://www.mailinglistarchive.com/quicktime-java@lists.apple.com/msg00969.html">deprecated</a> as of Quicktime X. Last night I did my first test render and it looked great; today I don&#8217;t have the ability to output .mov files anymore. So, that&#8217;s fun.</p>
<p>I&#8217;ve got a second computer with plain old Leopard on it that I can still render from, but I wish I&#8217;d taken advantage of that second of hesitation when I saw the &#8220;install Quicktime 7&#8243; checkbox as I upgraded this morning. There&#8217;s probably a way to get it back, I&#8217;ll update if I find out what it is.</p>
<p><ins datetime="2009-08-28T22:54:03+00:00">Update:</ins> So getting it back wasn&#8217;t hard. On the Snow Leopard install DVD there&#8217;s a folder called &#8220;Optional Installs&#8221;; run the package in there and select Quicktime 7 from the list. </p>
<p>Except that doesn&#8217;t seem to work. Even with Quicktime 7 I can&#8217;t seem to save out a movie file. Drat.</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/08/quicktime-x-no-love-for-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WallBlank prints now up</title>
		<link>http://exnihilo.mezzoblue.com/2009/08/wallblank-prints-now-up/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/08/wallblank-prints-now-up/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 18:03:10 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Print]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[dots]]></category>
		<category><![CDATA[wallblank]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=176</guid>
		<description><![CDATA[Just a quick update: I mentioned I was having some prints produced a few days ago; they&#8217;ve now been added to WallBank. I wrote up the process in Vector Output, so go have a read if you&#8217;re curious about how I did it. I have a print sitting on my desk, the paper is a [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick update: I mentioned I was having some prints produced a few days ago; they&#8217;ve now <a href="http://wallblank.com/products/bokeh-array">been added </a>to <a href="http://wallblank.com/">WallBank</a>. I wrote up the process in <a href="http://exnihilo.mezzoblue.com/2009/08/vector-output/">Vector Output</a>, so go have a read if you&#8217;re curious about how I did it. I have a print sitting on my desk, the paper is a thick high quality archival stock, and the ink is quite a bit richer than the on-site preview.</p>
<p>In an interesting case of things coming around full circle, apparently the <a href="http://wallblank.com/pages/about">whole idea behind WallBlank&#8217;s site</a> was inspired by a post I wrote on the main blog <a href="http://www.mezzoblue.com/archives/2008/03/04/producing/">last year</a>. Seems only fitting that I&#8217;d contribute something sooner or later.</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/08/wallblank-prints-now-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bring on the Trig</title>
		<link>http://exnihilo.mezzoblue.com/2009/08/bring-on-the-trig/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/08/bring-on-the-trig/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 05:25:59 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=162</guid>
		<description><![CDATA[2&#928;. Pythagorean. SOH CAH TOA. Conjures up terms of grade 10, doesn&#8217;t it? I had to go waaay back into the memory banks to even pull out a starting point for a recent trigonometry refresher.
It started like this: I had an idea to plot some points on a sphere. Now, I understand with some crafty [...]]]></description>
			<content:encoded><![CDATA[<p>2&#928;. Pythagorean. SOH CAH TOA. Conjures up terms of grade 10, doesn&#8217;t it? I had to go waaay back into the memory banks to even pull out a starting point for a recent trigonometry refresher.</p>
<p>It started like this: I had an idea to plot some points on a sphere. Now, I understand with some crafty use of the <code>rotate()</code> function I&#8217;d probably be able to get by without doing the math myself, but I guess I had the urge to dig a bit deeper in case I need to really know this (again) at some point.</p>
<p>So I started light and plotted some random points around a circle. By setting the X coordinate, I can reverse the Pythagorean equation enough to work out the math for the Y coordinate:</p>
<pre><code>
  X = random(0 - radius, radius);
  Y = sqrt(pow(radius, 2) - pow(X, 2));
</code></pre>
<p>That only gets me a positive value for Y though, which renders as a semicircle. So a bit more randomization was necessary to get the full circle:</p>
<pre><code>
  int rev = int(random(0, 2));
  if (rev == 1) {
    Y = sqrt(pow(radius, 2) - pow(X, 2));
  } else {
    Y = 0 - sqrt(pow(radius, 2) - pow(X, 2));
  };
</code></pre>
<p>Which doesn&#8217;t strike me as terribly elegant, but that&#8217;s about the limit of my coding ability.</p>
<div class="thumbnails">
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/Picture-21.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/Picture-21-150x150.png" alt="Random Point Circle" title="Random Point Circle" width="150" height="150" class="alignnone size-thumbnail wp-image-164" /></a>
</div>
<p>So that was the start. Now that I can plot individual points around a circle, why not use something other than points? With some fairly basic <code>box()</code> objects and various rotations and transformations, things get interesting quickly:</p>
<div class="thumbnails">
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-919.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-919-150x150.png" alt="screencap-919" title="screencap-919" width="150" height="150" class="alignnone size-thumbnail wp-image-165" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-9836.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-9836-150x150.png" alt="screencap-9836" title="screencap-9836" width="150" height="150" class="alignnone size-thumbnail wp-image-166" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-6176.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-6176-150x150.png" alt="screencap-6176" title="screencap-6176" width="150" height="150" class="alignnone size-thumbnail wp-image-167" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-6965.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-6965-150x150.png" alt="screencap-6965" title="screencap-6965" width="150" height="150" class="alignnone size-thumbnail wp-image-168" /></a>
</div>
<div class="thumbnails">
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-2446.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-2446-150x150.png" alt="screencap-2446" title="screencap-2446" width="150" height="150" class="alignnone size-thumbnail wp-image-169" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-5530.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-5530-150x150.png" alt="screencap-5530" title="screencap-5530" width="150" height="150" class="alignnone size-thumbnail wp-image-170" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-6119.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-6119-150x150.png" alt="screencap-6119" title="screencap-6119" width="150" height="150" class="alignnone size-thumbnail wp-image-171" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-7964.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/screencap-7964-150x150.png" alt="screencap-7964" title="screencap-7964" width="150" height="150" class="alignnone size-thumbnail wp-image-172" /></a>
</div>
<p>I still haven&#8217;t gotten the math for the sphere down yet, though. That was a &#8220;walk away for now, and come back to it in a few days&#8221; type of problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/08/bring-on-the-trig/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reading a Google Docs Spreadsheet</title>
		<link>http://exnihilo.mezzoblue.com/2009/08/reading-a-google-docs-spreadsheet/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/08/reading-a-google-docs-spreadsheet/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 03:22:16 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Google Docs]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[googledocs]]></category>
		<category><![CDATA[spreadsheet]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=144</guid>
		<description><![CDATA[There doesn&#8217;t seem to be much on the web specifically about tying together Processing and Google Docs, but it&#8217;s fairly simple when you realize the latter has a ton of export options that work pretty easily with Processing. I&#8217;m starting with CSV, though the option to work with XML will likely come in handy down [...]]]></description>
			<content:encoded><![CDATA[<p>There doesn&#8217;t seem to be much on the web specifically about tying together Processing and Google Docs, but it&#8217;s fairly simple when you realize the latter has a ton of export options that work pretty easily with Processing. I&#8217;m starting with CSV, though the option to work with XML will likely come in handy down the line.</p>
<p>Starting with a spreadsheet filled with a few dozen values, I can get at the <a href="http://spreadsheets.google.com/pub?key=tSLqWX2BTMg1-fUyRV5shBQ&#038;single=true&#038;gid=0&#038;output=csv">CSV</a> with a simple export:</p>
<div class="image">
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/Picture-2.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/Picture-2-273x300.png" alt="Picture 2" title="Picture 2" width="273" height="300" class="aligncenter size-medium wp-image-145" /></a>
</div>
<p>The <code><a href="http://processing.org/reference/loadStrings_.html">loadStrings</a></code> function pulls in a local file or a remote URL as a String array:</p>
<pre><code>
String[] inputFileLines;
inputFileLines = loadStrings(
  "http://spreadsheets.google.com/pub? <span class="break">-&gt;</span>
    key=tSLqWX2BTMg1-fUyRV5shBQ&#038;output=csv"
);
</code></pre>
<p>It&#8217;s fairly trivial to walk through the array and do something useful with the numbers:</p>
<pre><code>
inputFileIndex = 0;

while (inputFileIndex < inputFileLines.length) {
  String pieces = inputFileLines[inputFileIndex];
  if (pieces.length() > 0) {

    // do stuff with the 'pieces' string here,

  };
  inputFileIndex++;
};
</code></pre>
<p>The data exists as strings though, so it&#8217;s probably more useful to convert each value to <code>float() </code> or <code>int()</code> before using it. With the simple CSV file I linked up earlier as a source, I used the basic loop to assign the data points as the radii values for each of a set of spheres plotted randomly along the Y axis, or the height of a set of bars slightly tilted along the X axis:</p>
<div class="thumbnails">
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/spheres-53867.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/spheres-53867-150x150.png" alt="spheres-53867" title="spheres-53867" width="150" height="150" class="alignnone size-thumbnail wp-image-155" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/spheres-53667.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/spheres-53667-150x150.png" alt="spheres-53667" title="spheres-53667" width="150" height="150" class="alignnone size-thumbnail wp-image-156" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/blocks-52180.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/blocks-52180-150x150.png" alt="blocks-52180" title="blocks-52180" width="150" height="150" class="alignnone size-thumbnail wp-image-158" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/blocks-53883.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/blocks-53883-150x150.png" alt="blocks-53883" title="blocks-53883" width="150" height="150" class="alignnone size-thumbnail wp-image-159" /></a>
</div>
<p>If we were to say the linear-increasing X value is time, that makes for a couple of fun 3D graphs that even Tufte can be proud of. (Or not.)</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/08/reading-a-google-docs-spreadsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vector Output</title>
		<link>http://exnihilo.mezzoblue.com/2009/08/vector-output/</link>
		<comments>http://exnihilo.mezzoblue.com/2009/08/vector-output/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:32:26 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Print]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://exnihilo.mezzoblue.com/?p=129</guid>
		<description><![CDATA[After some idle speculation about taking my last posted sketch further, I&#8217;ve been going back and forth with a boutique print site called Wall Blank about doing a run of prints. This may be as far as I take them, or it may just be the tip of the iceberg; but more on that later [...]]]></description>
			<content:encoded><![CDATA[<p>After some idle speculation about taking my <a href="http://exnihilo.mezzoblue.com/2009/08/marbles/">last posted sketch</a> further, I&#8217;ve been going back and forth with a boutique print site called <a href="http://wallblank.com/">Wall Blank</a> about doing a run of prints. This may be as far as I take them, or it may just be the tip of the iceberg; but more on that later (whenever I figure it out).</p>
<p>The immediate challenge was outputting something usable in print. I saw two options; figure out a way to use a canvas thousands of pixels across for the sake of saving out a bitmapped screen grab as a file high-resolution enough to print, or, instead find a way to output as vector.</p>
<p>The latter is clearly the better option and it turns out Processing has a built in <a href="http://processing.org/reference/libraries/pdf/index.html">PDF library</a> that does all the hard work for you. It&#8217;s not totally straightforward; you can&#8217;t just dump the screen contents to a file, instead you have to capture the entire <code>draw</code> loop from the start and save that out. But even that is fairly simple. My draw loop ended up something like this:</p>
<pre><code>
void draw() {

  // setup the PDF save
  if (writePDF) {
    beginRecord(PDF, "frame-####.pdf");
  };

      // draw things here

  // now that the draw buffer is full,
  // dump the contents to a file
  if (writePDF) {
    endRecord();
    writePDF = false;
  };
};
</code></pre>
<p>The <code>writePDF</code> variable was an important check; without it I&#8217;d be writing PDFs on every frame. Instead I can toggle it on keypress and just capture a single frame:</p>
<pre><code>
void keyPressed() {
  // if 'p' is pressed, save out a PDF
  if (int(key) == 112) {
    writePDF = true;
  };
};
</code></pre>
<p>The resulting PDFs are surprisingly svelte; 8000 ellipses saved out to about files around 110k. My PNG screen grabs are usually at least 4 times as large.</p>
<p>What was particularly fun about this project is that I dared to ask whether each print could be unique, or if we were stuck working with the same source PDF for each print. I was pleasantly surprised to discover the printer was totally cool with printing a unique file for each one of the 100-print series, and happy to take advantage of that. With a slight modification to my draw loop:</p>
<pre><code>
void draw() {
  if ((createStuff > 0) &#038;&#038; (createStuff < 101)) {
    beginRecord(PDF, "print-####.pdf");
  };

  if ((createStuff > 0) &#038;&#038; (createStuff < 101)) {
    endRecord();
    createStuff++;
  };
};
</code></pre>
<p>...all I had to do was hit a key and wait about a minute, and voila, 100 totally unique prints, but united as a series with a common palette.</p>
<div class="thumbnails">
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0007.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0007-150x150.png" alt="print-0007" title="print-0007" width="150" height="150" class="alignnone size-thumbnail wp-image-130" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0008.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0008-150x150.png" alt="print-0008" title="print-0008" width="150" height="150" class="alignnone size-thumbnail wp-image-131" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0009.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0009-150x150.png" alt="print-0009" title="print-0009" width="150" height="150" class="alignnone size-thumbnail wp-image-132" /></a><br />
<a href="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0095.png"><img src="http://exnihilo.mezzoblue.com/wp-content/uploads/2009/08/print-0095-150x150.png" alt="print-0095" title="print-0095" width="150" height="150" class="alignnone size-thumbnail wp-image-133" /></a>
</div>
<p>I'll make sure to mention it again on here when the prints are available for purchase, probably closer to the end of August.</p>
]]></content:encoded>
			<wfw:commentRss>http://exnihilo.mezzoblue.com/2009/08/vector-output/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
