<?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>Stephen Braitsch</title>
	<atom:link href="http://www.quietless.com/kitchen/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.quietless.com/kitchen</link>
	<description>The choreography of color and code</description>
	<lastBuildDate>Thu, 07 Jan 2010 04:52:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Extract EXIF data using PHP to display GPS-tagged Images in Google Maps</title>
		<link>http://www.quietless.com/kitchen/extract-exif-data-using-php-to-display-gps-tagged-images-in-google-maps/</link>
		<comments>http://www.quietless.com/kitchen/extract-exif-data-using-php-to-display-gps-tagged-images-in-google-maps/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 03:51:16 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=373</guid>
		<description><![CDATA[While cycling around the city this past weekend with my girlfriend I shot a couple quick photos with my iPhone to play with some of the encoded EXIF/GPS data for an upcoming project I am working on. After creating some quick thumbnails, I built the following Google Maps prototype to display the images where I [...]]]></description>
			<content:encoded><![CDATA[<p>While cycling around the city this past weekend with my girlfriend I shot a couple quick photos with my iPhone to play with some of the encoded EXIF/GPS data for an upcoming project I am working on. After creating some quick thumbnails, I built the following Google Maps prototype to display the images where I photographed them extracting the GPS data with a PHP script I have running on the server.</p>
<p><a title="Extract EXIF data using PHP to display GPS-tagged Images in Google Maps" rel="shadowbox;width=1200;height=500;" href="http://www.quietless.com/php/gmaps-gps-images/GoogleMapImageGPS.swf"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2010/01/gmap-gps-cycling.jpg" alt="" /></a></p>
<p>In the process of building this simple example I came across a strange phenomenon where the GPS data wasn&#8217;t being preserved if the original iPhone image was altered in any way. This was happening whenever I saved an edited version of the image in Photoshop CS4 including the creation of a thumbail. <strong><em>Even with the preserve metadata flag selected when saving for web</em></strong>.<br />
<span id="more-373"></span><br />
This was especially annoying because I typically like to use the popular <a href="http://www.nevercenter.com/camerabag/">CameraBag</a> app to easily treat my images before saving them on the phone. An <a href=" http://www.nevercenter.com/camerabag/support/?helptext=exif.txt#text">explanation from their website</a> suggests that Apple does not allow third party applications to preserve the EXIF data on save. Seriously? Not sure if this is true although a very quick search through Apple&#8217;s iPhone dev portal hasn&#8217;t yielded any suggestions one way or the other.</p>
<p>Nonetheless, Apple&#8217;s own photo editing application Aperture <strong>does</strong> preserve the EXIF data when exporting out a version however this is a less than optimal solution as I find cropping and exporting batch sequences of thumbnails to a be a clumsy and tedious operation in Aperture.</p>
<p>So what to do? After some searching for a solution I came across Phil Harvey&#8217;s impressive ExifTool which can read/write/copy image metadata across files ala the command line.</p>
<p>After going <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/">here</a> and installing the package and adding it to my path I can run the following script and copy the GPS data from my source iPhone image1.jpg to my treated version or thumbnail image2.jpg.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">exiftool -overwrite_original <span style="color: #660033;">-tagsfromfile</span> image1.jpg -gps:all image2.jpg</pre></div></div>

<p>Awesome, and there are a whole list of tags, arguments, etc that you can pass into the tool all outlined in the <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#copying_examples">documentation</a>. One thing to note though is that I have been unsuccessful in copying over the data that describes when the source image was created &amp; last modified. Having tried all of the following commands without success I&#8217;m still searching for a solution to copy the timestamp over. If anyone has any ideas I&#8217;d love to hear how you did it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># none of these worked for me...</span>
exiftool -overwrite_original <span style="color: #660033;">-tagsfromfile</span> image1.jpg -all:all image2.jpg
exiftool -overwrite_original <span style="color: #660033;">-tagsfromfile</span> image1.jpg <span style="color: #660033;">-createdate</span> image2.jpg
<span style="color: #666666; font-style: italic;"># attempt to alter the existing date by a few hours...</span>
exiftool -overwrite_original -createdate+=<span style="color: #000000;">3</span> image2.jpg
exiftool -overwrite_original -alldates+=<span style="color: #000000;">1</span>:<span style="color: #000000;">30</span> image2.jpg</pre></div></div>

<p>So after treating the images and banging out some thumbnails, I added the GPS data back in via the ExifTool and pushed everything up my server to try working with the metadata inside of Flash.</p>
<p>The larger project that I am building this prototype for will require the image data to come to Flash via a DB which is why I wrote up a PHP solution instead of reading the image headers right out of the jpeg file using the methods of the AS3 ByteArray.</p>
<p>In my test case here I am communicating with the backend using AMFPHP and wrote a simple service class that includes the main ExifReader class, collects all the EXIF data and sends the results back to Flash.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> AMFDirectoryReader<span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<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;">// relative path to the ExifReader script //</span>
     <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'../../php/gmaps-gps-images/ExifReader.php'</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>    
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getEXIFImageData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$exif</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExifReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$exif</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">readImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$exif</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">readDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERROR: Target Does Not Exist'</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></div></div>

<p>I can then call getEXIFImageData() from Flash using my <a href="http://github.com/braitsch/internal/blob/master/code/com/quietless/remoting/RemotingCall.as">RemotingCall</a> class passing in the $target file or directory I want to read and an array of strings that describe what metadata tags I want to get back.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">quietless</span>.<span style="color: #006600;">remoting</span>.<span style="color: #006600;">RemotingCall</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">quietless</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HTTPRequestEvent</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AppMain <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rc	        :RemotingCall;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _params	:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'gps'</span>, <span style="color: #ff0000;">'date'</span>, <span style="color: #ff0000;">'size'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_target</span>	:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'../../php/gmaps-gps-images/thumbs'</span>;
&nbsp;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AppMain<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>		
     _rc = <span style="color: #000000; font-weight: bold;">new</span> RemotingCall<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://quietless.com/amfphp/gateway.php'</span><span style="color: #66cc66;">&#41;</span>;
     _rc.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'AMFDirectoryReader'</span>, <span style="color: #ff0000;">'getEXIFImageData'</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">_target</span>, _params.<span style="color: #0066CC;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
     _rc.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>HTTPRequestEvent.<span style="color: #006600;">COMPLETE</span>, onRequestComplete<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onRequestComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:HTTPRequestEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
   <span style="color: #66cc66;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">var</span> exif:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">response</span>;
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The real work happens inside of ExifReader where the target image or all images in a target directory are read using calls to <a href="http://php.net/manual/en/function.exif-read-data.php">exif_read_data()</a>. Currently the class only supports the $params arguments &#8216;gps&#8217;, &#8216;date&#8217;, &#8217;size&#8217; but if you take a look at what&#8217;s going on and reference the method&#8217;s <a href="http://php.net/manual/en/function.exif-read-data.php">man page</a> you can easily extend this to send back what you need.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ExifReader<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
  * Returns an array of EXIF data objecta for all jpgs in the target directory 
  **/</span>	
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readDirectory<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">,</span> <span style="color: #000088;">$props</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// $dir points to this directory from amfphp //</span>
    <span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$images</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// loop over the files array and look for images</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// if the jpeg has gps data add it to the images array //	</span>
      <span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">readImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$props</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$images</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* Returns the EXIF data object of a single image 
**/</span>	
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$props</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$exif</span> <span style="color: #339933;">=</span> <span style="color: #990000;">exif_read_data</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$exif</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FILE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FileName'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$props</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>				
  <span style="color: #666666; font-style: italic;">// return an array [lat, lng] //</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'gps'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'gps'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGPS</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// return date value in milliseconds //</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FILE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FileDateTime'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// return size in kilobytes //	</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FILE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'FileSize'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;KB&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* Returns GPS latitude &amp; longitude as decimal values
**/</span>	
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getGPS<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$exif</span> <span style="color: #339933;">=</span> <span style="color: #990000;">exif_read_data</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$exif</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$lat</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPSLatitude'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
      <span style="color: #000088;">$log</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPSLongitude'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$lat</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000088;">$log</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// latitude values //</span>
      <span style="color: #000088;">$lat_degrees</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$lat_minutes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$lat_seconds</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$lat_hemi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPSLatitudeRef'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// longitude values //</span>
      <span style="color: #000088;">$log_degrees</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$log_minutes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$log_seconds</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$log_hemi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exif</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'GPSLongitudeRef'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$lat_decimal</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat_degrees</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat_minutes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat_seconds</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lat_hemi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$log_decimal</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$log_degrees</span><span style="color: #339933;">,</span> <span style="color: #000088;">$log_minutes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$log_seconds</span><span style="color: #339933;">,</span> <span style="color: #000088;">$log_hemi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lat_decimal</span><span style="color: #339933;">,</span> <span style="color: #000088;">$log_decimal</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000000; font-weight: bold;">function</span> toDecimal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$deg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$min</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sec</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hemi</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$deg</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$min</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$sec</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hemi</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'S'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$hemi</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'W'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$d</span><span style="color: #339933;">*=-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$d</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> divide<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// evaluate the string fraction and return a float //	</span>
    <span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// prevent division by zero //</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At some point in the future I&#8217;d like to write an elegant way to load a batch of thumbnails and just extract the image metadata right from within Flash. This solution does allow you to read the image tags first though before you load them, ideal for querying a DB to collect a result set of images that meet a specific requirement say like falling within a coordinate boundary, before actually loading them into Flash.  </p>
<p><a href='http://www.quietless.com/kitchen/wp-content/uploads/2010/01/gmaps-source.zip'>As always downloads of the above classes.</a><br />
Comment and suggestions are most welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/extract-exif-data-using-php-to-display-gps-tagged-images-in-google-maps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Format Twitter &#8216;created_at&#8217; Date with Javascript</title>
		<link>http://www.quietless.com/kitchen/format-twitter-created_at-date-with-javascript/</link>
		<comments>http://www.quietless.com/kitchen/format-twitter-created_at-date-with-javascript/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 18:58:56 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=360</guid>
		<description><![CDATA[This is a quick snippet to format the date string returned in the &#8216;created_at&#8217; property of a typical Twitter XML/JSON request. The request returns a string such as : &#8220;Tue Apr 07 22:52:51 +0000 2009&#8243; which you&#8217;ll probably want to localize and clean up before sticking it on your page.
The following function takes the date [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick snippet to format the date string returned in the &#8216;created_at&#8217; property of a typical Twitter XML/JSON request. The request returns a string such as : &#8220;Tue Apr 07 22:52:51 +0000 2009&#8243; which you&#8217;ll probably want to localize and clean up before sticking it on your page.</p>
<p>The following function takes the date returned by Twitter, converts it to local time and formats it to :<br />
Tue Apr 07 • 10:52 PM</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// pass in the 'created_at' string returned from twitter //</span>
<span style="color: #006600; font-style: italic;">// stamp arrives formatted as Tue Apr 07 22:52:51 +0000 2009 //</span>
<span style="color: #003366; font-weight: bold;">function</span> parseTwitterDate<span style="color: #009900;">&#40;</span>$stamp<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>		
<span style="color: #006600; font-style: italic;">// convert to local string and remove seconds and year //		</span>
	<span style="color: #003366; font-weight: bold;">var</span> date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>Date.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>$stamp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLocaleString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// get the two digit hour //</span>
	<span style="color: #003366; font-weight: bold;">var</span> hour <span style="color: #339933;">=</span> date.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// convert to AM or PM //</span>
	<span style="color: #003366; font-weight: bold;">var</span> ampm <span style="color: #339933;">=</span> hour<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">12</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">' AM'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">' PM'</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hour<span style="color: #339933;">&gt;</span><span style="color: #CC0000;">12</span><span style="color: #009900;">&#41;</span> hour<span style="color: #339933;">-=</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hour<span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> hour <span style="color: #339933;">=</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// return the formatted string //</span>
	<span style="color: #000066; font-weight: bold;">return</span> date.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">' • '</span> <span style="color: #339933;">+</span> hour <span style="color: #339933;">+</span> date.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> ampm<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Of course there are plenty of other ways to do this, including parsing it on the server using php or .net.<br />
If you have a better implementation or suggestion go ahead and post it in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/format-twitter-created_at-date-with-javascript/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dynamically Create an Image in Flash and Save it to the Desktop or Server</title>
		<link>http://www.quietless.com/kitchen/dynamically-create-an-image-in-flash-and-save-it-to-the-desktop-or-server/</link>
		<comments>http://www.quietless.com/kitchen/dynamically-create-an-image-in-flash-and-save-it-to-the-desktop-or-server/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 23:10:29 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=321</guid>
		<description><![CDATA[This is an update to my earlier post where I demonstrated how to dynamically generate an image of a DisplayObject in Flash and push it up to the server using PHP. I&#8217;ve cleaned up and extended the code here to now allow you to also save an image to the desktop using the new save( [...]]]></description>
			<content:encoded><![CDATA[<p>This is an update to my <a href="http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/">earlier post</a> where I demonstrated how to dynamically generate an image of a DisplayObject in Flash and push it up to the server using PHP. I&#8217;ve cleaned up and extended the code here to now allow you to also save an image to the desktop using the new save( ) method of the FileReference class introduced in Flash Player 10.</p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/12/bitmap-snapshot.swf" rel="shadowbox;width=800;height=550;" title="Generate an Image from Flash and Save it to the Desktop or Remote Server"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/12/bitmap-snapshot.jpg" alt="bitmap-snapshot-demo" title="bitmap-snapshot-demo" /></a></p>
<p>To use this class <a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/12/bitmap-snapshot.zip">download the source files</a> and create a new BitmapSnapshot object passing in the DisplayObject you want to create an image of as well as an optional file name, width and height. If width and height are omitted BitmapSnapshot will use the full width and height of the object you are passing in.</p>
<p>Note : BitmapSnapshot will generate a jpg or a png based on the extension of the filename you pass in.<br />
The default output will be a png because it&#8217;s encoding algorithm is much faster than that of jpeg&#8217;s.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> saveToDesktop<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">var</span> img.<span style="color: #006600;">BitmapSnapshot</span> = <span style="color: #000000; font-weight: bold;">new</span> BitmapSnapshot<span style="color: #66cc66;">&#40;</span>_canvas, _filename<span style="color: #66cc66;">&#41;</span>;
    img.<span style="color: #006600;">saveToDesktop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;			
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> saveOnServer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">var</span> img:BitmapSnapshot = <span style="color: #000000; font-weight: bold;">new</span> BitmapSnapshot<span style="color: #66cc66;">&#40;</span>_canvas, _filename<span style="color: #66cc66;">&#41;</span>;
    img.<span style="color: #006600;">saveOnServer</span><span style="color: #66cc66;">&#40;</span>_phpscript, _destination<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>A note on dependencies : BitmapSnapshot does rely on the fantastic jpeg and png encoder classes written by <a href="http://www.kaourantin.net/">Tinic Uro</a> as part of the <a href="http://code.google.com/p/as3corelib/">AS3CoreLibrary</a>. These files are included in the &#8216;libs&#8217; directory along with BitmapSnapshot so be sure this folder is in your class path when you go to compile. </p>
<p>To see the generated image saved to the server, be sure to clear your cache and <a href="http://quietless.com/kitchen/wp-content/uploads/2009/12/bitmap-snapshots/colored-balls.png">view the image here</a>.</p>
<p>As always please leave any questions or problems in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/dynamically-create-an-image-in-flash-and-save-it-to-the-desktop-or-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Playing with P5Sunflow</title>
		<link>http://www.quietless.com/kitchen/playing-with-p5sunflow/</link>
		<comments>http://www.quietless.com/kitchen/playing-with-p5sunflow/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 01:34:49 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=268</guid>
		<description><![CDATA[Over the holiday weekend I had some time and got around to checking out Mark Chadwick&#8217;s port of Sunflow to Processing called P5Sunflow. Really cool engine to relatively quickly render out some 3D screens using simple primitives that you can easily extend. I say relatively quickly because while the code doesn&#8217;t take very long to [...]]]></description>
			<content:encoded><![CDATA[<p>Over the holiday weekend I had some time and got around to checking out Mark Chadwick&#8217;s port of <a href="http://sunflow.sourceforge.net/">Sunflow</a> to Processing called <a href="http://hipstersinc.com/p5sunflow/">P5Sunflow.</a> Really cool engine to relatively quickly render out some 3D screens using simple primitives that you can easily extend. I say relatively quickly because while the code doesn&#8217;t take very long to write, each of the below images took about 1-2 minutes to draw to the screen. </p>
<p>When I have more time I&#8217;ll come back to this and attempt an animation which as I understand it will easily be an overnight render.</p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow1.jpg" rel="shadowbox" ><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow1-575x323.png" alt="SunFlow-Render#1" /></a></p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow2.jpg" rel="shadowbox" ><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow2-575x323.png" alt="SunFlow-Render#2" /></a></p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow3.jpg" rel="shadowbox" ><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow3-575x323.png" alt="SunFlow-Render#3" /></a></p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow4.jpg" rel="shadowbox" ><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow4-575x323.png" alt="SunFlow-Render#4" /></a></p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow5.jpg" rel="shadowbox" ><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow5-575x323.png" alt="SunFlow-Render#5" /></a></p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow7.jpg" rel="shadowbox" ><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/SunFlow7-575x323.png" alt="SunFlow-Render#7" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/playing-with-p5sunflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stussy &amp; Nike NSW pick up CommArts Webpick of the Day 11/12 &amp; 11/18</title>
		<link>http://www.quietless.com/kitchen/stussy-nike-nsw-pick-up-commarts-webpick-of-the-day-1112-1118/</link>
		<comments>http://www.quietless.com/kitchen/stussy-nike-nsw-pick-up-commarts-webpick-of-the-day-1112-1118/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 00:30:48 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[General News]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=246</guid>
		<description><![CDATA[Congratulations to Jason, Dina and Adam at OrdinaryKids for another job well done.
The Communication Arts Webpick of the Day


]]></description>
			<content:encoded><![CDATA[<p>Congratulations to Jason, Dina and Adam at <a href="http://ordinarykids.com/">OrdinaryKids</a> for another job well done.</p>
<p><a href="http://www.commarts.com/webpicks/">The Communication Arts Webpick of the Day</a></p>
<p><a href="https://www.stussy.com/"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/stussy.jpg" alt="stussy" title="stussy" width="575" height="288" class="alignnone size-full wp-image-247" /></a></p>
<p><a href="http://www.nike.com/sportswear/collections/fall09"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/nike-nsw.jpg" alt="nike-nsw" title="nike-nsw" width="575" height="288" class="alignnone size-full wp-image-248" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/stussy-nike-nsw-pick-up-commarts-webpick-of-the-day-1112-1118/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with OpenFrameworks</title>
		<link>http://www.quietless.com/kitchen/getting-started-with-openframeworks/</link>
		<comments>http://www.quietless.com/kitchen/getting-started-with-openframeworks/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 00:32:05 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[OpenFrameworks]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=165</guid>
		<description><![CDATA[After months of peeking curiosity, this past week I finally downloaded and starting playing with OpenFrameworks and taking my first steps to learning C++. 
If you have a Flash / AS3 background like me you&#8217;ll quickly find that the two languages are vastly different not just in their syntax but in the way you structure [...]]]></description>
			<content:encoded><![CDATA[<p>After months of peeking curiosity, this past week I finally downloaded and starting playing with <a href="http://www.openframeworks.cc/">OpenFrameworks</a> and taking my first steps to <a href="http://www.learncpp.com/">learning C++</a>. </p>
<p>If you have a Flash / AS3 background like me you&#8217;ll quickly find that the two languages are vastly different not just in their syntax but in the way you structure a project and setup its dependencies.</p>
<p>With that in mind, this post will hopefully ease the process and help you sidestep some potentially confusing pitfalls especially if you are coming to OpenFrameworks from an AS3 background and have experience with <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">Object Oriented Programming</a>.</p>
<p>So first off, if you don&#8217;t already have oF <a href="http://www.openframeworks.cc/download">download it from here</a> and follow this <a href="http://www.openframeworks.cc/setup">guide</a> to setting up your IDE and compiling an example test project to make sure everything works.</p>
<p>Assuming you got through that ok, (if you didn&#8217;t I suggest hitting the <a href="http://www.openframeworks.cc/forum/">oF forums</a> for more help on getting setup), let&#8217;s walk through a very simple example that builds a basic particle emitter / starfield.</p>
<p><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/particles.jpg" alt="particles" title="particles" width="575" height="359" class="alignnone size-full wp-image-214" /></p>
<h4>Anatomy of an oF project.</h4>
<p>While there are probably many different ways you can approach structuring a C++ project, I like to follow the conventions of Object Oriented design and place code definitions into separate class files in an effort to keep things legible and easy to maintain. While this approach is probably overkill for such a simple example, using separate header and class files will help you get into the practice of organizing your code in such a way that will make your life much easier as you start developing more complex projects. </p>
<p>So first things first. </p>
<p>The first concept to grasp when starting out with OpenFrameworks is understanding how your program initializes.</p>
<p>Just like in Java, Every C++ program has an entry point in the form of a function called Main. This is analogous to the constructor of your &#8216;Document Class&#8217; in AS3. If your AS3 document Class is called &#8216;MyFlashApp&#8217; which subsequently links to a class file called &#8216;MyFlashApp.as&#8217;, the constructor in &#8216;MyFlashApp&#8217; will be the first function that is called when your application starts. It is here you can place calls to other functions that will execute after your program has initialized.</p>
<p>Typical Document Class Constructor in AS3</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyFlashApp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// trace(&quot;hello world&quot;); </span>
    <span style="color: #808080; font-style: italic;">// NowDoSomethingElse();</span>
    <span style="color: #808080; font-style: italic;">// NowDoSomethingAfterThat();</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Every oF project should start with a main.cpp file that defines the Main function that will serve as the entry point to the program</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    ofAppGlutWindow window<span style="color: #339933;">;</span>
    ofSetupOpenGL<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>window<span style="color: #339933;">,</span> <span style="color: #0000dd;">1280</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">720</span><span style="color: #339933;">,</span> OF_FULLSCREEN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// this kicks off the running of my app</span>
    <span style="color: #666666; font-style: italic;">// can be OF_WINDOW or OF_FULLSCREEN</span>
    <span style="color: #666666; font-style: italic;">// pass in width and height too:</span>
    ofRunApp<span style="color: #009900;">&#40;</span> new ParticleEmitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above snippet is just boiler plate code that every OpenFrameworks program should start with. Basically we&#8217;re just creating a window object to draw our program into and setting up the OpenGL graphics engine before we get rolling.</p>
<p>Notice the last line of the function where we call the oF function &#8220;ofRunApp&#8221; and pass it an instance of our ParticleEmitter. This is where we point OpenFrameworks to the custom ParticleEmitter program we are about to build thus linking the two together.</p>
<h4>Creating the Particle Emitter &#8211; Header Declarations and Class Definitions</h4>
<p>In C++ we build class objects using two files. Header declarations(.h) and class definitions(.cpp). While you can get away with declaring everything in one .cpp file, I feel that using separate header and class files helps keep the project organized and easier to maintain and read. </p>
<p>That said consider the following code inside of the header file &#8220;ParticleEmitter.h&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifndef _EMITTER</span>
<span style="color: #339933;">#define _EMITTER</span>
&nbsp;
<span style="color: #339933;">#include &quot;ofMain.h&quot;</span>
<span style="color: #339933;">#include &quot;Particle.h&quot;</span>
<span style="color: #339933;">#define size 5000</span>
&nbsp;
class ParticleEmitter <span style="color: #339933;">:</span> public ofBaseApp<span style="color: #009900;">&#123;</span>
&nbsp;
	private<span style="color: #339933;">:</span>
&nbsp;
	<span style="color: #993333;">int</span> centerX<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> centerY<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> rotation<span style="color: #339933;">;</span>
&nbsp;
	public<span style="color: #339933;">:</span>
&nbsp;
	<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Particle<span style="color: #339933;">*</span> p<span style="color: #009900;">&#91;</span>size<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#endif</span></pre></div></div>

<p>The <b>#ifndef, #define,</b> and <b>#endif</b> statements are what is called a &#8220;header guard&#8221; which is used by the C compiler to check if our ParticleEmitter class has already been included in the program. If it <b>has not,</b> the compiler registers the header file for us which in turn allows us to create instances of the ParticleEmitter class. If you attempt to include a header file more than once, the compiler will complain and your program will probably crash. Header guards help prevent against this. <a href="http://www.learncpp.com/cpp-tutorial/19-header-files/">You can read more about them here.</a></p>
<p>After the header guards we have two include statements. The first includes the &#8220;ofMain.h&#8221; header file which gives us access to the entire oF framework. This is necessary as you&#8217;ll see in a moment because our Particle Emitter is going to extend the class &#8220;ofBaseApp&#8221;, a fundamental base object of the oF library that provides us with access to a number of <a href="http://www.openframeworks.cc/documentation?detail=ofBaseApp#ofBaseApp">core oF properties and commands</a>.</p>
<p>The second include just gives us access to a Particle class that we will define here in a moment. </p>
<p>It might help to think of &#8220;ofBaseApp&#8221; as similar to the AS3 Sprite object in that both typically serve as the necessary base class to their respective programs. In AS3 any class that extends Sprite automatically gains access to the x and y properties of the Sprite class for instance. Similarly, since our ParticleEmitter class extends ofBaseApp we will gain access to the frame rate and background color properties of the ofBaseApp class via <a href="http://www.learncpp.com/cpp-tutorial/111-introduction-to-inheritance/">inheritance</a> as we&#8217;ll see in the ParticleEmitter class definition in a moment. </p>
<p>Looking at the ParticleEmitter class declaration itself inside of ParticleEmitter.h</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">class ParticleEmitter <span style="color: #339933;">:</span> public ofBaseApp <span style="color: #009900;">&#123;</span></pre></div></div>

<p>Translates in AS3 to:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ParticleEmitter <span style="color: #0066CC;">extends</span> ofBaseApp <span style="color: #66cc66;">&#123;</span></pre></div></div>

<p>Once we&#8217;re inside the class declaration we define all the properties and methods that our class will use. Notice how the private and public properties are grouped together. Further note that the &#8216;Private&#8217; keyword is entirely optional, by default any member variables or methods in a class declared <b>before</b> the &#8216;Public&#8217; keyword will automatically be assigned a private scope by the C++ compiler. If you are new to member access specifiers you can <a href="http://www.learncpp.com/cpp-tutorial/83-public-vs-private-access-specifiers/">read about them here.</a></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">class ParticleEmitter <span style="color: #339933;">:</span> public ofBaseApp<span style="color: #009900;">&#123;</span>
&nbsp;
	private<span style="color: #339933;">:</span>
&nbsp;
	<span style="color: #993333;">int</span> centerX<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> centerY<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> rotation<span style="color: #339933;">;</span>
&nbsp;
	public<span style="color: #339933;">:</span>
&nbsp;
	<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Particle<span style="color: #339933;">*</span> p<span style="color: #009900;">&#91;</span>size<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So within our ParticleEmitter declaration we&#8217;ve declared that we&#8217;re going to have an x and y value to position our emitter on the screen and a rotation value to rotate the emitter over time. We also declare three methods, setup, update, and draw that will define what our emitter will do every time the application cycles through a frame. Lastly we declare an Array called &#8220;p&#8221; that will store all of the Particles that are currently on the screen. The pointer syntax(*) that declares the &#8220;p&#8221; array is out of the scope of this article, however you can learn about pointers and how they work in C++ via this <a href="http://www.learncpp.com/cpp-tutorial/67-introduction-to-pointers/">excellent tutorial here</a>.</p>
<p>Lastly, <b>note the hanging semicolon</b> after the closing brace of the class declaration. For some reason the closing brace is not enough by itself to tell the C compiler you&#8217;ve finished your class declaration. If you are experiencing strange errors or your compliler starts throwing EXC_BAD_ACCESS statements at you, ensure that this guy is hanging on there. </p>
<h4>Setup, Update and Draw.</h4>
<p>Now that our ParticleEmitter class is declared, we move on to write its class <b>definition</b>.</p>
<p>One way to think about C++ header and class files is that headers declare the member variables that a class will define. It is like a contract between the two files where anything declared in the header must be defined in its accompanying class file. This is very similar to how interfaces work in AS3. Note however that in C++ headers you are also declaring instance variables where as AS3 interfaces are limited to only method declarations and final static variables.</p>
<p>So with all that said consider the following skeleton code for ParticleEmitter.cpp</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;ParticleEmitter.h&quot;</span>
&nbsp;
<span style="color: #993333;">void</span> ParticleEmitter<span style="color: #339933;">::</span><span style="color: #202020;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    centerX <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    centerY <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span>
    rotation <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    p<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new Particle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> ParticleEmitter<span style="color: #339933;">::</span><span style="color: #202020;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> ParticleEmitter<span style="color: #339933;">::</span><span style="color: #202020;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you look back at Main.cpp you&#8217;ll remember we created an instance of our ParticleEmitter class within the call to ofRunApp() with the line :</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">ofRunApp<span style="color: #009900;">&#40;</span> new ParticleEmitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The &#8220;new&#8221; keyword is used to call the class&#8217;s constructor which creates and returns a new instance of that class, however notice that inside our ParticleEmitter class definition no constructor method is ever defined. It&#8217;s important to note that, like in AS3, constructor methods are entirely optional. However if your class extends ofBaseApp and you chose not to provide a constructor for it, you MUST declare the setup method which gives your custom class the chance to initialize the variables you declared in its header file.</p>
<p>An example of how to use a constructor method inside of a class will be shown in the Particle class coming up.</p>
<h4>AS3 onEnterFrame vs C++ Update and Draw</h4>
<p>Once we&#8217;ve created our ParticleEmitter and have initialized its variables via the setup method, we&#8217;re ready to start calculating expressions and drawing to the screen. </p>
<p>In AS3, once a Flash program initializes we&#8217;re automatically given an onEnterFrame listener that runs in the background listening for changes in application state such as user input. This is essentially what allows things like Event Listeners to work by comparing whether the mouse was up on one frame or was down on another. When the change in state is heard an event is dispatched by the Flash player which allows us to write handlers and execute code based on the new conditions.</p>
<p>In OpenFrameworks this is accomplished a bit differently via two methods of the ofBaseApp class called update and draw. Basically the idea is both of the functions are called every frame and you want to evaluate your expressions in the update method and execute commands that render the screen from within draw. </p>
<p>In AS3 the following code would create a ball and move it 1 pixel to the right every frame.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ball;
<span style="color: #808080; font-style: italic;">// constructor </span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyFlashApp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    ball = <span style="color: #000000; font-weight: bold;">new</span> Ball<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, <span style="color: #0066CC;">onEnterFrame</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onEnterFrame</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    ball.<span style="color: #006600;">x</span> +=<span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This same code written in a C++ class file using oF could be written as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> MyOFApp<span style="color: #339933;">::</span><span style="color: #202020;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    ball<span style="color: #339933;">*</span> <span style="color: #339933;">=</span> new Ball<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> MyOFApp<span style="color: #339933;">::</span><span style="color: #202020;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    x <span style="color: #339933;">+=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> MyOFApp<span style="color: #339933;">::</span><span style="color: #202020;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    ball.<span style="color: #202020;">xpos</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see in C++ we get a little more granular by placing expressions into their own separate update method that is executed right before the draw method where the screen is redrawn.</p>
<h4>Adding in the details of ParticleEmitter.cpp</h4>
<p>First lets fill in our setup method by setting the framerate, background color, telling OpenGL to smooth our particles and hide the cursor. centerX and centerY just capture the center point of the screen which we&#8217;ll want since we told oF in Main.cpp to open in Fullscreen mode. Next we initialize rotation to zero so we can add to it and the last line is a for loop that fills our &#8216;p&#8217; array with a number of particles equal to the constant &#8217;size&#8217; as defined in the ParticleEmitter.h header file, which in our case is 5000.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> ParticleEmitter<span style="color: #339933;">::</span><span style="color: #202020;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    ofSetFrameRate<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ofBackground<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ofHideCursor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ofEnableSmoothing<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    centerX <span style="color: #339933;">=</span> ofGetScreenWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
    centerY <span style="color: #339933;">=</span> ofGetScreenHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
    rotation <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new Particle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now that we got some 5000 particles stored in our &#8216;p&#8217; array, we can define inside of update what to do with them on every frame that ticks by. Here our update method is going to loop over all the particles in the array calling each particles &#8216;update&#8217; method and checking if its &#8216;dead&#8217; property evaluates to true. If it does the ParticleEmitter will delete it from the &#8216;p&#8217; array and create a brand new particle to store in its place. This ensures that we always have a constant number of particles in the &#8216;p&#8217; array at all times, again a value equal to whatever we define &#8217;size&#8217; to be in the header file. Lastly we increment our rotation var that keeps track with the current rotation of the emitter.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> ParticleEmitter<span style="color: #339933;">::</span><span style="color: #202020;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>dead<span style="color: #339933;">==</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    delete p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>	
	    p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new Particle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span>
    rotation<span style="color: #339933;">+=</span><span style="color:#800080;">.05</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>After our array of particles is updated we are ready to refresh the screen.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> ParticleEmitter<span style="color: #339933;">::</span><span style="color: #202020;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>			
    ofTranslate<span style="color: #009900;">&#40;</span>centerX<span style="color: #339933;">,</span> centerY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ofRotate<span style="color: #009900;">&#40;</span>rotation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>ofTranslate is special method of the oF graphics package that allows up to reposition the current &#8216;display object&#8217; on the screen, In this case our ParticleEmitter. Since our ParticleEmitter does not come with a baked in x and y property as we would have with a display object in Flash, we need to use ofTranslate(x, y) to position it in the center of the screen. We then call ofRotate() and pass in the rotation value we incremented in the update method to slowly rotate the emitter around the center of the screen. Lastly we iterate over all of the particles in our &#8216;p&#8217; array calling the draw method on each one which is what actually redraws them to the screen. </p>
<p>With that our Particle Emitter is complete so we can now set up and define the Particle objects themselves.</p>
<h4>The Particle Header Declaration &#8211; Particle.h</h4>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifndef PARTICLE</span>
<span style="color: #339933;">#define PARTICLE</span>
&nbsp;
<span style="color: #339933;">#import &quot;ofMain.h&quot;</span>
&nbsp;
class Particle <span style="color: #009900;">&#123;</span>
&nbsp;
	private<span style="color: #339933;">:</span>
	<span style="color: #993333;">float</span> x<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> y<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> color<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> radius<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> age<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> maxAge<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> speedX<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> speedY<span style="color: #339933;">;</span>
&nbsp;
	public<span style="color: #339933;">:</span>
	Particle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">void</span> update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	bool dead<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#endif</span></pre></div></div>

<p>Once again we wrap the declaration in header guards and import the oF framework via the command #import &#8220;ofMain.h&#8221;. Next within the actual class declaration we&#8217;ll define some private instance variables so the particle knows where it is. After that we explicitly declare a public constructor method which allows us the opportunity to customize each particle before we start calling its update and draw methods. Then after the constructor we have public declarations for update, draw and the boolean variable &#8216;dead&#8217; which will let our ParticleEmitter class know when to remove one particle and replace it with another.</p>
<h4>The Particle Class Definition &#8211; Particle.cpp</h4>
<p>The Particle Class definition itself should hopefully be pretty straightforward. Notice the syntax of the first method Particle::Particle which is the constructor method where we can initialize the variables we declared in the header file.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;Particle.h&quot;</span>
&nbsp;
Particle<span style="color: #339933;">::</span><span style="color: #202020;">Particle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	x <span style="color: #339933;">=</span> ofRandomf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	y <span style="color: #339933;">=</span> ofRandomf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	speedX <span style="color: #339933;">=</span> ofRandom<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	speedY <span style="color: #339933;">=</span> ofRandom<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	radius <span style="color: #339933;">=</span> ofRandom<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	color <span style="color: #339933;">=</span> ofRandom<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xff0000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	age <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	dead <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	maxAge <span style="color: #339933;">=</span> ofRandom<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000dd;">250</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> Particle<span style="color: #339933;">::</span><span style="color: #202020;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	age<span style="color: #339933;">++;</span>
	x <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> speedX <span style="color: #339933;">:</span> speedX<span style="color: #339933;">*-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	y <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>y<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> speedY <span style="color: #339933;">:</span> speedY<span style="color: #339933;">*-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>age <span style="color: #339933;">&gt;=</span> maxAge<span style="color: #009900;">&#41;</span> dead <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> Particle<span style="color: #339933;">::</span><span style="color: #202020;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	ofSetColor<span style="color: #009900;">&#40;</span>color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ofCircle<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> radius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>ofRandomf() is an oF function that returns a random number (float) between -1 and 1. We use random values here in the constructor to ensure that every particle has a slightly unique starting position, color, radius and speed. maxAge is simply a variable to contain a duration value of how long this particle should exist. A value that we&#8217;ll be counting up to every time &#8216;update&#8217; is called which increments this particles current age. </p>
<p>As the application runs the update method is called on every frame incrementing this particles age, its x and y position and checking to see if its current age is >= the max age in which case it sets it &#8216;dead&#8217; property to true.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> Particle<span style="color: #339933;">::</span><span style="color: #202020;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    age<span style="color: #339933;">++;</span>
    x <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> speedX <span style="color: #339933;">:</span> speedX<span style="color: #339933;">*-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    y <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>y<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> speedY <span style="color: #339933;">:</span> speedY<span style="color: #339933;">*-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>age <span style="color: #339933;">&gt;=</span> maxAge<span style="color: #009900;">&#41;</span> dead <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next in the draw method, which is called immediately after update, we set the application&#8217;s color to the color of this particle and draw the particle to its new x and y position on the screen.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> Particle<span style="color: #339933;">::</span><span style="color: #202020;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    ofSetColor<span style="color: #009900;">&#40;</span>color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ofCircle<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> radius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So in linear terms the running of the application can be thought of as such :</p>
<ul>
<li>function main() called inside of main.cpp to start (bootstrap) the application</li>
<li>ofRunApp(new ParticleEmitter()) creates a new instance of the Particle Emitter class and passes it to our running OpenFrameworks application</li>
<li>When the ParticleEmitter is created its setup() method is automatically called by oF which initializes its variables and creates 5000 particles to store in the &#8216;p&#8217; array</li>
<li>ParticleEmitter.update() is automatically called by OpenFrameworks.</li>
<li>ParticleEmitter.update() loops over the &#8216;p&#8217; array and calls the update method on each of the particles which calculates their new x and y position.</li>
<li>ParticleEmitter.draw() is automatically called by OpenFrameworks.</li>
<li>ParticleEmitter.draw() positions the emitter in the center of the screen, rotates it slightly, and again loops over all the particles in the array and redraws each one at its new x and y position</li>
</ul>
<p>And that&#8217;s about it. Note that this is still very much a learning process for me so any feedback or suggestions on how to improve is always welcome in the comments below.</p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/11/ParticleEmitter.zip">Download xCode project and source files here</a></p>
<p>To use the attached files, place the ParticleEmitter folder inside of the directory in which you keep your oF programs. This should be a folder inside of the &#8216;apps&#8217; directory where you installed OpenFrameworks.<br />
Ex. OpenFrameworks->apps->myApps->ParticleEmitter. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/getting-started-with-openframeworks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Moving Forward &amp; Setting New Goals</title>
		<link>http://www.quietless.com/kitchen/moving-forward-setting-new-goals/</link>
		<comments>http://www.quietless.com/kitchen/moving-forward-setting-new-goals/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 00:03:55 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[General News]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=127</guid>
		<description><![CDATA[	In a few days, Nov. 1st, will mark the 1 year anniversary of my move from Portland, OR to San Francisco. It has been an exciting year getting set up in the city, moving from the shared flat in the Mission that I found on Craigslist to watching my girlfriend finish grad school and join [...]]]></description>
			<content:encoded><![CDATA[<p>	In a few days, Nov. 1st, will mark the 1 year anniversary of my move from Portland, OR to San Francisco. It has been an exciting year getting set up in the city, moving from the shared flat in the Mission that I found on Craigslist to watching my <a href="http://jenniepearson.com/">girlfriend</a> finish grad school and join me to help setup our home in the Lower Haight.</p>
<p>	Now that we&#8217;re somewhat stabilized and are starting to grow a small group of good friends, I feel like I can take a moment to reflect and revisit some of the reasons why I moved to SF in the first place. </p>
<p><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/10/jennie-ocean-beach.jpg" title="jennie-ocean-beach" width="575" height="431" /></p>
<p>	For those of you who know me, you know about my background in Film and my experiences in Portland working with the crew of <a href="http://blueprintfilms.com/">blueprintfilms</a>. Having gone to school for English Lit. and then for Film, I was never privy to a formal education in low-level computing, a subject I have always had a real curiosity in since hacking programs on my Commodore 64 back when I was a kid. Suffice to say everything I know about Flash and web application development I learned from <a href="http://oreilly.com/catalog/9780596526948">reading books</a> and of course from <a href="http://theflashblog.com/">various</a> <a href="http://www.kirupa.com/developer/flash/index.htm">sources</a> <a href="http://www.gotoandplay.net/forum/">online</a>. </p>
<p>	So I have been programming Flash for about 7 years now during which time I have taught myself maybe half a dozen other scripting languages that are all commensurate with a career in Interactive Design. While writing Flash programs has always been a blast, I can&#8217;t continue to ignore my growing interest and passion to explore the rapidly expanding space of physical computing. The space that languages like <a href="http://processing.org/">processing</a> and toolkits like <a href="http://www.openframeworks.cc/">openframeworks</a> are really starting to allow access to.</p>
<p>	Years ago when I was in Film school and just getting started with Flash, I remember being inspired by the work of <a href="http://www.crashmedia.com/">Craig Swann</a> and <a href="http://jot.eriknatzke.com/">Eric Natzke</a> and being blown away by what those guys were doing back in the day. Now I&#8217;m seeing <a href="http://www.uva.co.uk/">a new generation</a> of <a href="http://vimeo.com/flight404">talented designers</a> emerge that are <a href="http://vimeo.com/5595869">creating</a> <a href="http://www.chrisoshea.org/projects/hand-from-above/#video">interactive</a> <a href="http://graffitiresearchlab.com/?page_id=76#video">physical</a> <a href="http://toddvanderlin.com/projects/carnival-interactive-aquarium">experiences</a> that go way beyond the boundaries of what I believe the desktop and mobile platforms can inherently provide.</p>
<p>        This is not to suggest that Flash does not continue to hold vast potential for what it is, nor am I abandoning it as I still believe it will continue to dominate as a fantastically expressive technology to create rich desktop experiences. Given its ubiquity and the <a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200910/100509AFPforMobileDevicesandPCs.html">solid R&#038;D that Adobe continues to dedicate to the platform</a>, I wholeheartedly believe that Flash is here to stay. I merely state that I believe a tremendous amount of untapped potential exists in the aforementioned technologies which I, for some time now, have been very excited to explore.</p>
<p>	So with all that having been said, after 7 months and three <a href="http://tracychapman.com/">award</a> <a href="http://www.nike.com/sportswear/collections/fall09/">winning</a> <a href="https://www.stussy.com/">projects</a> with the good people of <a href="http://ordinarykids.com/">Ordinary Kids</a>, I have decided to step out of my full-time role at OK and venture back out on my own to pursue new opportunities to collaborate with others interested in exploring this space.</p>
<p>	If you share my feelings and want to collaborate <a href="mailto:stephen@quietless.com">please reach out.</a> If you live here in the SF Bay area, let&#8217;s go grab a beer. I&#8217;m siked to finally start developing with these technologies and look forward to publishing my findings and explorations here on this blog. </p>
<p>Cheers and thanks for reading.<br />
Stephen</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/moving-forward-setting-new-goals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy Full-Screen Gradients in Flash &#8211; AS3</title>
		<link>http://www.quietless.com/kitchen/easy-full-screen-gradients-in-flash-as3/</link>
		<comments>http://www.quietless.com/kitchen/easy-full-screen-gradients-in-flash-as3/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 19:17:49 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=82</guid>
		<description><![CDATA[Here&#8217;s a handy class that takes an array of hex values and creates a full screen radial or linear gradient that automatically scales to the width and height of the screen.
Implementation is simple.

// create an array of string hex values
var colors:Array = &#91;'0xFFFFFF', '0xF57E04', '0xC64D18', '0xA95354'&#93;;
&#160;
// constrains width to height, convenient for radial gradients
// to [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a handy class that takes an array of hex values and creates a full screen radial or linear gradient that automatically scales to the width and height of the screen.</p>
<p>Implementation is simple.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// create an array of string hex values</span>
<span style="color: #000000; font-weight: bold;">var</span> colors:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'0xFFFFFF'</span>, <span style="color: #ff0000;">'0xF57E04'</span>, <span style="color: #ff0000;">'0xC64D18'</span>, <span style="color: #ff0000;">'0xA95354'</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// constrains width to height, convenient for radial gradients</span>
<span style="color: #808080; font-style: italic;">// to keep them circular, default is true</span>
<span style="color: #000000; font-weight: bold;">var</span> constrain:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// valid types are FullScreenGradient.RADIAL</span>
<span style="color: #808080; font-style: italic;">// or FullScreenGradient.LINEAR, default is RADIAL</span>
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span> = FullScreenGradient.<span style="color: #006600;">RADIAL</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> grad:FullScreenGradient =
--<span style="color: #66cc66;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">new</span> FullScreenGradient<span style="color: #66cc66;">&#40;</span>colors, <span style="color: #0066CC;">type</span>, constrain<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>grad<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>You can use the tool below to drop in color values using the pickers to preview your gradient and check for &#8216;banding&#8217; which seems to be a weird phenomenon that occurs on linear gradients when Flash attempts to interpolate between color values that are too far apart.</p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2009/02/fs-gradient-example.swf" rel="shadowbox;width=1000;height=500;" title="Easy Full-Screen Gradients in Flash - AS3"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2009/02/fs-gradient-preview.jpg" alt="" /></a></p>
<p>Enjoy.</p>
<p><a href="http://www.quietless.com/zip/FullScreenGradient.zip">Download the Class File</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/easy-full-screen-gradients-in-flash-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>AS3 Image Batch Loader with PHP Directory Browsing</title>
		<link>http://www.quietless.com/kitchen/as3-image-batch-loader-with-php-directory-browsing/</link>
		<comments>http://www.quietless.com/kitchen/as3-image-batch-loader-with-php-directory-browsing/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 01:50:51 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=42</guid>
		<description><![CDATA[Updated: February 4. 2009 &#8211; Much cleaner implementation with added comments to hopefully help you understand what is going on
In this being a utility I have been meaning to improve on for awhile, this post attempts to tackle two tasks that are especially common in Flash Platform development. 1st the need to load in a [...]]]></description>
			<content:encoded><![CDATA[<p><em>Updated: February 4. 2009 &#8211; Much cleaner implementation with added comments to hopefully help you understand what is going on</em></p>
<p>In this being a utility I have been meaning to improve on for awhile, this post attempts to tackle two tasks that are especially common in Flash Platform development. 1st the need to load in a batch of images sequentially and 2nd the ability for Flash to be able to &#8217;see&#8217; inside of a directory on the filesystem and load all the available images within.</p>
<p>As is common knowledge, Flash by itself cannot measure the contents of a directory but PHP conveniently can and report back to Flash its findings. This is all accomplished by loading the included PHP script &#8216;directory-reader.php&#8217; into an AS3 URLLoader object and capturing the variables PHP echoes back to it.</p>
<p>Consider the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ImageLoadManager <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">var</span> dr = <span style="color: #000000; font-weight: bold;">new</span> DirectoryReader<span style="color: #66cc66;">&#40;</span>_pathToDirectory,  <span style="color: #ff0000;">'*'</span><span style="color: #66cc66;">&#41;</span>;
   dr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>HTTPRequestEvent.<span style="color: #006600;">COMPLETE</span>, onDirectoryRead<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We create a DirectoryReader object and pass into it the path to the directory we want to read <strong><em>relative to the location of the php script on the filesystem.</em></strong> (We&#8217;ll talk about where that script goes in a second). It should be noted that many PHP installations have URL file-access disabled in the server configuration by default which may throw errors if you try to provide absolute URL&#8217;s. You many need to change your config file to get around this or just use a relative URL as the sample files provided do instead.</p>
<p>Since this utility was designed to gather all of the image files from a directory that Flash supports, (jpg, png, and gif), it will do just that if you leave the second parameter blank. If you are interested in seeing every visible file in the directory (not including sub-directories) you can pass in a wildcard flag ( * ) as shown in the example above. <strong><em>Note the array of file names this returns will include non-image filetypes which will throw IO errors if you pass them into the ImageBatchLoader in the next step.</em></strong></p>
<p>After we&#8217;ve created our DirectoryReader we&#8217;ll want to listen for the &#8216;HTTPRequestEvent.COMPLETE&#8217; event that gets fired when the PHP script is successfully executed. In the onDirectoryRead function below we can access the array of file names that came back from PHP through the data property of HTTPRequestEvent object.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDirectoryRead<span style="color: #66cc66;">&#40;</span>evt:HTTPRequestEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  _files = evt.<span style="color: #0066CC;">data</span> as <span style="color: #0066CC;">Array</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We can then take this list of files and pass it into a new ImageBatchLoader object that will naturally go and load up our images.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDirectoryRead<span style="color: #66cc66;">&#40;</span>evt:HTTPRequestEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  _files = evt.<span style="color: #0066CC;">data</span> as <span style="color: #0066CC;">Array</span>;
<span style="color: #808080; font-style: italic;">// load a batch of images //</span>
  _loader = <span style="color: #000000; font-weight: bold;">new</span> ImageBatchLoader<span style="color: #66cc66;">&#40;</span>_files, _swfToImages<span style="color: #66cc66;">&#41;</span>;
  _loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ImageBatchEvent.<span style="color: #006600;">IMAGE_PROGRESS</span>, 
   onImageLoadProgress<span style="color: #66cc66;">&#41;</span>;
  _loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ImageBatchEvent.<span style="color: #006600;">BATCH_PROGRESS</span>, 
   onImageBatchProgress<span style="color: #66cc66;">&#41;</span>;
  _loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ImageBatchEvent.<span style="color: #006600;">BATCH_COMPLETE</span>, 
   onImageBatchComplete<span style="color: #66cc66;">&#41;</span>;	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>An instance of the ImageBatchLoader class expects at least one parameter, an array of file names to load. Once it has this it will load each image one by one and trace out a whole slew of loader event info to the console so you can monitor each image load&#8217;s progress. <em>(Note: To view this output set the debug property of _loader to true)</em> The second parameter is a relative path to the directory where the images to be loaded reside. It should be noted that this path will almost always be different from the path you fed to DirectoryReader since <strong><em>it needs to be relative to the location of the published SWF on the filesystem, NOT the location of the PHP file as we noted above.</em></strong></p>
<p>Of course you can create a list of files names via a remoting call that polls a database or by reading in an XML file. The purpose of this technique to address those situations where you need a fast and lightweight solution to &#8216;peek&#8217; inside a directory and grab however many images are in it.</p>
<p>This can all be accomplished with the following sample of code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">quietless</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">DirectoryReader</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">quietless</span>.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">ImageBatchLoader</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">quietless</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ImageBatchEvent</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">quietless</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HTTPRequestEvent</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ImageLoadManager <span style="color: #0066CC;">extends</span> Sprite
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loader:ImageBatchLoader;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _files:<span style="color: #0066CC;">Array</span>; <span style="color: #808080; font-style: italic;">// all files names returned by php //</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _bitmaps:<span style="color: #0066CC;">Array</span>;<span style="color: #808080; font-style: italic;">// all bitmaps successfully loaded //</span>
<span style="color: #808080; font-style: italic;">// path from the published swf to the image folder //</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _swfToImages:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'images/'</span>;	
<span style="color: #808080; font-style: italic;">// path from the php script to the directory you want to browse //	</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _phpToImages:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'../images'</span>;	
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ImageLoadManager <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">var</span> dr = <span style="color: #000000; font-weight: bold;">new</span> DirectoryReader<span style="color: #66cc66;">&#40;</span>_phpToImages, <span style="color: #ff0000;">'*'</span><span style="color: #66cc66;">&#41;</span>;
   dr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>HTTPRequestEvent.<span style="color: #006600;">COMPLETE</span>, onDirectoryRead<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDirectoryRead<span style="color: #66cc66;">&#40;</span>evt:HTTPRequestEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
   _files = evt.<span style="color: #0066CC;">data</span> as <span style="color: #0066CC;">Array</span>;
<span style="color: #808080; font-style: italic;">// load a batch of images //</span>
   _loader = <span style="color: #000000; font-weight: bold;">new</span> ImageBatchLoader<span style="color: #66cc66;">&#40;</span>_files, _swfToImages<span style="color: #66cc66;">&#41;</span>;
   _loader.<span style="color: #006600;">debug</span> = <span style="color: #000000; font-weight: bold;">false</span>;
   _loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ImageBatchEvent.<span style="color: #006600;">IMAGE_PROGRESS</span>, 
   onImageLoadProgress<span style="color: #66cc66;">&#41;</span>;
   _loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ImageBatchEvent.<span style="color: #006600;">BATCH_PROGRESS</span>, 
   onImageBatchProgress<span style="color: #66cc66;">&#41;</span>;
   _loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ImageBatchEvent.<span style="color: #006600;">BATCH_COMPLETE</span>, 
   onImageBatchComplete<span style="color: #66cc66;">&#41;</span>;			    
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onImageLoadProgress<span style="color: #66cc66;">&#40;</span>evt:ImageBatchEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">var</span> bl:<span style="color: #0066CC;">Number</span> = evt.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">loaded</span>;
   <span style="color: #000000; font-weight: bold;">var</span> bt:<span style="color: #0066CC;">Number</span> = evt.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">total</span>;
   <span style="color: #0066CC;">log</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Loading Image # '</span>+evt.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">position</span>+<span style="color: #ff0000;">' : '</span>+bl+<span style="color: #ff0000;">' of
   --&gt; '</span>+bt+<span style="color: #ff0000;">' Bytes Loaded = '</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">ceil</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bl<span style="color: #66cc66;">/</span>bt<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">' %'</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onImageBatchProgress<span style="color: #66cc66;">&#40;</span>evt:ImageBatchEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">log</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Successfully Loaded '</span>+evt.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">loaded</span>+<span style="color: #ff0000;">' of 
   --&gt; '</span>+evt.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">total</span>+<span style="color: #ff0000;">' Images In This Batch'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onImageBatchComplete<span style="color: #66cc66;">&#40;</span>evt:ImageBatchEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
   _bitmaps = evt.<span style="color: #0066CC;">data</span> as <span style="color: #0066CC;">Array</span>;
   <span style="color: #000000; font-weight: bold;">var</span> img = _bitmaps<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>; 		
   addChild<span style="color: #66cc66;">&#40;</span>img<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #0066CC;">log</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Image Batch Load Complete!!'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As for the business of where to put the PHP script that can actually read the directory you specify? I have it set as a constant variable inside of the DirectoryReader class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const PATH_TO_DIRECTORY_READER:<span style="color: #0066CC;">String</span> =
   <span style="color: #ff0000;">'http://localhost:8888/php/directory-reader.php'</span>;</pre></div></div>

<p>My <a href="http://www.mamp.info">Mamp</a> installation points to my project root folder which contains a &#8216;php&#8217; folder (containing &#8216;directory-reader.php&#8217;), an &#8216;images&#8217; folder that contains my images and of course the published swf and an html page. <strong><em>Note you will need to have a server running PHP 5 locally if you want to test the sample files from the Flash IDE.</em></strong></p>
<p>If you have any questions please post in the comments below.</p>
<p><a href="http://www.quietless.com/zip/ImageLoadManager.zip">Sample Files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/as3-image-batch-loader-with-php-directory-browsing/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Tracy Chapman wins FWA!</title>
		<link>http://www.quietless.com/kitchen/tracy-chapman-wins-fwa/</link>
		<comments>http://www.quietless.com/kitchen/tracy-chapman-wins-fwa/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 18:56:21 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>
		<category><![CDATA[General News]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=38</guid>
		<description><![CDATA[I just got the call from Jason that the site I built for Tracy&#8217;s new album, &#8216;Our Bright Future&#8217; has won the FWA for December 28, 2008! 
Very special thanks to Jason, Adam, Sanaz and Hampus at Ordinary Kids and of course Tracy and Gretchen for making it happen. What a great Xmas present!!
]]></description>
			<content:encoded><![CDATA[<p>I just got the call from Jason that the site I built for Tracy&#8217;s new album, &#8216;Our Bright Future&#8217; has won the <a href="http://www.thefwa.com/">FWA</a> for December 28, 2008! </p>
<p>Very special thanks to Jason, Adam, Sanaz and Hampus at <a href="http://ordinarykids.com/">Ordinary Kids</a> and of course Tracy and Gretchen for making it happen. What a great Xmas present!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/tracy-chapman-wins-fwa/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Work &#8211; Tracy Chapman</title>
		<link>http://www.quietless.com/kitchen/new-work-tracy-chapman/</link>
		<comments>http://www.quietless.com/kitchen/new-work-tracy-chapman/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 18:19:35 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[General News]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/?p=17</guid>
		<description><![CDATA[After four months of traveling throughout the US and France, and Italy I have finally landed, now in the beautiful city to the south of my beloved Portland, San Francisco. It was an awesome nine years living in Stumptown and I already miss the great friends I have made there over the years. 

After getting [...]]]></description>
			<content:encoded><![CDATA[<p>After four months of traveling throughout the <a href="http://www.flickr.com/photos/braitsch/sets/72157606978809829/">US</a> and <a href="http://www.flickr.com/photos/braitsch/sets/72157607246930638/">France</a>, and <a href="http://www.flickr.com/photos/braitsch/sets/72157607460401341/">Italy</a> I have finally landed, now in the beautiful city to the south of my beloved Portland, <a href="http://www.flickr.com/photos/braitsch/sets/72157606638203998/">San Francisco.</a> It was an awesome nine years living in Stumptown and I already miss the great friends I have made there over the years. </p>
<p><a href="http://tracychapman.com"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2008/11/tracy-chapman-site.jpg" alt="Tracy-Chapman-Our-Bright-Future" title="Tracy-Chapman" /></a></p>
<p>After getting back in the states in late September I shuffled down to SF in search of work and while hustling out of hotel rooms all over the city I worked with the brilliant team over at <a href="http://ordinarykids.com/">Ordinary Kids</a> to produce the new <a href="http://tracychapman.com/">Tracy Chapman</a> site. The site leverages a simple painting engine that I wrote which lets you paint the elements onscreen as you cruise around the site. I think a great addition in V2 would be to add functionality to save your creation to a gallery or maybe write a cookie that saves your painting for the next time you return.</p>
<p>As for being in SF. I am loving it here and siked to finally be able to pour myself into my work again. I am currently taking on freelance projects while searching for the perfect F/T opportunity.<br />
If you think we&#8217;d be a great fit, <a href="mailto:stephen@quietless.com">hit me up</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/new-work-tracy-chapman/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Transform Tool &#8211; Drag, Scale and Rotate in Flash at Runtime</title>
		<link>http://www.quietless.com/kitchen/transform-tool-drag-scale-and-rotate-at-runtime/</link>
		<comments>http://www.quietless.com/kitchen/transform-tool-drag-scale-and-rotate-at-runtime/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 17:39:30 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/transform-tool-drag-scale-and-rotate-at-runtime/</guid>
		<description><![CDATA[On a recent project I created a Transform Tool similar to the one you might find in a typical CS3 application like Photoshop, Illustrator or Flash. Once you instantiate this tool and and assign it a target, you can easily scale, drag and rotate it around the Stage at runtime. Optional properties include a min [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent project I created a Transform Tool similar to the one you might find in a typical CS3 application like Photoshop, Illustrator or Flash. Once you instantiate this tool and and assign it a target, you can easily scale, drag and rotate it around the Stage at runtime. Optional properties include a min and max scale value, a boundaries Rectangle object to constrain where the target can be dragged and custom scale and rotate handle icons that you can specify via a linked MovieClip in the library.</p>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2008/08/transform-tool.swf" rel="shadowbox;width=575;height=360;" title="Transform Tool - Drag, Scale and Rotate in Flash at Runtime"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2008/08/transform-tool.jpg" alt="TransformTool" /></a></p>
<p>In a future version I will combine scale and rotate into one mode eliminating the need to select between them.</p>
<p><a href="http://www.quietless.com/docs/transform-tool.html">View the documentation here</a><br />
<a href="http://www.quietless.com/zip/TransformTool.zip">View the source files here</a></p>
<p>Update 11/24/09 : This class has been refactored for improved legibility. Also added now is the ability to register specific targets on the stage via an internal _targets array. <a href="http://www.quietless.com/docs/transform-tool.html">See documentation for details.</a></p>
<p>Update 11/24/08 : There was a syntax bug that was confusing placement of the transform handles which subsequently was throwing the selected object off screen at times. This has been fixed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/transform-tool-drag-scale-and-rotate-at-runtime/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Upload BitmapData Snapshot to Server in AS3</title>
		<link>http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/</link>
		<comments>http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/#comments</comments>
		<pubDate>Fri, 30 May 2008 18:11:39 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Actionscript / Flash]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[fileupload]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[snapshot]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/</guid>
		<description><![CDATA[Note : This class has been updated, you can view the new post here.
Here is a very simple wrapper class I wrote last night that allows you to take a BitmapData snapshot of a Display Object on the Stage, convert it to a .png or .jpg and upload it to your server in a directory [...]]]></description>
			<content:encoded><![CDATA[<p><em>Note : This class has been updated, <a href="http://www.quietless.com/kitchen/save-an-image-from-flash-to-the-desktop-or-server/">you can view the new post here</a>.</em></p>
<p>Here is a very simple wrapper class I wrote last night that allows you to take a BitmapData snapshot of a Display Object on the Stage, convert it to a .png or .jpg and upload it to your server in a directory you can specify at runtime. All in about 10 lines of code.</p>
<p>The technique is quite simple. You instantiate a new &#8216;DynamicBitmap&#8217; and pass in the target DisplayObject you want to snapshot as well as a string of the filename you want to call it. e.g. &#8216;MyBitmapSnapshot.png&#8217;</p>
<p>In the following example I created two buttons on the stage which snapshot and upload the bitmap separately however you can combine this all into one action if you like.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dbmp:DynamicBitmap;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _uploadScript:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'uploads/upload.php'</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _uploadDirectory:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'images/'</span>; <span style="color: #808080; font-style: italic;">// optional //</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_target</span>; <span style="color: #808080; font-style: italic;">// some display object on the stage //</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _filename:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">'myBitmapSnapshot.png'</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ApplicationMain <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
     snapshot_btn.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, takeSnapshot<span style="color: #66cc66;">&#41;</span>;
     upload_btn.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, uploadSnapshot<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> takeSnapshot<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
     _dbmp = <span style="color: #000000; font-weight: bold;">new</span> DynamicBitmap<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_target</span>, _filename<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> uploadSnapshot<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
     _dbmp.<span style="color: #006600;">upload</span><span style="color: #66cc66;">&#40;</span>_uploadscript, _directory<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Underneath the _target DisplayObject is drawn into a BitmapData object and then based on the file extension you give it in the filename it is converted into either a JPEG or PNG byteArray using the <a href="http://code.google.com/p/as3corelib/">AS3CoreLib</a> encoding classes by <a href="http://www.kaourantin.net/2005/10/png-encoder-in-as3.html">Tinic Uro</a>.</p>
<p>These encoding classes return a raw byteArray which by itself cannot be uploaded to the server as the <a href="http://en.wikipedia.org/wiki/MIME#Multipart_messages">MIME</a> protocol requires precisely defined headers to accompany the raw image data and instruct the server what to do with it.</p>
<p>Enter the URLRequestWrapper class which is a slightly modified version of the UploadPostHelper class written by <a href="http://marstonstudio.com/index.php/2007/08/19/how-to-take-a-snapshot-of-a-flash-movie-and-automatically-upload-the-jpg-to-a-server-in-three-easy-steps">Jonathan Marston</a> which adds in the necessary headers required by the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">--pfhchaivbrmxhcighexxsspxpxhepeea</span>
&nbsp;
Content-Disposition: form-data; <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;Filename&quot;</span>
&nbsp;
myBitmapSnapshot.png
&nbsp;
<span style="color: #660033;">--pfhchaivbrmxhcighexxsspxpxhepeea</span>
&nbsp;
Content-Disposition: form-data; <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;dir&quot;</span>
&nbsp;
images<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #660033;">--pfhchaivbrmxhcighexxsspxpxhepeea</span>
&nbsp;
Content-Disposition: form-data; <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;Filedata&quot;</span>; <span style="color: #007800;">filename</span>=<span style="color: #ff0000;">&quot;myBitmapSnapshot.png&quot;</span>
&nbsp;
Content-Type: application<span style="color: #000000; font-weight: bold;">/</span>octet-stream
&nbsp;
PNG</pre></div></div>

<p>The URLRequestWrapper is simply a modified URLRequest with a data property that contains the image data and all the necessary headers required by the server, including the optional destination directory you specified for the image. When this URLRequest is loaded into a URLLoader object it arrives at the server via the global $_POST array.</p>
<p>I&#8217;ve included a simple upload script &#8216;uploads.php&#8217; that looks for a &#8216;dir&#8217; property in the header information which contains the _uploadDirectory variable you specified in Flash. It is entirely optional, if no directory is specified it will install the image in the default directory as specified in the upload.php script. This may prove handy in an application where the you&#8217;d like to be able to change the destination directory of the newly created image at runtime.</p>
<p>Note:  If you specify a directory that does not exist on the server it will be created via the new <a href="http://us.php.net/mkdir">recursive flag</a> introduced in php5. Be sure to have php5 installed and enabled on your server or the script will throw an argument error and possibly not run.</p>
<p><a href='http://www.quietless.com/kitchen/wp-content/uploads/2008/05/bitmapuploader.zip' title='Source Example Files Here'>Source Example Files Here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Top Five Things You Need to Know Before Driving Across The United States</title>
		<link>http://www.quietless.com/kitchen/top-five-things-you-need-to-know-before-driving-across-the-united-states/</link>
		<comments>http://www.quietless.com/kitchen/top-five-things-you-need-to-know-before-driving-across-the-united-states/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 17:44:57 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[Travel]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/how-to-drive-across-america/</guid>
		<description><![CDATA[On March 10th I flew one-way from Portland, Oregon to Charlotte, North Carolina to pick up my &#8216;97 Honda Civic and drive it 3700 miles back across America. My girlfriend Jennie accompanied me for half of the trip back to Lincoln, Nebraska where she had to pit stop to hustle up on getting her graduate [...]]]></description>
			<content:encoded><![CDATA[<p>On March 10th I flew one-way from Portland, Oregon to Charlotte, North Carolina to pick up my &#8216;97 Honda Civic and drive it 3700 miles back across America. My girlfriend <a href="http://www.jenniepearson.com">Jennie</a> accompanied me for half of the trip back to Lincoln, Nebraska where she had to pit stop to hustle up on getting her graduate degree at <a href="http://sram.unl.edu/">UNL</a>.</p>
<p><a href="http://www.flickr.com/photos/braitsch/sets/72157604260037948/"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2008/04/welcome-oregon.jpg" alt="Welcome To Oregon" /></a></p>
<p>Now safely back in Portland and reflecting on the experience, I have realized there are some immutable facts one must know before taking on the open road.</p>
<h3><strong>Top Five Things You Need to Know Before Driving Across America.</strong></h3>
<p><strong><em>01. Maintain at least a half-tank of gas at all times.</em></strong><br />
<strong>America</strong> is <strong>BIG</strong>, very big, and there are <a href="http://www.flickr.com/photos/braitsch/2382935303/in/set-72157604260037948/" title="No Fuel">huge empty pockets of nothingness with signs that announce &#8216;No Services&#8217;</a> at what might misleading seem like a safe pull-off from the interstate to re-fuel.</p>
<p>If you do not maintain at least a half tank of gas in your car at all times, you are asking for pain.</p>
<p><a href="http://www.fhwa.dot.gov/trafficinfo/"><em><strong>02. Check the Weather and Road Closures Report Daily.</strong></em></a><br />
Depending on the time of year you are traveling, the weather can change dramatically within a few hundred miles. On the morning I left Lincoln, NE heading west on I-80 I hit a road closure just past the Wyoming border that forced me to take <a href="http://www.flickr.com/photos/braitsch/2383698270/in/set-72157604260037948/">a 300 mile detour south into Colorado and into a blizzard</a> that almost stranded me atop the Rocky Mountains. While I&#8217;m usually all about the unexpected adventure, in this case I had a plane to catch in 48 hours back in Portland and was still 1500 miles away from the airport!</p>
<p><em><strong>03. Plan your destinations in advance.</strong></em><br />
I used to be of the school &#8220;we&#8217;ll figure it out when we get there&#8221; then I arrived in St. Louis and spent over two hours looking for a room that was less than $200 a night. Get a listing of hotels/motels/hostels that are in your price range and print out a map of their locations to bring with you. While it might seem tedious, the 20 minutes you spend now before you leave will save you hours of searching when you arrive in a city exhausted from having just driven hundreds of miles to get there.</p>
<p><em><strong>04. Decide what you really want to see and what you can pass on.</strong></em><br />
It is impossible to get any real impression of a city by just staying the night there and getting coffee the next morning before you hit the road again. You&#8217;ll think you&#8217;ll have all this energy to explore, but trust me after you drive 5 hours to get there and have been on the road for a few days your ambition to explore wanes in favor of a drink and a hot shower. If you want to see a city and remember something about it, plan to stay at least one full day there by booking two nights of lodging before you leave town. We did exactly this in St. Louis and had a blast.</p>
<p><em><strong>05. Pack a survival kit.</strong></em><br />
Again, this might seem overkill, but if you break down in <a href="http://www.flickr.com/photos/braitsch/2382865667/in/set-72157604260037948/">a blizzard at 9,000 ft</a> you&#8217;ll be happy to have a few extra blankets to keep you company until help arrives. Also don&#8217;t rely solely on AAA as I found that there were plenty of pockets along my drive where I didn&#8217;t have cell-phone service (thanks to Sprint) so I wouldn&#8217;t have been able to call them if needed.</p>
<p><strong>The Essential Cross-Country Road Trip Survival Kit</strong></p>
<ul>
<li>Spare tire, jack, and <a href="http://images.jupiterimages.com/common/detail/02/88/22768802.jpg">tire iron</a> to take off lug nuts</li>
<li>Road flares (available at most auto part stores for a dollar or so each)</li>
<li>A flashlight in case you breakdown at night</li>
<li><a href="http://www.amazon.com/McNally-United-States-Canada-Mexico/dp/0528939661/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1208635622&amp;sr=8-1">A real road atlas</a>, not a $3.99 map of the US from 7-11</li>
<li>Sunglasses!</li>
<li>Snow chains that you&#8217;ve tested to fit your car.</li>
<li>A credit card that earns you points for gasoline purchases</li>
<li>$200 in emergency cash for the mechanic in Wyoming who doesn&#8217;t take Amex.</li>
<li>A fifth of Jack Daniels (for the hotel room)</li>
<li>And a digital camera to remember it all.</li>
</ul>
<p><a href="http://www.quietless.com/kitchen/wp-content/uploads/2008/04/map-america-large.jpg"><img src="http://www.quietless.com/kitchen/wp-content/uploads/2008/04/map-across-america.jpg" alt="xCountry Trip 2008" /></a></p>
<p><strong> Bonus: Expense Recap of Entire Trip </strong></p>
<ul>
<li>One-Way Plane Ticket from Portland, OR &#8211; Charlotte, NC : $149</li>
<li>Cost to totally tune-up the car for the drive : $614</li>
<li>Gasoline (14 fill-ups) : $340</li>
<li>Hotel/Motel/Hostel Accommodations (total 4 nights) : $370<br />
<em> The rest of the time we stayed w/ family and friends</em></li>
<li>Restaurants and Supermarkets : $590</li>
<li>Alcohol / Bars : $100</li>
<li>Random Fun, Misc Crap, etc.. $270</li>
</ul>
<p><strong>Total length of trip : 3 Weeks / 3700 Miles</strong><br />
<strong>Total cost of the whole sha-bang : $2433</strong></p>
<p><strong>Happy Travels!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/top-five-things-you-need-to-know-before-driving-across-the-united-states/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Starting Over</title>
		<link>http://www.quietless.com/kitchen/starting-over/</link>
		<comments>http://www.quietless.com/kitchen/starting-over/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 06:45:20 +0000</pubDate>
		<dc:creator>Stephen Braitsch</dc:creator>
				<category><![CDATA[General News]]></category>

		<guid isPermaLink="false">http://www.quietless.com/kitchen/starting-over/</guid>
		<description><![CDATA[Last friday I quit my job. and holy shit did it feel good!! And so now, once again, I  saddle up on the bucking horse of self-employment wild eyed and excited about what the next year will bring.

I’m starting this blog of sorts to document this process as now, working for myself, I will [...]]]></description>
			<content:encoded><![CDATA[<p>Last friday I quit my job. and holy shit did it feel good!! And so now, once again, I  saddle up on the bucking horse of self-employment wild eyed and excited about what the next year will bring.</p>
<p><img src="http://www.quietless.com/kitchen/wp-content/uploads/2008/03/niagara-overcracker.jpg" alt="Robert Overcracker jumps Niagara Falls on a jet-ski" /></p>
<p>I’m starting this blog of sorts to document this process as now, working for myself, I will once more have total control over my days allowing me to spend my time as I see fit. So in the spirit of experimentation, I intentionally come at this without a plan but to simply record and keep organized the various projects and conversations I will participate in over the next few months.</p>
<p>Furthermore expect colorful bitch sessions if I encounter any terrorists along the way.<br />
Woot Woot! Go me!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.quietless.com/kitchen/starting-over/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
