<?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>www.mark-hill.co.uk</title>
	<atom:link href="http://www.mark-hill.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mark-hill.co.uk/blog</link>
	<description></description>
	<lastBuildDate>Thu, 22 Jul 2010 13:48:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Processing JS Test</title>
		<link>http://www.mark-hill.co.uk/blog/2010/07/22/processing-js-test/</link>
		<comments>http://www.mark-hill.co.uk/blog/2010/07/22/processing-js-test/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 13:37:01 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[processing.js]]></category>

		<guid isPermaLink="false">http://www.mark-hill.co.uk/blog/?p=190</guid>
		<description><![CDATA[float radius = 50.0; int X, Y; int nX, nY; int delay = 16; void setup(){ size( 200, 200 ); strokeWeight( 10 ); frameRate( 15 ); X = width / 2; Y = width / 2; nX = X; nY = Y; } void draw(){ radius = radius + sin( frameCount / 4 ); X+=(nX-X)/delay; [...]]]></description>
			<content:encoded><![CDATA[<p><script type="application/processing">
float radius = 50.0;
int X, Y;
int nX, nY;
int delay = 16;

void setup(){
size( 200, 200 );
strokeWeight( 10 );
frameRate( 15 );
X = width / 2;
Y = width / 2;
nX = X;
nY = Y;
}

void draw(){
radius = radius + sin( frameCount / 4 );
X+=(nX-X)/delay;
Y+=(nY-Y)/delay;
background( 100 );
fill( 0, 121, 184 );
stroke(255);
ellipse( X, Y, radius, radius );
}

void mouseMoved(){
nX = mouseX;
nY = mouseY;
}
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mark-hill.co.uk/blog/2010/07/22/processing-js-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing, Drupal, and JSON</title>
		<link>http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/</link>
		<comments>http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 12:15:26 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[drupal]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[sourcecode]]></category>

		<guid isPermaLink="false">http://www.mark-hill.co.uk/blog/?p=54</guid>
		<description><![CDATA[Introduction Drupal is a powerful open-source content management framework, whose core functionality is hugely extensible through the use of contributed modules, of which there are literally thousands! This allows you to do all sorts of weird and wonderful things. Drupal can also be used to provide Processing Sketches with a sophisticated backend capable of processing [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p><a href="http://www.drupal.org">Drupal</a> is a powerful open-source content management framework, whose core functionality is hugely extensible through the use of <a href="http://drupal.org/project/modules">contributed modules</a>, of which there are literally thousands! This allows you to do all sorts of weird and wonderful things.</p>
<p>Drupal can also be used to provide Processing Sketches with a sophisticated backend capable of processing and serving up data in many different ways. I frequently use it as part of my local development to perform batch processing tasks and the like, which can then be integrated in a sketch, for example.</p>
<p>The simple method outlined in this tutorial uses <a href="http://www.json.org/">JSON</a> &#8211; <em>a lightweight data interchange format </em>to demonstrate how Drupal can be used to provide a Processing Sketch with a list of images and titles by using just a few contributed modules. Emphasis is placed upon the <a href="http://drupal.org/project/views">Views</a> module, as this provides an incredibly powerful means of pulling data out of a database. It also introduces the <a href="http://drupal.org/project/cck">CCK</a> (Content Construction Kit) module, which allows users to define custom content types and assign fields to them; think geo-location data, profiles, pictures, text, and dates etc.</p>
<p>Some of the topics covered in this tutorial will show you how to:</p>
<ul>
<li>define custom content types and their associated fields using Drupal and the CCK module</li>
<li>generate cached image variants based on user-defined custom presets</li>
<li>construct database queries or <em>views</em> using the Views module &#8211; <em>a smart query builder</em></li>
<li>output views in both HTML and JSON</li>
<li>access and display a view&#8217;s results in Processing</li>
</ul>
<h2>Drupal</h2>
<h3>Installation</h3>
<p><span style="font-weight: normal; font-size: 13px;"><a href="http://drupal.org/node/628292">Here</a> you&#8217;ll find instructions on how to download, install, and configure the latest version of Drupal for your particular development environment. <a href="http://www.mamp.info/en/index.html">MAMP</a> and variants such as LAMP (the M and the L refer to Mac and Linux respectively) offer a contained and relatively foolproof Apache Server, MySql, and PHP stack for whatever platform you happen to be using; this is all that is required to host and run Drupal. Personally, I use MAMP on a Mac. </span>I usually install Drupal in a sub-folder to help keep things organized; decompressing Drupal into your public_html folder and renaming it to <em>processing</em> or whatever is the easiest way to achieve this.</p>
<p>Drupal has a very active and supportive community. Google or search the forums if you&#8217;re having difficulties getting up and running with Drupal. If you&#8217;ve ever installed WordPress (who hasn&#8217;t!?) you shouldn&#8217;t have too much difficulty.</p>
<blockquote><p><strong>Please note</strong> that this tutorial assumes that you are using <a href="http://drupal.org/">Drupal 6.17</a>. Version 7 is nearing release, but is not production ready at the time of posting.</p></blockquote>
<p>Once you&#8217;ve run the install script and told Drupal all about your database and filled out all the configuration settings you&#8217;ll be redirected to the welcome page:</p>
<p><a rel="attachment wp-att-100" href="http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/screen-shot-2010-07-15-at-12-25-37-3/"><img class="alignnone size-full wp-image-100" title="Drupal Welcome Screen" src="http://www.mark-hill.co.uk/blog/wp-content/uploads/2010/07/Screen-shot-2010-07-15-at-12.25.372.png" alt="" width="564" height="361" /></a></p>
<p><strong>Modules</strong></p>
<p>The next thing to do is download the following Drupal contrib modules to your modules directory:</p>
<ul>
<li><a href="http://drupal.org/project/admin_menu">admin_menu</a> (6.x-3.x-dev)</li>
<li><a href="http://drupal.org/project/cck">cck</a> (6.x-3.x)</li>
<li><a href="http://drupal.org/project/devel">devel</a> (6.x-1.20)</li>
<li><a href="http://drupal.org/project/filefield">filefield</a> (6.x-3.7)</li>
<li><a href="http://drupal.org/project/imageapi">imageapi</a> (6.x-1.8)<a href="http://drupal.org/project/filefield"></a></li>
<li><a href="http://drupal.org/project/imagecache">imagecache</a> (6.x-2.0-beta10)</li>
<li><a href="http://drupal.org/project/imagefield">imagefield</a> (6.x-3.7)</li>
<li><a href="http://drupal.org/project/views">views</a> (6.x-2.11)</li>
<li><a href="http://drupal.org/project/views_datasource">views_datasource</a> (6.x-1.x-dev)</li>
</ul>
<blockquote><p><strong>Note: </strong>You will need to create a directory called modules in your /drupal/sites/all folder as this does not exist by default.</p></blockquote>
<p><strong>Avoid</strong> placing contributed modules in the /drupal_folder/modules folder, as this is where Drupal&#8217;s default core modules live. This image shows my /drupal_folder/sites/all/modules folder with all the above modules decompressed inside it.</p>
<p><a rel="attachment wp-att-107" href="http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/screen-shot-2010-07-15-at-12-46-41/"><img class="alignnone size-full wp-image-107" title="Modules Directory" src="http://www.mark-hill.co.uk/blog/wp-content/uploads/2010/07/Screen-shot-2010-07-15-at-12.46.41.png" alt="" width="454" height="398" /></a></p>
<p>Now navigate to drupal_folder/admin/build/modules to see the list of all available modules (the downloaded modules will also appear in this list), and ensure the following are enabled:</p>
<p><a rel="attachment wp-att-121" href="http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/modules/"><img class="alignnone size-full wp-image-121" title="Module List" src="http://www.mark-hill.co.uk/blog/wp-content/uploads/2010/07/Modules.png" alt="" width="564" height="1270" /></a></p>
<p>A new black toolbar should have appeared at the top of the screen. This makes finding things in Drupal a whole lot quicker and easier, and avoids countless page refreshes when drilling down through menus. The rest of this tutorial assumes that you have this toolbar working.</p>
<h3>CCK</h3>
<p><strong>Step 1 &#8211; Create new content type</strong></p>
<p>First we need a new content type to store our images.</p>
<p><span style="font-weight: normal;"><em><span style="font-style: normal;">Select</span><strong> &#8216;</strong>Content management &gt; Content types &gt; Add content type&#8217; </em>from the toolbar. This should present a form with various fields in groups, which need to be filled out. Many of them can be left with default settings. The following lists only those groups of fields that need to be altered in some way:</span></p>
<ul>
<li><strong>Identification:</strong>
<ul>
<li><strong>Name:</strong><span style="font-weight: normal;"> Image</span></li>
<li><span style="font-weight: normal;"> </span><strong>Type:</strong><span style="font-weight: normal;"> image</span></li>
</ul>
</li>
<li><strong>Submission form settings:</strong>
<ul>
<li><strong>Body field label:</strong><span style="font-weight: normal;"> delete the word &#8216;Body&#8217; already in this field, so that it is blank (we don&#8217;t need body text in this example)</span></li>
</ul>
</li>
<li><strong>Comment settings:</strong>
<ul>
<li><strong>Default comment setting:</strong><span style="font-weight: normal;"> disabled (we don&#8217;t need the commenting system)</span></li>
</ul>
</li>
</ul>
<p>Submitting the form should result in a redirect to a list of available content types including the one we just created with the following green success message at the top: <span style="color: #008000;">The content type </span><em><span style="color: #008000;">Image</span></em><span style="color: #008000;"> has been added.</span></p>
<h4>Step 2 &#8211; Add image field to Image content type</h4>
<p>At this stage our newly created content type only stores a title, and a few other items of information relating to authorship etc. To upload and store images we will need to add an image field to this content type.</p>
<p>First <em><span style="color: #000000;"><span style="font-style: normal;">click on the</span> &#8216;manage fields&#8217; <span style="font-style: normal;">link</span></span></em> to the right of your newly created content type, and then fill out the form as shown below:</p>
<h3><a rel="attachment wp-att-142" href="http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/screen-shot-2010-07-16-at-09-26-20/"><img class="alignnone size-full wp-image-142" title="Add Image Field" src="http://www.mark-hill.co.uk/blog/wp-content/uploads/2010/07/Screen-shot-2010-07-16-at-09.26.20.png" alt="" width="564" height="268" /></a></h3>
<p>The next screen presents another form with lots of fieldgroups affecting the behaviour of this field. The only change we need to make is to make our new field required* under Global settings near the bottom of the form.</p>
<p>Although for this tutorial you can submit the form with the default settings, take a look at some of the other options for future reference.</p>
<h3>ImageCache</h3>
<ol>
<li>Navigate to &#8216;<em>Imagecache&#8217;</em> under &#8216;<em>Site building</em>&#8216; menu</li>
<li>Add new preset called &#8216;thumbnail&#8217;</li>
<li>Add a resize action of 75&#215;75 pixels by entering 75 and 75 into width and height fields respectively</li>
<li>Save preset</li>
</ol>
<p>A Drupal icon appears at the bottom of the screen providing a demo of how your new preset will affect images.</p>
<h3>Devel</h3>
<p>Among other things the devel module provides a convenient way to generate dummy or test content for a site, including images.</p>
<ol>
<li>Click on &#8216;<em>Generate items &gt; Generate content</em>&#8216; link in the toolbar</li>
<li>In &#8216;Which node types do you want to create?&#8217; check that Image is the only type selected</li>
<li>Change &#8216;Max word length of titles&#8217; to 1 (default of 8 is excessive)</li>
<li>Do it!</li>
</ol>
<p>You should get a progress bar indicating that the action is being performed before returning to the Generate content page with a list of new nodes created and a total of how many were created (default 50).</p>
<p>If you  click on the &#8216;<em>home&#8217;</em> link in the breadcrumb trail you should see a paginated list of your newly created images, which can be clicked and viewed, or edited individually. <strong>Note: </strong>If you click on a nodes &#8216;<em>edit</em>&#8216; tab you&#8217;ll see the form used to create nodes of this type when doing it manually, i.e. by clicking &#8216;<em>Create content</em>&#8216; in the left-hand navigation block and choosing &#8216;<em>Image</em>&#8216;; do this when you want to name and upload your own custom images, rather than have them automatically generated by the Devel module.</p>
<h3>Views</h3>
<p>Although our home page displays all of our newly created content it is insufficient for our purposes, as by default it displays the teaser for any new content added to the system in reverse chronological order regardless of its type, i.e. anything with the promote to front page flag set as part of its workflow.</p>
<p>Views is the module that will allow us to be much more selective in the construction of a new page.</p>
<ol>
<li>&#8216;<em>Site building &gt; Views</em>&#8216; brings up a page of available views -<em> all of which are disabled by default</em></li>
<li>Now there are two options on how to proceed:
<ol>
<li>Click the &#8216;<em>Add</em>&#8216; tab and name the view<em> images </em>and click &#8216;<em>Next</em>&#8216; leaving all other settings as defaults, and proceed with the configuration of the view by hand beginning at the <strong>Filters </strong>section directly below, or</li>
<li>Copy my exported view code and click on the &#8216;<em>import</em>&#8216; tab to avoid the configuring the view by hand. If you choose the latter option just paste in the code and progress directly to the Processing section of this tutorial, but check the imported view gives you a new menu item called &#8216;<em>Images</em>&#8216; at the top right-hand side of the screen and that the view includes the <em>default</em> and <em>json</em> tabs</li>
</ol>
</li>
</ol>
<pre class="brush: php;">
$view = new view;
$view-&gt;name = 'images';
$view-&gt;description = '';
$view-&gt;tag = '';
$view-&gt;view_php = '';
$view-&gt;base_table = 'node';
$view-&gt;is_cacheable = FALSE;
$view-&gt;api_version = 2;
$view-&gt;disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view-&gt;new_display('default', 'Defaults', 'default');
$handler-&gt;override_option('fields', array(
  'title' =&gt; array(
    'label' =&gt; 'Title',
    'alter' =&gt; array(
      'alter_text' =&gt; 0,
      'text' =&gt; '',
      'make_link' =&gt; 0,
      'path' =&gt; '',
      'link_class' =&gt; '',
      'alt' =&gt; '',
      'prefix' =&gt; '',
      'suffix' =&gt; '',
      'target' =&gt; '',
      'help' =&gt; '',
      'trim' =&gt; 0,
      'max_length' =&gt; '',
      'word_boundary' =&gt; 1,
      'ellipsis' =&gt; 1,
      'html' =&gt; 0,
      'strip_tags' =&gt; 0,
    ),
    'empty' =&gt; '',
    'hide_empty' =&gt; 0,
    'empty_zero' =&gt; 0,
    'link_to_node' =&gt; 0,
    'exclude' =&gt; 0,
    'id' =&gt; 'title',
    'table' =&gt; 'node',
    'field' =&gt; 'title',
    'relationship' =&gt; 'none',
  ),
  'field_image_fid' =&gt; array(
    'label' =&gt; '',
    'alter' =&gt; array(
      'alter_text' =&gt; 0,
      'text' =&gt; '',
      'make_link' =&gt; 0,
      'path' =&gt; '',
      'link_class' =&gt; '',
      'alt' =&gt; '',
      'prefix' =&gt; '',
      'suffix' =&gt; '',
      'target' =&gt; '',
      'help' =&gt; '',
      'trim' =&gt; 0,
      'max_length' =&gt; '',
      'word_boundary' =&gt; 1,
      'ellipsis' =&gt; 1,
      'html' =&gt; 0,
      'strip_tags' =&gt; 0,
    ),
    'empty' =&gt; '',
    'hide_empty' =&gt; 0,
    'empty_zero' =&gt; 0,
    'link_to_node' =&gt; 0,
    'label_type' =&gt; 'none',
    'format' =&gt; 'thumbnail_default',
    'multiple' =&gt; array(
      'group' =&gt; TRUE,
      'multiple_number' =&gt; '',
      'multiple_from' =&gt; '',
      'multiple_reversed' =&gt; FALSE,
    ),
    'exclude' =&gt; 0,
    'id' =&gt; 'field_image_fid',
    'table' =&gt; 'node_data_field_image',
    'field' =&gt; 'field_image_fid',
    'relationship' =&gt; 'none',
    'override' =&gt; array(
      'button' =&gt; 'Override',
    ),
  ),
));
$handler-&gt;override_option('filters', array(
  'status' =&gt; array(
    'operator' =&gt; '=',
    'value' =&gt; '1',
    'group' =&gt; '0',
    'exposed' =&gt; FALSE,
    'expose' =&gt; array(
      'operator' =&gt; FALSE,
      'label' =&gt; '',
    ),
    'id' =&gt; 'status',
    'table' =&gt; 'node',
    'field' =&gt; 'status',
    'relationship' =&gt; 'none',
  ),
  'type' =&gt; array(
    'operator' =&gt; 'in',
    'value' =&gt; array(
      'image' =&gt; 'image',
    ),
    'group' =&gt; '0',
    'exposed' =&gt; FALSE,
    'expose' =&gt; array(
      'operator' =&gt; FALSE,
      'label' =&gt; '',
    ),
    'id' =&gt; 'type',
    'table' =&gt; 'node',
    'field' =&gt; 'type',
    'relationship' =&gt; 'none',
  ),
));
$handler-&gt;override_option('access', array(
  'type' =&gt; 'none',
));
$handler-&gt;override_option('cache', array(
  'type' =&gt; 'none',
));
$handler = $view-&gt;new_display('page', 'Page', 'page_1');
$handler-&gt;override_option('path', 'images/default');
$handler-&gt;override_option('menu', array(
  'type' =&gt; 'default tab',
  'title' =&gt; 'default',
  'description' =&gt; '',
  'weight' =&gt; '0',
  'name' =&gt; 'navigation',
));
$handler-&gt;override_option('tab_options', array(
  'type' =&gt; 'normal',
  'title' =&gt; 'Images',
  'description' =&gt; '',
  'weight' =&gt; '0',
  'name' =&gt; 'primary-links',
));
$handler = $view-&gt;new_display('page', 'JSON', 'page_2');
$handler-&gt;override_option('fields', array(
  'title' =&gt; array(
    'label' =&gt; 'title',
    'alter' =&gt; array(
      'alter_text' =&gt; 0,
      'text' =&gt; '',
      'make_link' =&gt; 0,
      'path' =&gt; '',
      'link_class' =&gt; '',
      'alt' =&gt; '',
      'prefix' =&gt; '',
      'suffix' =&gt; '',
      'target' =&gt; '',
      'help' =&gt; '',
      'trim' =&gt; 0,
      'max_length' =&gt; '',
      'word_boundary' =&gt; 1,
      'ellipsis' =&gt; 1,
      'html' =&gt; 0,
      'strip_tags' =&gt; 0,
    ),
    'empty' =&gt; '',
    'hide_empty' =&gt; 0,
    'empty_zero' =&gt; 0,
    'link_to_node' =&gt; 0,
    'exclude' =&gt; 0,
    'id' =&gt; 'title',
    'table' =&gt; 'node',
    'field' =&gt; 'title',
    'relationship' =&gt; 'none',
    'override' =&gt; array(
      'button' =&gt; 'Use default',
    ),
  ),
  'field_image_fid' =&gt; array(
    'label' =&gt; 'thumbnail',
    'alter' =&gt; array(
      'alter_text' =&gt; 0,
      'text' =&gt; '',
      'make_link' =&gt; 0,
      'path' =&gt; '',
      'link_class' =&gt; '',
      'alt' =&gt; '',
      'prefix' =&gt; '',
      'suffix' =&gt; '',
      'target' =&gt; '',
      'help' =&gt; '',
      'trim' =&gt; 0,
      'max_length' =&gt; '',
      'word_boundary' =&gt; 1,
      'ellipsis' =&gt; 1,
      'html' =&gt; 0,
      'strip_tags' =&gt; 0,
    ),
    'empty' =&gt; '',
    'hide_empty' =&gt; 0,
    'empty_zero' =&gt; 0,
    'link_to_node' =&gt; 0,
    'label_type' =&gt; 'custom',
    'format' =&gt; 'thumbnail_url',
    'multiple' =&gt; array(
      'group' =&gt; TRUE,
      'multiple_number' =&gt; '',
      'multiple_from' =&gt; '',
      'multiple_reversed' =&gt; FALSE,
    ),
    'exclude' =&gt; 0,
    'id' =&gt; 'field_image_fid',
    'table' =&gt; 'node_data_field_image',
    'field' =&gt; 'field_image_fid',
    'relationship' =&gt; 'none',
    'override' =&gt; array(
      'button' =&gt; 'Use default',
    ),
  ),
));
$handler-&gt;override_option('style_plugin', 'views_json');
$handler-&gt;override_option('style_options', array(
  'root_object' =&gt; 'nodes',
  'top_child_object' =&gt; 'node',
  'field_output' =&gt; 'normal',
  'plaintext_output' =&gt; 1,
  'format' =&gt; 'simple',
  'content_type' =&gt; 'default',
  'using_views_api_mode' =&gt; 0,
));
$handler-&gt;override_option('path', 'images/json');
$handler-&gt;override_option('menu', array(
  'type' =&gt; 'tab',
  'title' =&gt; 'json',
  'description' =&gt; '',
  'weight' =&gt; '0',
  'name' =&gt; 'navigation',
));
$handler-&gt;override_option('tab_options', array(
  'type' =&gt; 'none',
  'title' =&gt; '',
  'description' =&gt; '',
  'weight' =&gt; 0,
  'name' =&gt; 'navigation',
));
</pre>
<p><strong>Filters</strong></p>
<p>Click the + symbol next to &#8216;filters&#8217; and locate the following two filter types and set them accordingly:</p>
<ul>
<li><strong>Node: Published:</strong> yes (as a precaution we don&#8217;t want to display content that isn&#8217;t ready)</li>
<li><strong>Node: Type:</strong> is one of Image type</li>
</ul>
<p><strong>Fields</strong></p>
<p>Click the  + symbol next to &#8216;fields&#8217; and select the following two fields from the list and configure them as follows:</p>
<ul>
<li><strong>Node: Title: </strong>default settings</li>
<li><strong>Content: Image: </strong>leave default settings, but change format* to &#8216;<em>thumbnail image</em>&#8216; and label to &#8216;<em>none</em>&#8216;</li>
</ul>
<p>When you start adding fields to your view you&#8217;ll notice that the views module provides a live preview at the bottom of the page, to give you an overall impression of what the final view will look like. Notice what happens when you change the image <strong>format*</strong> to generic files, or some other setting.</p>
<p><strong>Displays</strong></p>
<p>You should now have a view that looks similar to this:</p>
<p><a rel="attachment wp-att-150" href="http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/screen-shot-2010-07-16-at-10-56-39/"><img class="alignnone size-full wp-image-150" title="Default Images View" src="http://www.mark-hill.co.uk/blog/wp-content/uploads/2010/07/Screen-shot-2010-07-16-at-10.56.39.png" alt="" width="564" height="364" /></a></p>
<p>At this stage we&#8217;ve only setup a few defaults for our view and it is not accessible as a page via a URL until we add a display.</p>
<p><strong>Pages</strong></p>
<ul>
<li>Click &#8216;<em>Add display</em>&#8216; from the left hand panel while ensuring that &#8216;<em>Page</em>&#8216; is the selected item in the drop down list</li>
</ul>
<p>A new section called <strong>Page settings </strong>will have appeared below <strong>Basic settings. </strong>This will allow us to assign a URL and menu item to this view.</p>
<ul>
<li>Click &#8216;<em>Path&#8217;</em> and enter <em>images/default </em>as our preferred URL</li>
<li>Click &#8216;<em>Menu&#8217; </em>and choose &#8216;Default menu tab&#8217; and enter <em>default</em> as the Title</li>
<li>In &#8216;<em>Default tab options</em>&#8216; choose &#8216;<em>Normal menu item</em>&#8216; and set its title to: <em>Images</em> and select &#8216;<em>Primary links</em>&#8216; from the Menu options list.</li>
</ul>
<p>If you now save the view you should see a new menu item &#8216;<em>Images</em>&#8216; appear on the top right-hand side of the screen. Clicking on this link will take you to /drupal_folder/images where you should see the results of our view displayed. Return to the view editing page either by choosing the &#8216;<em>Site building &gt; Views</em>&#8216; link, or by hovering near the top of our view until an &#8216;<em>edit</em>&#8216; link appears.</p>
<p><strong>JSON</strong></p>
<p>Now it&#8217;s time to get the contents of our view as a JSON document.</p>
<ul>
<li>Click &#8216;<em>Add display</em>&#8216; with &#8216;<em>Page</em>&#8216; selected as before</li>
<li>Under <strong>Basic settings:</strong>
<ul>
<li><strong>Name:</strong> to &#8216;JSON&#8217;</li>
<li><strong>Style:</strong> click &#8216;<em>override</em>&#8216; to avoid affecting the default settings (<strong>!Important</strong>), and then choose &#8216;<em>JSON data document</em>&#8216; as the style. On the following screen you can submit the defaults.</li>
</ul>
</li>
<li><strong>Page settings:</strong>
<ul>
<li>Click &#8216;<em>Path</em>&#8216; and enter <em>images/json</em> as our preferred URL</li>
<li>Click &#8216;<em>Menu</em>&#8216; and choose &#8216;<em>Menu tab</em>&#8216; and enter <em>json</em> as the title</li>
</ul>
</li>
</ul>
<p>If you update and save the view you should be taken to the completed view, which should now have two tabs entitled: <em>default</em>, and <em>json. </em>If you click &#8216;<em>json</em>&#8216; your browser should present you with a JSON representation of the view.</p>
<p>The final thing to do is ensure that our fields are labelled sensibly, as this affects the JSON output by the views_datasource module.</p>
<ul>
<li>Ensure that <em>JSON</em> is our selected display in the view editor, and then click &#8216;<em>Fields</em>&#8216;</li>
<li><strong>Fields:</strong>
<ul>
<li><strong>Node: Title: </strong>Click override if not already using overridden values and enter: <em>title </em>(lowercase)</li>
<li><strong>Content: Image: </strong>Again, double check that status is &#8216;using overridden values&#8217;, and then choose custom label option and enter: <em>thumbnail, </em>and finally choose &#8216;thumbnail url&#8217; from the format* select list</li>
</ul>
</li>
</ul>
<p>Update and save the view and check the first line of json output has the correct labels, something like:</p>
<pre class="brush: plain;">{&quot;nodes&quot;:[{&quot;node&quot;:{&quot;title&quot;:&quot;Caecus&quot;,&quot;thumbnail&quot;:&quot;http:\/\/localhost\/processing\/sites\/default\/files\/imagecache\/thumbnail\/filefield_1b265U_2_5.jpg&quot;}}</pre>
<h2><strong>Processing</strong></h2>
<p>Now that Drupal is setup and running it's time to fire up <a href="http://www.processing.org">Processing</a>!</p>
<p><strong>Json</strong></p>
<p>Jer Thorp aka <a href="http://www.blprnt.com">blprnt</a> has kindly posted a processing <a href="http://www.blprnt.com/processing/json.zip">library</a> along with a really useful <a href="http://blog.blprnt.com/blog/blprnt/processing-json-the-new-york-times">introduction to using JSON within Processing</a>, which you should read. Also, grab a copy of his library and stick it in the usual place.</p>
<p>All you need to do now is copy this code into an empty sketch and fill in the URL of your JSON data document in the 'request' string. If you get an parsing errors, try uncommenting some of the println statements and examine the JSON String being returned, and ensure that the keys used as arguments to getJSON* match the labels returned by your JSON view.</p>
<p><strong>Sketch</strong></p>
<pre class="brush: java;">
import org.json.*;

ImageNode[] nodes;

PFont font;

void setup() {
  size(455, 245);

  font = createFont(&quot;SansSerif&quot;, 11);
  textFont(font);
  textAlign(CENTER);

  String request = &quot;http://localhost/processing/images/json&quot;;
  String result = join( loadStrings( request ), &quot;&quot;);

  try {
    JSONObject json_view = new JSONObject(join(loadStrings(request), &quot;&quot;));
    //println(json_view.toString(2));

    JSONArray json_nodes = json_view.getJSONArray(&quot;nodes&quot;);

    nodes = new ImageNode[json_nodes.length()];
    //println(&quot;json nodes: &quot; + json_nodes.toString(2) );

    for (int i = 0; i &lt; json_nodes.length(); i++) {
      //println(json_nodes.get(i));
      JSONObject json_node = (JSONObject)json_nodes.get(i);
      json_node = json_node.getJSONObject(&quot;node&quot;);

      String title = json_node.getString(&quot;title&quot;);
      String imageUrl = json_node.getString(&quot;thumbnail&quot;);
      //println(title + &quot;: &quot; + imageUrl);
      PImage thumbnail = loadImage(imageUrl);
      nodes[i] = new ImageNode(title, thumbnail);
    }
  }
  catch (JSONException e) {
    println (&quot;There was an error parsing the JSONObject.&quot;);
  };
}

void draw() {
  background(72);

  int x=20;
  int y=20;
  fill(255);

  for(int i = 0; i &lt; nodes.length; i++) {
    ImageNode node = nodes[i];
    image(node.thumbnail(), x, y);
    text(node.title(), x+75/2, y+90);

    x+=85;
    if(x &gt; width-85) {
      x=20;
      y+=105;
    }
  }
}

// Simple container class
class ImageNode {
  String title;
  PImage thumbnail;

  ImageNode(String title, PImage thumbnail) {

    this.title = title;
    this.thumbnail = thumbnail;
  }

  String title() {
    return this.title;
  }

  PImage thumbnail() {
    return this.thumbnail;
  }
}
</pre>
<h2><strong>Result</strong></h2>
<p>When you run the above sketch you should see something like this:</p>
<p><a rel="attachment wp-att-165" href="http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/screen-shot-2010-07-16-at-12-54-38/"><img class="alignnone size-full wp-image-165" title="Processing, Drupal, and JSON Result" src="http://www.mark-hill.co.uk/blog/wp-content/uploads/2010/07/Screen-shot-2010-07-16-at-12.54.38.png" alt="" width="457" height="269" /></a></p>
<p>And if you don&#8217;t?</p>
<p>Double check that your view is properly setup, and that your Processing sketch is configured with the right URL and that the keys match the labels being used in the view. Finally, leave a comment below and I&#8217;ll try and help you troubleshoot it.</p>
<p>If I&#8217;ve made any errors in this post (yikes!), or it doesn&#8217;t make any sense let me know and I&#8217;ll try and make the necessary amendments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mark-hill.co.uk/blog/2010/07/16/processing-drupal-and-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
