<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
	<channel>
		<title>Vormplus - Full Articles</title>
		<link>http://vormplus.be/</link>
		<description>The personal blog of Jan Vantomme</description>
		<pubDate>Mon, 21 Jun 2010 05:27:34 GMT</pubDate>
		
		
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/vormplus-fullarticles" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="vormplus-fullarticles" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
			<title>Exploring the Hemesh WB_Render Class</title>
			<link>http://vormplus.be/blog/article/exploring-the-hemesh-wb-render-class</link>
			<pubDate>Thu, 11 Aug 2011 20:25:51 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/exploring-the-hemesh-wb-render-class</guid>
			<description><![CDATA[	<p>Hemesh has changed a lot since the last tutorials I wrote about <a href="http://vormplus.be/blog/article/creating-3d-shapes-with-hemesh">Creating Shapes</a>, <a href="http://vormplus.be/blog/article/modifying-a-mesh-with-hemesh">Modifying a Mesh</a> and <a href="http://vormplus.be/blog/article/subdividing-a-mesh-with-hemesh">Subdividing a Mesh</a>. The examples in these articles don&#8217;t work with the latest version of the libary. In the previous version, you needed to render your mesh to the screen using <code>mesh.drawFaces()</code>, in the latest version, the new WB_Render class does all the hard work. To use the class, you need to declare a WB_Render object and create it in <code>setup()</code>. This is the code you need to get started.</p>

<pre><code>WB_Render render;
HE_Mesh mesh;
void setup()
&#123;
    size(450, 400);
    HEC_Geodesic geo = new HEC_Geodesic(60, 1);
    mesh = new HE_Mesh( geo );
    render = new WB_Render( this );
&#125;
</code></pre>

	<p>All the code to render the mesh to the screen goes inside <code>draw()</code>. This is a list with the descriptions of the most important methods for the WB_Render class. I&#8217;ve used them all to create the image below.</p>

	<ul>
		<li><code>render.drawFaces( mesh )</code> &#8211; Draw the faces of the mesh object. You&#8217;ll normally use this with <code>fill()</code> and <code>noStroke()</code>.</li>
		<li><code>render.drawFacesSmooth( mesh )</code> &#8211; Draw the faces using the vertex normals. This is a great method if you need to render a really smooth organic shape. You&#8217;ll normally use this with <code>fill()</code> and <code>noStroke()</code>.</li>
		<li><code>render.drawFaceNormals( 20, mesh )</code> &#8211; Draw the face normals of the mesh. The first parameter is the length of the normal. You&#8217;ll normally use this with <code>noFill()</code> and <code>stroke()</code>. This is a useful method for debugging.</li>
		<li><code>render.drawEdges( mesh )</code> &#8211; Draw the edges of the mesh. You&#8217;ll normally use this with <code>noFill()</code> and <code>stroke()</code>.</li>
		<li><code>render.drawVertices( 10, mesh )</code> &#8211; Draw the vertices of the mesh, a useful method for debugging if you want to create your own meshes from scratch. The vertices are rendered as cubes, the first parameter sets the size for these cubes. You&#8217;ll normally use this with <code>noFill()</code> and <code>stroke()</code>.</li>
		<li><code>render.drawHalfedges( 10, mesh )</code> &#8211; Draw the halfedges of the mesh, again a useful method for debugging. The vertices are rendered as cubes, the first parameter sets the size for these cubes.</li>
	</ul>

	<p><img src="http://img.vormplus.be/blog/hemesh-rendermodes.png" title="The different render modes from the WB_Render class in Hemesh" alt="The different render modes from the WB_Render class in Hemesh" /></p>

	<h2>Download</h2>

	<p>Download the <a href="http://img.vormplus.be/downloads/hemesh_rendermodes.zip">example</a> for rendering with the WB_Render class.</p>]]></description>
		</item>
		
		<item>
			<title>Paintbots</title>
			<link>http://vormplus.be/blog/article/paintbots</link>
			<pubDate>Tue, 09 Aug 2011 13:39:21 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/paintbots</guid>
			<description><![CDATA[	<p>My first iPad application &#8220;Paintbots&#8221; is now available in the <a href="http://itunes.apple.com/us/app/paintbots/id454058538?ls=1&amp;mt=8">App Store</a>. Paintbots was made with <a href="http://www.openframeworks.cc/">openFrameworks</a> and took me a while to finish, but I&#8217;m happy with the result. For the <a href="http://www.paintbots.com/">Paintbots website</a>, I&#8217;ve used HTML5 and CSS3 transitions and animations. Some screenshots and the promo video can be found below. Buy the app, have some fun and let me know what you think about it.</p>

	<p><img src="http://img.vormplus.be/news/paintbots-news-screenshot-001.png" title="Select a photo to create a digital painting with Paintbots." alt="Select a photo to create a digital painting with Paintbots." /></p>

	<p><img src="http://img.vormplus.be/news/paintbots-news-screenshot-002.png" title="These four robots will help you create a great digital painting with Paintbots." alt="These four robots will help you create a great digital painting with Paintbots." /></p>

	<p><img src="http://img.vormplus.be/news/paintbots-news-screenshot-003.png" title="Adjust the brush settings to create your digital painting with Paintbots." alt="Adjust the brush settings to create your digital painting with Paintbots." /></p>

	<p><iframe src="http://player.vimeo.com/video/27114213?title=0&amp;byline=0&amp;portrait=0&amp;color=f9e100" width="450" height="260"></iframe></p>]]></description>
		</item>
		
		<item>
			<title>Voronoi Paintings with Toxiclibs</title>
			<link>http://vormplus.be/blog/article/voronoi-paintings-with-toxiclibs</link>
			<pubDate>Thu, 28 Jul 2011 14:32:04 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/voronoi-paintings-with-toxiclibs</guid>
			<description><![CDATA[	<p>Every generative artist has probably created a work using Voronoi diagrams. I already wrote a tutorial on how to create them with <a href="http://vormplus.be/blog/article/creating-3d-voronoi-with-hemesh">Hemesh</a>. Today, we&#8217;ll take a look at how you can create 2D voronoi diagrams with the popular <a href="http://toxiclibs.org/">Toxiclibs</a> library for Processing. You can start by downloading and installing the library if you haven&#8217;t done that already. Import the library to your sketch and declare these two variables:</p>

<pre><code>ToxiclibsSupport gfx;
Voronoi voronoi;
</code></pre>

	<p>The next thing you&#8217;ll need to do is creating the ToxiclibsSupport object, which will be used to easily draw the voronoi regions to the screen and the Voronoi object that will hold the points. The full code for <code>setup()</code> will look like this:</p>

<pre><code>void setup()
&#123;
    size(450, 360);  
    gfx = new ToxiclibsSupport( this );
    voronoi = new Voronoi();  
    for ( int i = 0; i &lt; 50; i++ ) &#123;
        voronoi.addPoint( new Vec2D( random(width), random(height) ) );
    &#125;
&#125;
</code></pre>

	<p>To draw the voronoi diagram to the screen, you&#8217;ll need to use the <code>getRegions()</code> method on the voronoi object. This returns an ArrayList of Polygon2D objects. If you iterate through this ArrayList, you can draw each polygon to the screen using the <code>Polygon2D()</code> method on the ToxiclibsSupport object. This piece of code goes inside <code>draw()</code>.</p>

<pre><code>for ( Polygon2D polygon : voronoi.getRegions() ) &#123;
    gfx.polygon2D( polygon );
&#125;
</code></pre>

	<p>If all goes well, your image should look like the one below. The code for this sketch can be found in the folder <strong>voronoi001</strong>.</p>

	<p><img src="http://img.vormplus.be/blog/toxiclibs-voronoi-001.png" title="A Voronoi diagram made with Toxiclibs." alt="A Voronoi diagram made with Toxiclibs." /></p>

	<h2>Drawing Points</h2>

	<p>The easiest way to draw the points that make up the voronoi diagram is to use the <code>getSites()</code> method of the Voronoi class. This method returns an ArrayList of Vec2D objects that hold the location of each point. I&#8217;ve used green to render these points to the screen in the image below. The red points are rendered using the <code>getCentroid()</code> method of the Polygon2D class, which returns the polygon&#8217;s centre of mass. You can find the code for this example in the folder <strong>voronoi002</strong>.</p>

	<p><img src="http://img.vormplus.be/blog/toxiclibs-voronoi-002.png" title="A Voronoi diagram made with Toxiclibs, showing the points that make up the diagram." alt="A Voronoi diagram made with Toxiclibs, showing the points that make up the diagram." /></p>

	<h2>Creating a Painting</h2>

	<p>The next thing I did was stealing the image of <a href="http://en.wikipedia.org/wiki/Mona_Lisa">Mona Lisa</a> from Wikipedia so I could use it as a reference image to create the voronoi painting. The technique I used for picking the colors to fill the voronoi regions is the same as I&#8217;ve used in my tutorial on <a href="http://vormplus.be/blog/article/processing-month-day-11-painting-part-2">Painting with Processing</a>. The code for this sketch can be found in the folder <strong>voronoi_monalisa_001</strong>.</p>

	<p><img src="http://img.vormplus.be/blog/mona-lisa-voronoi-001.jpg" title="Mona Lisa, painted with a Voronoi diagram." alt="Mona Lisa, painted with a Voronoi diagram." /></p>

	<p>In the image above, I&#8217;ve used the <code>getCentroid()</code> method of the Polygon2D class to pick the color. This is the fastest way to create the painting, but it doesn&#8217;t use the points that make up the voronoi diagram. The centre of mass of the polygon is usually close to the voronoi point, as you can see in the image with the red and green dots, but they are not the same.</p>

	<p>The first thing I tried to use the colors below the real points is collecting them in an array using <code>voronoi.getSites()</code> before drawing the polygons to the screen using <code>voronoi.getRegions()</code>. The result wasn&#8217;t quite what I expected. The <code>getSites()</code> and <code>getRegions()</code> don&#8217;t return the voronoi regions and points in the same order. You can see the result in the image below, the code is available in the folder <strong>voronoi_monalisa_002</strong>. The second method I&#8217;ve tried was somewhat similar an can be found in the folder <strong>voronoi_monalisa_003</strong>.</p>

	<p><img src="http://img.vormplus.be/blog/mona-lisa-voronoi-002.jpg" title="Mona Lisa, painted with a Voronoi diagram." alt="Mona Lisa, painted with a Voronoi diagram." /></p>

	<p>The only way to use the real voronoi points is to use a nested loop that iterates over all regions and checks all points if they are inside the polygon. This might be ok if you only have 50 points, but the function gets really expensive if you use a few thousand points. But you get the best possible result, as you can see in the image below. The code for the final image can be found in the folder <strong>voronoi_monalisa_004</strong>.</p>

	<p><img src="http://img.vormplus.be/blog/mona-lisa-voronoi-003.jpg" title="Mona Lisa, painted with a Voronoi diagram." alt="Mona Lisa, painted with a Voronoi diagram." /></p>

	<h2>Download</h2>

	<p>The <a href="http://img.vormplus.be/downloads/toxiclibs-voronoi-paintings.zip">examples for this Toxiclibs tutorial</a> are available for download so you can create your own voronoi paintings. Have fun coding!</p>]]></description>
		</item>
		
		<item>
			<title>Kinetic Typography, Workshop Notes</title>
			<link>http://vormplus.be/blog/article/kinetic-typography-workshop-notes</link>
			<pubDate>Thu, 07 Jul 2011 14:01:51 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/kinetic-typography-workshop-notes</guid>
			<description><![CDATA[	<p>In this article, I&#8217;ll explain some techniques I use on a regular basis to create typographic experiments with Processing. The examples were used in the <a href="http://vormplus.be/blog/article/kinetic-typography-workshop-the-results">Kinetic Typography workshop</a> I did last year with my students in Brussels. The goal of this workshop is to visualize a word or phrase using Processing. Students need to choose a word, an appropriate typeface and use particles to animate that text.</p>

	<h2>The Basic Example</h2>

	<p>I usually start by creating a reference image with black and white pixels. This image contains the words I want to render on the screen. For performance, this image should be kept small. I generally use images of 192&#215;108 pixels. Renders of my sketch are High Definition video at 1920&#215;1080 pixels. Each pixel in the reference image stands for an area of 10 &#215; 10 pixels in the final image.</p>

	<p>In the basic example, I created an image with the word &#8220;<span class="caps">BUBBLES</span>&#8221;. The particles move from the bottom of the screen to the top. The size of the particles is set by the speed of the velocity vector. The bigger the particles are, the faster they go to the top. This is an easy trick to create a sense of depth without using 3D. The update() method in the Bubble class checks if in which 10 &#215; 10 area of pixels the location vector is, and maps it to the pixel in the reference image. If that pixel is black, the bubble grows and is filled. If the pixel is white, the bubble is rendered as an outline. The video below shows what the final sketch will look like.</p>

	<p><iframe src="http://player.vimeo.com/video/26076852?title=0&amp;byline=0&amp;portrait=0" width="462" height="260"></iframe></p>

	<p>If you want to know a little more about how the Bubbles class, I suggest you to read these articles I wrote during my Processing Month.</p>

	<ul>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-7-bubbles">Day 7 &#8211; Bubbles</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-8-animating-bubbles">Day 8 &#8211; Animating Bubbles</a></li>
	</ul>

	<h2>The Advanced Example</h2>

	<p>Rendering the sketch from an image is somewhat limited. You always need to go back to Photoshop or another image editor if you want to render another text. In the advanced example, I&#8217;ve used the <a href="http://www.sojamo.de/libraries/controlP5/">ControlP5 library</a> by Andreas Schlegel to create a small interface so I can easily interact with the sketch. The finished interface looks like this:</p>

	<p><img src="http://img.vormplus.be/blog/controlp5-interface-processing.jpg" title="The finished interface made with the ControlP5 Processing library" alt="The finished interface made with the ControlP5 Processing library" /></p>

	<p>The reference image is rendered on the fly when you enter text into the textfield. I&#8217;m using a PGraphics object to do this. The code for rendering text on a PGraphics object looks a lot like what you would normally do in Processing, but with the name of the object in front of every function. This is the code I&#8217;ve used to create my object.</p>

<pre><code>void generateReference()
&#123;
    reference.beginDraw();
    reference.noStroke();
    reference.background( 255 );
    reference.fill( 0 );
    reference.textAlign( CENTER );
    reference.textFont( font, 48 );
    reference.text( theText, 96, 70 );
    reference.endDraw();
&#125;
</code></pre>

	<p>In the basic example, you needed to press keys to save an image or movie. In the advanced example, you can use the buttons on the interface. Be sure that you hide the reference image when you save files, otherwise it will be visible.</p>

	<h2>Downloads</h2>

	<p><a href="http://img.vormplus.be/downloads/kinetic-typography-with-processing.zip">Download the examples</a> and start doing some typographic experiments with Processing. Have fun!</p>]]></description>
		</item>
		
		<item>
			<title>Kinetic Typography Workshop - The Results</title>
			<link>http://vormplus.be/blog/article/kinetic-typography-workshop-the-results</link>
			<pubDate>Thu, 23 Jun 2011 22:42:07 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/kinetic-typography-workshop-the-results</guid>
			<description><![CDATA[	<p>I did a Processing workshop about Kinetic Typography with some of my students in Brussels last year, and I somehow forgot to post the results. So here they are. The students participating in this workshop had never programmed before. I&#8217;m quite happy with the quality of the work they made in just over 20 hours.</p>

	<h2><span class="caps">FUCKU</span>/LOVEU by Nena Driehuijzen</h2>

	<p><iframe src="http://player.vimeo.com/video/18892086?title=0&amp;byline=0&amp;portrait=0" width="450" height="260"></iframe></p>

	<h2>The Birds, The Bees by Stefan Corthals</h2>

	<p><iframe src="http://player.vimeo.com/video/18881280?title=0&amp;byline=0&amp;portrait=0" width="450" height="260"></iframe></p>

	<h2>The Fish is Gone by Tom Vanhooreweder</h2>

	<p><iframe src="http://player.vimeo.com/video/18917244?title=0&amp;byline=0&amp;portrait=0" width="450" height="260"></iframe></p>

	<h2>Shine by René Rieger</h2>

	<p><iframe src="http://player.vimeo.com/video/18934775?title=0&amp;byline=0&amp;portrait=0" width="450" height="260"></iframe></p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, The Overview</title>
			<link>http://vormplus.be/blog/article/processing-month-the-overview</link>
			<pubDate>Wed, 01 Jun 2011 13:00:47 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-the-overview</guid>
			<description><![CDATA[	<p>Processing Month is over, and it was great. I got a lot of great response on Twitter, via email and on the blog. I&#8217;d like to thank <a href="http://twitter.com/mariuswatz/">Marius Watz</a> and <a href="http://twitter.com/reas/">Casey Reas</a> for mentioning Processing Month on Twitter. I&#8217;d also like to thank <a href="http://www.theliztaylor.com/blog/2011/05/may-is-processing-month-day-1/">Liz Taylor</a>, <a href="http://rasterweb.net/raster/2011/05/03/processing-overlapping-ovals/">Pete Prodoehl</a> and <a href="http://ibowman.loni.ucla.edu/">Ian Bowman</a> for trying to do a Procesing Month.</p>

	<h2>The Articles</h2>

	<p>This post will make it easy for you to get an overview of Processing Month. Here are the links to all articles.</p>

	<ul>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-1-connecting-points-part-1">Day 1 &#8211; Connecting Points, Part 1</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-2-connecting-points-part-2">Day 2 &#8211; Connecting Points, Part 2</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-3-triangle-grids">Day 3 &#8211; Triangle Grids</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-4-stars">Day 4 &#8211; Stars</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-5-square-flowers-part-1">Day 5 &#8211; Square Flowers, Part 1</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-6-square-flowers-part-2">Day 6 &#8211; Square Flowers, Part 2</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-7-bubbles">Day 7 &#8211; Bubbles</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-8-animating-bubbles">Day 8 &#8211; Animating Bubbles</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-9-circular-pixels">Day 9 &#8211; Circular Pixels</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-10-painting-part-1">Day 10 &#8211; Painting, Part 1</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-11-painting-part-2">Day 11 &#8211; Painting, Part 2</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-12-painting-part-3">Day 12 &#8211; Painting, Part 3</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-13-regular-polygons">Day 13 &#8211; Regular Polygons</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-14-manipulating-circles">Day 14 &#8211; Manipulating Circles</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-15-rounded-rectangles">Day 15 &#8211; Rounded Rectangles</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-16-building-a-spaceship">Day 16 &#8211; Building a Spaceship</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-17-falling-asteroids">Day 17 &#8211; Falling Asteroids</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-18-finishing-the-game">Day 18 &#8211; Finishing the Game</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-19-exporting-pdf-files-for-lasercutting">Day 19 &#8211; Exporting <span class="caps">PDF</span> Files for Lasercutting</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-20-optimize-your-workflow-with-processing-tools">Day 20 &#8211; Optimize your Workflow with Processing Tools</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-21-fitting-rectangles">Day 21 &#8211; Fitting Rectangles</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-22-patterns">Day 22 &#8211; Patterns</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-23-client-server-part-1">Day 23 &#8211; Client/Server Part 1</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-24-client-server-part-2">Day 24 &#8211; Client/Server Part 2</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-25-circular-bar-charts">Day 25 &#8211; Circular Bar Charts</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-26-data-visualisation">Day 26 &#8211; Data Visualisation</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-27-mesh-basics">Day 27 &#8211; Mesh Basics</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-28-distorted-grids">Day 28 &#8211; Distorted Grids</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-29-distorted-3d-mesh">Day 29 &#8211; Distorted 3D Mesh</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-30-particle-system">Day 30 &#8211; Particle System</a></li>
		<li><a href="http://vormplus.be/blog/article/processing-month-day-31-building-interactive-installations-with-opencv">Day 31 &#8211; Building Interactive Installations with OpenCV</a></li>
	</ul>

	<h2>OpenProcessing</h2>

	<p>Some of the examples are also available on my <a href="http://openprocessing.org/portal/?userID=11331">OpenProcessing Portfolio</a>. Here&#8217;s the full list.</p>

	<ul>
		<li><a href="http://openprocessing.org/visuals/?visualID=27952">Connecting Points, Part 1</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28023">Connecting Points, Part 2</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28100">Triangle Grid</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28207">Stars</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28291">Square Flower</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28338">Square Flowers</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28431">Bubbles</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28547">Painting, Part 1</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28713">Regular Polygons</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28764">Manipulating Circles</a></li>
		<li><a href="http://openprocessing.org/visuals/?visualID=28805">Rounded Rectangles</a></li>
	</ul>

	<h2>Download</h2>

	<p>I made a zip-file with all sketches I made during Processing Month. This will be a lot easier than downloading all examples one by one. Download all examples for <a href="http://img.vormplus.be/downloads/processing_month_all_examples.zip">Processing Month</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 31 - Building Interactive Installations with OpenCV</title>
			<link>http://vormplus.be/blog/article/processing-month-day-31-building-interactive-installations-with-opencv</link>
			<pubDate>Tue, 31 May 2011 14:04:55 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-31-building-interactive-installations-with-opencv</guid>
			<description><![CDATA[	<p>For the last day in my Processing Month series, I&#8217;m going to cover the basics of building interactive installations with Processing. The name of the installation we&#8217;ll build is &#8220;The Blurry Mirror&#8221;. The concept is easy: the computer screen will act as a digital mirror. The closer somebody gets to the installation, the more the image in the digital mirror will be blurred. We&#8217;re going to do some facetracking with the OpenCV library for Processing. You should <a href="http://ubaa.net/shared/processing/opencv/">download and install the OpenCV library</a> to get started.</p>

	<h2>Setting up OpenCV</h2>

	<p>Inside the <code>setup()</code> function, we need to setup OpenCV and tell it what we&#8217;re going to track. I have set OpenCV to capture the video from my webcam at a resolution of 640 &#215; 480 pixels. This should be enough for most installations. You can use a higher resolution if your camera supports it, but this will require more processing time for the <span class="caps">CPU</span>. The last OpenCV method I used in the <code>setup()</code> of my sketch is <code>cascade()</code>. I&#8217;m using one of the standard cascades (<code>CASCADE_FRONTALFACE_ALT</code>) to track a face in a video. This method can also be used to load a custom xml file with a description for tracking objects.</p>

<pre><code>size( 1024, 768 );
opencv = new OpenCV( this );
opencv.capture( 640, 480 );
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
</code></pre>

	<h2>Preparing the Image</h2>

	<p>The next thing we need to do is to prepare the image from the camera for face tracking. This code below should be the first part inside the <code>draw()</code> function. The <code>read()</code> method will get the current image from the camera so we can use it in our installation. We also need to flip our image with <code>FLIP_HORIZONTAL</code> to get the mirror effect. You can also adjust the contrast and brightness of the image to get better tracking when needed. These methods need an integer between -128 and 128. I&#8217;ve used the arrow keys to adjust the values. You can display the image by using the OpenCV <code>image()</code> method as the first parameter for the standard Processing <code>image()</code> function.</p>

<pre><code>opencv.read();
opencv.flip( OpenCV.FLIP_HORIZONTAL );
opencv.contrast( contrastValue );
opencv.brightness( brightnessValue );
image( opencv.image(), 0, 0 );
</code></pre>

	<h2>Detecting Faces</h2>

	<p>Now that our image is prepared, we need to use the <code>detect()</code> method to scan the image for frontal faces. We can do this with the following line of code. I&#8217;ve imported java.awt.Rectangle because the <code>detect()</code> method will return an array of rectangles. These rectangles have a location, width and height we can use as parameters for blurring the final output of our installation.</p>

<pre><code>Rectangle[] faces = opencv.detect( 1.2, 2, ¬
        OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
</code></pre>

	<p>Because a mirror is something personal, I only want to track one face, so only one person at a time will be able to interact with the installation. The first if statement is really important. We only need to do things with the image or the rectangles if a face is found in the image, otherwise the installation would crash. I&#8217;ve mapped the coordinate and the width of the first face to the size of our Processing sketch. The variable <code>f</code> is then used to decide how much the final image should be blurred. If the size of the face is small (far away from the camera), the image doesn&#8217;t get blurred, if the size is big (close to the camera) the image gets blurred a lot. I also added an if statement for debugging. This can be toggled by pressing the <strong>d key</strong> on your keyboard. The image below shows you the blurred image when somebody gets close to the camera.</p>

<pre><code>if ( faces.length &gt; 0 ) &#123;
	// values needed for debugging
    float x = map( faces[0].x, 0, 640, 0, 1024 );
    float y = map( faces[0].y, 0, 480, 0, 768 );
    float f = map( faces[0].width, 0, 640, 0, 1024 );       
    if ( f &lt;= 200) &#123;
        // no blurring
    &#125; else if ( f &gt; 200 &amp;&amp; f &lt;= 300 ) &#123;
        opencv.blur( OpenCV.GAUSSIAN, 11 );    
    &#125; else if ( f &gt; 300 &amp;&amp; f &lt;= 400 ) &#123;
        opencv.blur( OpenCV.GAUSSIAN, 31 );    
    &#125; else if ( f &gt; 400 &amp;&amp; f &lt;= 500 ) &#123;
        opencv.blur( OpenCV.GAUSSIAN, 51 );   
    &#125; else &#123;
        opencv.blur( OpenCV.GAUSSIAN, 71 );
    &#125;
    image( opencv.image(), 0, 0, width, height );
    if ( DEBUG ) &#123;
        noFill();
        stroke( 255, 0, 0 );
    	rect( x, y, f, f );
    &#125;
&#125;
</code></pre>

	<p><img src="http://img.vormplus.be/blog/blurry-mirror-installation.jpg" title="A blurred face close to our Mirror installation" alt="A blurred face close to our Mirror installation" /></p>

	<p>The last thing we need to do is to add an extra function to our application to stop OpenCV when our application quits.</p>

<pre><code>public void stop()
&#123;
    opencv.stop();
    super.stop();
&#125;
</code></pre>

	<h2>Download</h2>

	<p>We covered the basics of OpenCV, so you should be able to get started and build your own interactive installation. You can download the example for the <a href="http://img.vormplus.be/downloads/processing_month_day_031.zip">Blurry Mirror installation</a>. and experiment with it.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 30 - Particle System</title>
			<link>http://vormplus.be/blog/article/processing-month-day-30-particle-system</link>
			<pubDate>Mon, 30 May 2011 20:10:16 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-30-particle-system</guid>
			<description><![CDATA[	<p>Today, I&#8217;ve used the algorithm we programmed on <a href="http://vormplus.be/blog/article/processing-month-day-2-connecting-points-part-2">day 2</a> to create a simple particle system. Each particle has a location and velocity vector and a color. If the particle goes off-screen, it dies and a new one will be born. This is an easy way to create a continously animated system. When the particles get close enough to each other, a line is drawn between them. I&#8217;ve used <code>lerp()</code> to calculate the location of the dots on those lines and <code>lerpColor()</code> to calculate the color of each dot.</p>

	<h2>Example</h2>

	<p>I&#8217;ve used the video library to render the animation as a movie file. The HD video is also available on <a href="http://vimeo.com/24419668">Vimeo</a>.</p>

	<p><iframe src="http://player.vimeo.com/video/24419668?title=0&amp;byline=0&amp;portrait=0&amp;color=000000" width="427" height="240"></iframe></p>

	<h2>Download</h2>

	<p>Download the sketch for the <a href="http://img.vormplus.be/downloads/processing_month_day_030.zip">particle system</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 29 - Distorted 3D Mesh</title>
			<link>http://vormplus.be/blog/article/processing-month-day-29-distorted-3d-mesh</link>
			<pubDate>Sun, 29 May 2011 20:36:02 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-29-distorted-3d-mesh</guid>
			<description><![CDATA[	<p>Today we&#8217;ll take a look at how we can construct <a href="http://vormplus.be/blog/article/processing-month-day-28-distorted-grids">the grid we made yesterday</a> in 3D. The first thing you need to do is add a third parameter to the <code>size()</code> function. If you import the OpenGL library, you can use <code>OPENGL</code> as the third parameter, but for now we&#8217;ll use the <code>P3D</code> renderer. When we fill the PVector array, we need a third parameter for the PVector constructor. This will be the z-coordinate of that point in space. I&#8217;ve used a random number between -20 and 20. In the draw function, you need to add this z-coordinate to the <code>vertex()</code> function.</p>

	<h2>Examples</h2>

	<p>The grid in 3D looks like this. I used the <code>lights()</code> to add shadows to the mesh so it looks better when Processing renders it.</p>

	<p><img src="http://img.vormplus.be/blog/3d-grid-001.png" title="A distorted 3D mesh made with Processing." alt="A distorted 3D mesh made with Processing." /></p>

	<p><img src="http://img.vormplus.be/blog/3d-grid-002.png" title="A distorted 3D mesh made with Processing." alt="A distorted 3D mesh made with Processing." /></p>

	<p><img src="http://img.vormplus.be/blog/3d-grid-003.png" title="A distorted 3D mesh made with Processing." alt="A distorted 3D mesh made with Processing." /></p>

	<p><img src="http://img.vormplus.be/blog/3d-grid-004.png" title="A distorted 3D mesh made with Processing." alt="A distorted 3D mesh made with Processing." /></p>

	<h2>Download</h2>

	<p>Download the <a href="http://img.vormplus.be/downloads/processing_month_day_029.zip">distorted 3D mesh sketch</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 28 - Distorted Grids</title>
			<link>http://vormplus.be/blog/article/processing-month-day-28-distorted-grids</link>
			<pubDate>Sat, 28 May 2011 22:00:41 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-28-distorted-grids</guid>
			<description><![CDATA[	<p>Today, we&#8217;re going to distort the grid we made yesterday. To do this, we&#8217;ll need to modify the algorithm a little bit. We need a multidimensional <code>PVector</code> array to keep track of the points in the grid. We&#8217;ll calculate the normal points and use <code>random()</code> to move them away from the grid. The code below shows you how to fill the array.</p>

<pre><code>for (int j = 0; j &lt; 11; j++) &#123;
    for (int i = 0; i &lt; 11; i++) &#123;
         vertices&lt;i&gt;[j] = new PVector( i*40 + random(-10, 10),
                                       j*40 + random(-10, 10) );
    &#125;
&#125;
</code></pre>

	<p>the code for drawing the grid is a little different too. We don&#8217;t calculate the points while drawing in this example, we get them out of the PVector array we&#8217;ve set up earlier.</p>

<pre><code>for (int j = 0; j &lt; 10; j ++) &#123;
    beginShape(QUAD_STRIP);
    for (int i = 0; i &lt; 11; i++) &#123;
        vertex( vertices&lt;i&gt;[j].x, vertices&lt;i&gt;[j].y );
        vertex( vertices&lt;i&gt;[j+1].x, vertices&lt;i&gt;[j+1].y );
    &#125;
    endShape();
&#125;
</code></pre>

	<h2>Examples</h2>

	<p>If we draw the grids with <code>QUAD_STRIP</code> and <code>TRIANGLE_STRIP</code>, they&#8217;ll look like this.</p>

	<p><img src="http://img.vormplus.be/blog/quadstrip-grid-distort.png" title="A distorted quad strip grid." alt="A distorted quad strip grid." /></p>

	<p><img src="http://img.vormplus.be/blog/trianglestrip-grid-distort.png" title="A distorted triangle strip grid." alt="A distorted triangle strip grid." /></p>

	<h2>Download</h2>

	<p>Download the <a href="http://img.vormplus.be/downloads/processing_month_day_028.zip">examples to create your own distorted grid</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 27 - Mesh Basics</title>
			<link>http://vormplus.be/blog/article/processing-month-day-27-mesh-basics</link>
			<pubDate>Fri, 27 May 2011 21:46:12 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-27-mesh-basics</guid>
			<description><![CDATA[	<p>Today we&#8217;ll take a look at how we can use the <code>QUAD_STRIP</code> and <code>TRIANGLE_STRIP</code> modes with <code>beginShape()</code> to draw a mesh to the screen. This will be useful when you want to get started with <a href="http://vormplus.be/blog/article/drawing-3d-shapes-with-processing">drawing 3D shapes with Processing</a>. This first example will draw a strip made from rectangles.</p>

<pre><code>beginShape(QUAD_STRIP);
for (int i = 0; i &lt; 11; i++) &#123;
    vertex( i * 40, 0 );
    vertex( i * 40, 60 );
&#125;
endShape();
</code></pre>

	<p><img src="http://img.vormplus.be/blog/quadstrip.png" title="A quad strip, made with Processing" alt="A quad strip, made with Processing" /></p>

	<p>The second example uses the <code>TRIANGLE_STRIP</code> mode and draws the same thing to the screen, only with triangles now.</p>

<pre><code>beginShape(TRIANGLE_STRIP);
for (int i = 0; i &lt; 11; i++) &#123;
    vertex( i * 40, 0 );
    vertex( i * 40, 60 );
&#125;
endShape();
</code></pre>

	<p><img src="http://img.vormplus.be/blog/trianglestrip.png" title="A triangle strip, made with Processing" alt="A triangle strip, made with Processing" /></p>

	<p>If we want to draw a grid, we need nested for loops. The code is almost the same as in the first example. The y-coordinate of each vertex gets calculated now and we wrapped an extra for loop around the code. Note that the outer for-loop only runs to 10, not to 11. If it would run to 11, we would render a grid of 11 &#215; 10 rectangles.</p>

<pre><code>for (int j = 0; j &lt; 10; j ++) &#123;
    beginShape(QUAD_STRIP);
    for (int i = 0; i &lt; 11; i++) &#123;
        vertex( i * 40, j * 40 );
        vertex( i * 40, (j+1) * 40 );
    &#125;
    endShape();
&#125;
</code></pre>

	<p><img src="http://img.vormplus.be/blog/quadstrip-grid.png" title="A quad strip grid, made with Processing" alt="A quad strip grid, made with Processing" /></p>

	<p>If you want to render the grid with triangles, replace <code>QUAD_STRIP</code> in the previous example to <code>TRIANGLE_STRIP</code> to get the result in the image below.</p>

	<p><img src="http://img.vormplus.be/blog/trianglestrip-grid.png" title="A triangle strip, made with Processing" alt="A triangle strip, made with Processing" /></p>

	<h2>Download</h2>

	<p>Download all <a href="http://img.vormplus.be/downloads/processing_month_day_027.zip">Processing examples for Mesh Basics</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 26 - Data Visualisation</title>
			<link>http://vormplus.be/blog/article/processing-month-day-26-data-visualisation</link>
			<pubDate>Thu, 26 May 2011 21:32:16 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-26-data-visualisation</guid>
			<description><![CDATA[	<p>Today I&#8217;ll be mixing two sketches we did this month: the data visualisation sketch we did yesterday and the one about using <span class="caps">PDF</span> files for lasercutting. I&#8217;ll share the algorithm I used to create these beautiful tangible datasets.</p>

	<p><img src="http://img.vormplus.be/blog/data-visualisation-finished-lasercut-001.jpg" title="Data visualisation made with Processing and a lasercutter" alt="Data visualisation made with Processing and a lasercutter" /></p>

	<p><img src="http://img.vormplus.be/blog/data-visualisation-finished-lasercut-002.jpg" title="Data visualisation made with Processing and a lasercutter" alt="Data visualisation made with Processing and a lasercutter" /></p>

	<p>The algorithm for drawing the polygon is similar to the one we used yesterday for drawing the bars. We&#8217;ll use beginShape() and we need to draw two vertices each time we go through the loop.</p>

<pre><code>void renderPolygon()
&#123;
    float closeX = 0;
    float closeY = 0;
    beginShape();
    for (int i = 0; i &lt; values.length; i++) &#123;
        float r = map(values&lt;i&gt;, 0, 100, minRadius, maxRadius);
        if ( i == 0 ) &#123;
            closeX = cos(i * angle) * r;
            closeY = sin(i * angle) * r;
        &#125;
        float x1 = cos(i * angle) * r;
        float y1 = sin(i * angle) * r;
        float x2 = cos((i + 1) * angle) * r;
        float y2 = sin((i + 1) * angle) * r;
        vertex(x1, y1);
        vertex(x2, y2);
    &#125;
    endShape(CLOSE);
    ellipse( 0, 0, minRadius, minRadius );
    ellipse( minRadius/2 + 5, 0, 4, 4 );
&#125;
</code></pre>

	<p>The function for the circles uses the minimum and maximum radius and the lerp() function to calculate the radius for each circle. The distance between each circle is 10%, so the values for each bar will still be readable when the objects are cut.</p>

<pre><code>void renderCircles()
&#123;
    float diff = maxRadius - minRadius;
    for (int i = 0; i &lt; 10; i++) &#123;
        float r = lerp( minRadius, maxRadius, i / 10.0 ) * 2;
        noFill();
        ellipse( 0, 0, r, r );
    &#125;
    ellipse( 0, 0, maxRadius * 2, maxRadius * 2 );
&#125;
</code></pre>

	<p>The output of the sketch looks like this. If you combine this algorithm with the technique I&#8217;ve used to output everything to a <span class="caps">PDF</span> file, you&#8217;ll be able to make beautiful objects made from data.</p>

	<p><img src="http://img.vormplus.be/blog/data-visualisation-for-lasercutting.png" title="The output from our sketch, ready for lasercutting" alt="The output from our sketch, ready for lasercutting" /></p>

	<h2>Download</h2>

	<p>Download the sketch for <a href="http://img.vormplus.be/downloads/processing_month_day_026.zip">day 26, Data Visualisation</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 25 - Circular Bar Charts</title>
			<link>http://vormplus.be/blog/article/processing-month-day-25-circular-bar-charts</link>
			<pubDate>Wed, 25 May 2011 19:24:11 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-25-circular-bar-charts</guid>
			<description><![CDATA[	<p>Today we&#8217;ll take a dive into data visualisation. We&#8217;re going to take look at how we can draw a circular bar chart. I&#8217;m not going to use a real data set for this example. An array of random numbers between 0 and 100 will do the trick for now, the focus is on drawing the chart to the screen.</p>

	<p>The code below is the full class to draw the chart. To create a beautiful chart you need about 60 values, but it&#8217;s flexible enough to draw charts with 30 bars or 100 bars.</p>

<pre><code>class CircularBarChart
&#123;
    float maxRadius;
    float minRadius;
    float values[];
    float angle;
    CircularBarChart(float[] _values)
    &#123;
        minRadius = 50;
        maxRadius = 200;
        values = _values;
        angle = TWO_PI / float( values.length );
    &#125;
    void renderLines()
    &#123;
        for (int i = 0; i &lt; values.length; i++) &#123;
            float x1 = cos( i * angle ) * ( minRadius / 2 );
            float y1 = sin( i * angle ) * ( minRadius / 2 );
            float r = map(values&lt;i&gt;, 0, 100, minRadius, maxRadius);
            float x2 = cos( i * angle ) * r;
            float y2 = sin( i * angle ) * r;
            line(x1, y1, x2, y2);
        &#125;
    &#125; 
&#125;
</code></pre>

	<h2>Examples</h2>

	<p><img src="http://img.vormplus.be/blog/circular-bar-chart-30.png" title="A circular bar chart with 30 bars, made with Processing" alt="A circular bar chart with 30 bars, made with Processing" /></p>

	<p><img src="http://img.vormplus.be/blog/circular-bar-chart-50.png" title="A circular bar chart with 50 bars, made with Processing" alt="A circular bar chart with 50 bars, made with Processing" /></p>

	<p><img src="http://img.vormplus.be/blog/circular-bar-chart-80.png" title="A circular bar chart with 80 bars, made with Processing" alt="A circular bar chart with 80 bars, made with Processing" /></p>

	<p><img src="http://img.vormplus.be/blog/circular-bar-chart-120.png" title="A circular bar chart with 120 bars, made with Processing" alt="A circular bar chart with 120 bars, made with Processing" /></p>

	<h2>Downloads</h2>

	<p>Download the sketch for <a href="http://img.vormplus.be/downloads/processing_month_day_025.zip">Processing Month Day 25, Circular Bar Charts</a>.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 24 - Client/Server Part 2</title>
			<link>http://vormplus.be/blog/article/processing-month-day-24-client-server-part-2</link>
			<pubDate>Tue, 24 May 2011 19:42:12 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-24-client-server-part-2</guid>
			<description><![CDATA[	<p>In part two of Client/Server programming with Processing, we&#8217;ll take a look at creating the client application. You need to create a new client object with the same port number as the server. If you run the client sketch on the same machine, you can use 127.0.0.1 for the IP Address, if it runs on another computer, you need to use the IP Address of the machine that runs the server sketch.</p>

<pre><code>client = new Client( this, &quot;127.0.0.1&quot;, 5000 );
</code></pre>

	<p>We also need a function to convert the byte array back to an integer. You can find this one in the functions tab.</p>

<pre><code>int byteArrayToInt(byte[] bytes) &#123;
    int bits = 0;
    int counter = 0;
    for (int i = 3; i &gt;= 0; i--) &#123;
        bits |= ((int) bytes[counter] &amp; 0xff) &lt;&lt; (i * 8);
        counter++;
    &#125;
    return bits;
&#125;
</code></pre>

	<p>The final thing we need to do is to read the data the server application is sending with <code>clients.readBytesUntil()</code> into a bytebuffer and get the x and y coordinates out of there for drawing ellipses and lines to the screen.</p>

<pre><code>if ( client.available() &gt; 0 ) &#123;
    int byteCount = client.readBytesUntil( interesting, byteBuffer );
    byte[] xb = new byte[4];
    for (int i = 0; i &lt; 4; i++) &#123;
        xb&lt;i&gt; = byteBuffer&lt;i&gt;;
    &#125;
    byte[] yb = new byte[4];
    for (int i = 0; i &lt; 4; i++) &#123;
        yb&lt;i&gt; = byteBuffer[i+4];
    &#125;
    int x = byteArrayToInt( xb );
    int y = byteArrayToInt( yb );
    line( x, y, prevX, prevY );
    ellipse( x, y, 10, 10 );
    prevX = x;
    prevY = y;
&#125;
</code></pre>

	<h2>Screencast</h2>

	<p>I&#8217;ve created a screencast so you can see what the application does. You can find it on <a href="http://vimeo.com/24178953">Vimeo</a>.</p>

	<p><iframe src="http://player.vimeo.com/video/24178953?title=0&amp;byline=0&amp;portrait=0&amp;color=000000" width="427" height="240"></iframe></p>

	<h2>Download</h2>

	<p>Download the <a href="http://img.vormplus.be/downloads/processing_month_day_024.zip">client sketch</a> you&#8217;ve read about today. I&#8217;ve included the server sketch from yesterday.</p>]]></description>
		</item>
		
		<item>
			<title>Processing Month, Day 23 - Client/Server Part 1</title>
			<link>http://vormplus.be/blog/article/processing-month-day-23-client-server-part-1</link>
			<pubDate>Mon, 23 May 2011 22:18:00 +0000</pubDate>
			<guid>http://vormplus.be/blog/article/processing-month-day-23-client-server-part-1</guid>
			<description><![CDATA[	<p>Today and tomorrow, we&#8217;ll dive into the dark art of communication between computers. We&#8217;ll use the <a href="http://processing.org/reference/libraries/net/index.html">Network</a> library that is included with Processing. The server application we&#8217;ll create today will send the mouse position to the client application we&#8217;ll create tomorrow. You should start a server inside <code>setup()</code> and use a port number that is high enough. I&#8217;m using port number 5000 in this example.</p>

<pre><code>server = new Server( this, 5000 );
</code></pre>

	<p>We&#8217;re going to keep this program as simple as possible. The only piece of code that goes inside <code>draw()</code> is the line below. The server.write() method is part of the Network library, the <code>getMousePositionAsByteArray()</code> function is one we&#8217;re going to write ourselves.</p>

<pre><code>server.write( getMousePositionAsByteArray() );
</code></pre>

	<p>To communicate to the client application, we need to send the info as bytes. The mouseX and mouseY variables are integers (stored in memory as 32 bits) so we need to convert each integer to a byte Array with a length of 4.</p>

<pre><code>byte[] intToByteArray(int number) &#123;
    byte[] result = new byte[4];
    for (int i = 0; i &lt; 4; i++) &#123;
        int offset = (result.length - 1 - i) * 8;
        result&lt;i&gt; = (byte) ((number &gt;&gt;&gt; offset) &amp; 0xff);
    &#125;
    return result;
&#125;
</code></pre>

	<p>To send the mouse position to the client application, we need to create an array with the x and y position and an extra byte at the end so we can &#8216;sync&#8217; the client application with the server. This function creates a byte Array with a length of 9 and fills it with the mouse position and the separator byte.</p>

<pre><code>byte[] getMousePositionAsByteArray()
&#123;
    byte[] x = intToByteArray( mouseX );
    byte[] y = intToByteArray( mouseY );    
    byte[] b = new byte[9];
    for (int i = 0; i &lt; 4; i++) &#123;
        b&lt;i&gt; = x&lt;i&gt;;
    &#125;
    for (int i = 4; i &lt; 8; i++) &#123;
        b&lt;i&gt; = y[i-4];
    &#125;
    b[8] = 10; // separator byte
    return b;
&#125;
</code></pre>

	<h2>Download</h2>

	<p>Download the <a href="http://img.vormplus.be/downloads/processing_month_day_023.zip">server sketch</a> you&#8217;ve read about today.</p>]]></description>
		</item>
		
	</channel>
</rss>

