<?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>voyce &#187; Graphics</title>
	<atom:link href="http://www.voyce.com/index.php/category/graphics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Sat, 03 Jul 2010 12:40:51 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Minilight renderer in F#</title>
		<link>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/</link>
		<comments>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 17:19:43 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[monte carlo]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=938</guid>
		<description><![CDATA[Porting the Minilight global illumination renderer to F#.]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_961" class="wp-caption alignleft" style="width: 150px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/cornellbox-e.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/cornellbox-e.png" alt="Cornell Box in the evening" title="cornellbox-e" width="140" height="140" class="size-full wp-image-961" /></a><p class="wp-caption-text">Cornell Box in the evening</p></div>I&#8217;m a sucker for eye-candy, and the other day I came across the beautifully lit renders produced by <a href="http://www.hxa.name/minilight/">Minilight</a>. It&#8217;s a nice, minimal implementation of a global illumination renderer that&#8217;s been ported to a wide variety of different languages from C to ActionScript. So of course, I couldn&#8217;t resist trying to implement it in F#.<br />
<span id="more-938"></span></p>
<h3>What is a &#8220;global illumination renderer&#8221;?</h3>
<p>In short; a global illumination renderer attempts to simulate the way that light behaves in the real world. It bounces rays of light around the scene, noting which surfaces are hit, and how each of them affects the ray. Of course real light travels fast &#8211; at about the speed of light, in fact &#8211; and our simulated rays can&#8217;t match that, so although the resulting effect looks natural, it&#8217;s not a very efficient way of getting there. Graphics systems that need to be near real-time (i.e. games), use a variety of short-cuts to try and get the same effect without requiring the same amount of number crunching.</p>
<p>Even this implementation is forced to use a couple of techniques to improve performance, I won&#8217;t go into them here, as they&#8217;re explained pretty thoroughly on the Minilight site. </p>
<p>Interestingly the algorithm uses a Monte Carlo technique to simulate the random path of the ray through the scene and the same technique is used in finance to model how the price of an asset will change through time. </p>
<h3>Translating to F#</h3>
<p><div id="attachment_970" class="wp-caption alignright" style="width: 160px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/roomfront.sun.ml.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/roomfront.sun.ml-150x150.png" alt="Room with sun and light, 800 paths per pixel" title="roomfront.sun.ml" width="150" height="150" class="size-thumbnail wp-image-970" /></a><p class="wp-caption-text">Room with sun and light, 800 paths per pixel</p></div>Luckily, the existing OCaml version is considered one of the reference implementations, and as ML is the spiritual predecessor of F# I didn&#8217;t expect it to be too difficult to port. It wasn&#8217;t. I&#8217;m no ML expert, so some of the language features were a bit of a surprise; things like the use of a dot on all of the operators, but these are pretty minimal syntactic differences.</p>
<p>Some of the ML constructs caused warnings from the F# compiler as I didn&#8217;t use the explicit ML compatibility mode. For instance, the use of the <code>^</code> operator to concatenate strings:<br />
<code><br />
warning FS0062: This construct is for ML compatibility. Consider using the '+' operator instead. This may require a type annotation to indicate it acts on strings.<br />
</code><br />
Some other changes included:</p>
<ul>
<li>Using dot rather than # notation to access class members</li>
<li>Using square bracket for array element access (<code>array.[n]</code> rather than <code>array.(n)</code>)</li>
<li>Removing <code>let...and</code> for non-recursive bindings</li>
</ul>
<p>There was also the opportunity to make use of some of the .NET framework classes, things like <code>System.Drawing.Bitmap</code> to write pixels directly into a bitmap and then save it into a .PNG file. Much easier than trying to find something to read the .PPM file that the original version emits.    </p>
<h3>Potential improvements</h3>
<p>One of the most obvious improvements that could be made is to make use of the parallelism support in F# and .NET. The algorithm itself is easily (if not embarrassingly) parallelisable, given that it iterates over the pixels in the output image, and performs independent operations on each of them. Unfortunately I haven&#8217;t had a chance to look at this yet &#8211; and the Windows VM I&#8217;m using only has a single processor anyway, so on a purely selfish note, I wouldn&#8217;t see any immediate performance improvements.  It should be as simple as changing the pixel loop to use <code>Parallel.For</code>, or creating an <code>async</code> computation expression.</p>
<p>Something else to note: I err&#8217;d on the side of caution when it comes to saving intermediate images, so every iteration it creates and writes the file. This will be doing lots of allocation and strictly unnecessary work, especially for simple scenes.</p>
<p>Given this approach is so completely compute bound it would be interesting to see how moving some of the calculations to a GPU would affect it. It might even be possible to use quotations for some of the inner loops and then generate Nvidia intermediate language (PTX) from them &#8211; that&#8217;s something I&#8217;ve been wanting to do for a while. </p>
<p>I did run the code through the Visual Studio 2010 profiler to get a rough idea of where the time was being spent; it looked like the majority was in the leaf of the calculations where numerical operations where being performed on the vectors, which is consistent with what we&#8217;d expect.</p>
<h3>Use the source</h3>
<p>So, here&#8217;s the source. No warranties implied, use at your own risk, your mileage may vary, all errors are mine etc, etc.<br />
<a href='http://www.voyce.com/wp-content/uploads/2010/06/minilight_fsharp.zip'>minilight_fsharp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating an iPad flip-clock with Core Animation</title>
		<link>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/</link>
		<comments>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 17:48:04 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=791</guid>
		<description><![CDATA[Using Core Animation to create flip-card number animations on the iPad and iPhone]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_one.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_one.png" alt="flipclock_one" title="flipclock_one" width="69" height="127" class="alignleft size-full wp-image-793" /></a>As part of the sliding puzzle game I&#8217;m developing for the iPhone and iPad (well, I can&#8217;t survive on the profits from <a href="http://voyce.com/BattleFingers/">BattleFingers</a> forever), I looked for a way to represent a numeric score and time display in an interesting way. One of the nicer visual effects you could use for this is the &#8220;flip-card clock&#8221; style, where each number consists of a top and bottom part, and the top part flips down to reveal the next number. It&#8217;s been used in a few other places including the home screen in the HTC Diamond device, and its physical, realistic style fits well with the iPad, so I set about creating a version for the iPhone and iPad using the built-in Core Animation library. Read on for more details.<br />
<span id="more-791"></span><br />
I started by thinking about the motions that would be required for the animation. We can break it down as three elements, the top, the bottom and the flipping part. Each of these parts can be represented as a Core Animation Layer (a <code>CALayer</code>). We create them using the class method on CALayer, there&#8217;s no additional <code>retain</code> here, as the <code>_toplayer</code> property is retained.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">_toplayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CALayer layer<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Splitting images</h2>
<p>Now we&#8217;ve got the layers, we need something to but into them. I didn&#8217;t want to create lots of pre-processed images for the top and bottom sections of each number, so instead I wrote a routine to split the images in code, drawing each half into an image context and grabbing a <code>UIImage</code> from it. This is then stored in an array for later use. We can get any of the elements from the array and set it as the <code>content</code> of the layer as required.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// The size of each part is half the height of the whole image</span>
CGSize size <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.width, <span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Create image-based graphics context for top half</span>
UIGraphicsBeginImageContext<span style="color: #002200;">&#40;</span>size<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Draw into context, bottom half is cropped off</span>
<span style="color: #002200;">&#91;</span>img drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>,<span style="color: #2400d9;">0.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// Grab the current contents of the context as a UIImage </span>
<span style="color: #11740a; font-style: italic;">// and add it to our array</span>
UIImage <span style="color: #002200;">*</span>top <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;			
<span style="color: #002200;">&#91;</span>_imagesTop addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>top<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Now draw the image starting half way down, to get the bottom half</span>
<span style="color: #002200;">&#91;</span>img drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>,<span style="color: #002200;">-</span><span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// And store that image in the array too</span>
UIImage <span style="color: #002200;">*</span>bottom <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;			
<span style="color: #002200;">&#91;</span>_imagesBottom addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>bottom<span style="color: #002200;">&#93;</span>;
&nbsp;
UIGraphicsEndImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Now our <code>_imagesTop</code> and <code>_imagesBottom</code> arrays contains all the images we need, let&#8217;s get &#8216;em moving.</p>
<h2>Applying animation</h2>
<p><div id="attachment_808" class="wp-caption alignright" style="width: 212px"><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_axes1.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_axes1-202x300.png" alt="The axes and anchor point of a CALayer" title="flipclock_axes" width="202" height="300" class="size-medium wp-image-808" /></a><p class="wp-caption-text">The axes and anchor point of a CALayer</p></div>The animation we need to apply to the &#8216;flipping&#8217; part is a rotation around the bottom of the layer, at the join between the two halves. The default location of the anchor point is the middle of the layer, which would mean the piece would rotate around the middle, but we can easily change it to instead be at the middle in the bottom (for our purposes it could be anywhere on the bottom, as we&#8217;re only interested in x-axis rotation):</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">_fliplayer.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.5</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>I use the <code>CATransform3DMakeRotation</code> function to create a transform around the X axis using the vector [1,0,0]. For the first part of the motion, we go from 0 radians to pi/2 radians (0 to 90 degrees), using an explicit <code>CABasicAnimation</code> object:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CABasicAnimation <span style="color: #002200;">*</span>topAnim <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CABasicAnimation animationWithKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;transform&quot;</span><span style="color: #002200;">&#93;</span>;
topAnim.duration<span style="color: #002200;">=</span><span style="color: #2400d9;">0.25</span>;
topAnim.repeatCount<span style="color: #002200;">=</span><span style="color: #2400d9;">1</span>;
topAnim.fromValue<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCATransform3D<span style="color: #002200;">:</span>CATransform3DMakeRotation<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">float</span> f <span style="color: #002200;">=</span> <span style="color: #002200;">-</span>M_PI<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>;
topAnim.toValue<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCATransform3D<span style="color: #002200;">:</span>CATransform3DMakeRotation<span style="color: #002200;">&#40;</span>f, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
topAnim.delegate <span style="color: #002200;">=</span> self;
topAnim.removedOnCompletion <span style="color: #002200;">=</span> FALSE;
<span style="color: #002200;">&#91;</span>_fliplayer addAnimation<span style="color: #002200;">:</span>topAnim forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span>k_TopAnimKey<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Drawing layer content</h2>
<p>Unfortunately a CALayer doesn&#8217;t have a &#8220;back&#8221;, so creating the flip layer is not as easy as it could be. We need to add a step in the process to change the image displayed by the flip layer half way through its fall. We can do this in a variety of ways, I&#8217;ve chosen to set a delegate object to perform the drawing of the layer contents:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_fliplayer setDelegate<span style="color: #002200;">:</span>_layerHelper<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This means our delegate object (<code>_layerHelper</code>) has its <code>drawLayer</code> method called whenever the layer needs to display its contents. Be wary though, this may not be as often as you think! Core graphics aggressively caches the contents of the layer, and will only call your delegate when absolutely necessary. You can force it to happen by calling <code>setNeedsDisplay</code>, which invalidates the contents of the layer:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_fliplayer setNeedsDisplay<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>I encapsulated this in the helper object itself, by providing a custom implementation of the <code>isTop</code> property setter that calls <code>setNeedsDisplay</code>. At least that way callers don&#8217;t have to be aware of this requirement.</p>
<p>The <code>drawLayer</code> method itself simply draws one of two images into the context, depending on whether it&#8217;s in &#8216;top&#8217; mode. A slight further complication is that when drawing the bottom part, the image needs to be inverted to display upside down. This is achieved by applying a translation and scale to the context before drawing the image:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextSaveGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
CGContextTranslateCTM<span style="color: #002200;">&#40;</span>context, 0.0f, r.size.height<span style="color: #002200;">&#41;</span>;
CGContextScaleCTM<span style="color: #002200;">&#40;</span>context, 1.0f, <span style="color: #002200;">-</span>1.0f<span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextDrawImage<span style="color: #002200;">&#40;</span>context, r, <span style="color: #002200;">&#91;</span>_imgTop CGImage<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextRestoreGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;</pre></div></div>

<h2>Avoiding implicit animation</h2>
<p>I&#8217;ve tried to avoid using implicit animation here, instead using explicit construction of <code>CABasicAnimation</code> objects, because we need some control of when things happen, and the order in which they happen. Normally, it would be easier to just set some property of the view and let the OS manage animating it. Many properties have default transition that are applied whenever they&#8217;re changed, so it takes some additional effort to make them change immediately.</p>
<p>In our example we change the contents of the top half and show the flip layer, but we need that to happen immediately so we disable actions within an explicit transaction that we then commit. This gives us the control we need, and avoids the default behaviour of the transition occurring when the message loop next runs.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>CATransaction begin<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>CATransaction setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kCFBooleanTrue
				forKey<span style="color: #002200;">:</span>kCATransactionDisableActions<span style="color: #002200;">&#93;</span>;
_toplayer.contents <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>_imagesTop objectAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self getNextIndex<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> CGImage<span style="color: #002200;">&#93;</span>;
_fliplayer.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#91;</span>CATransaction commit<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Getting some perspective</h2>
<p>Although the images I&#8217;ve used to illustrate this post are isometric, what we really want is a front-on perspective view, so that the falling piece seems to stick out. For this we have to set a <code>sublayerTransform</code> on the view&#8217;s inherent layer, by setting an individual element on a transform:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CATransform3D aTransform <span style="color: #002200;">=</span> CATransform3DIdentity;
<span style="color: #a61390;">float</span> zDistance <span style="color: #002200;">=</span> <span style="color: #2400d9;">1000</span>;
aTransform.m34 <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.0</span> <span style="color: #002200;">/</span> <span style="color: #002200;">-</span>zDistance;	
<span style="color: #002200;">&#91;</span>self layer<span style="color: #002200;">&#93;</span>.sublayerTransform <span style="color: #002200;">=</span> aTransform;</pre></div></div>

<p>This gives us a much more realistic look.</p>
<h2>Putting it together</h2>
<p>Wow, so now we&#8217;ve got some appropriately sliced images, some layers and some animations. Let&#8217;s put them together to get the final effect.<br />
<div id="attachment_812" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock-300x96.png" alt="The animation states (last is same as first)" title="flipclock" width="300" height="96" class="size-medium wp-image-812" /></a><p class="wp-caption-text">The animation states (last is same as first)</p></div><br />
I&#8217;ve used a very simple state machine that moves through 3 states; TopToMiddle, MiddleToBottom, ResetForNext. We can use the <code>animationDidStop</code> delegate as the state transition point. We don&#8217;t have to bother determining exactly which animation finished, because we do the same thing (change state) regardless.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animationDidStop<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CAAnimation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>oldAnimation finished<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>flag
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self changeState<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<ul>
<li><strong>TopToMiddle</strong>: show flip layer, and start rotation through 90 degrees</li>
<li><strong>MiddleToBottom</strong>: change image on flip layer, start rotation through further 90 degrees</li>
<li><strong>ResetForNext</strong>: change displayed top and bottom layer contents and hide flip layer</li>
</ul>
<p>Let&#8217;s see how it looks in action:<br />
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/RbPmAl_AeSU&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RbPmAl_AeSU&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>iPad &#8211; The rise of the naturalistic user interface</title>
		<link>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/</link>
		<comments>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 01:05:53 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=679</guid>
		<description><![CDATA[Apple's iPad applications make use of real-world objects in their user interfaces: books, newspapers, address books. What is it about the iPad that makes it a good platform for this kind of UI?]]></description>
			<content:encoded><![CDATA[<p>It was fascinating to see Apple unveiling its new iPad hardware recently, and one of the things that caught my eye were the interfaces of the various apps that were demonstrated. They look different from apps on other platforms, and even from the equivalent apps on the iPhone. It seems to me as if there&#8217;s been a change to a more naturalistic style of user interfaces. Why is this, and what is it about the iPad that makes it suited to this kind of UI?<br />
<span id="more-679"></span></p>
<h2>Form factor</h2>
<p>The most obvious reason that this kind of interface works on the iPad is the form factor of the device itself. Think about it: an iPhone is a small (well, smallish) object which has no physical, real-world equivalent. It&#8217;s not supposed to &#8220;be&#8221; anything other than a phone. The iPad, on the other hand, is intended to mimic an actual object, or rather, a variety of objects: a book, a newspaper or an address book for example. The interface for each of these uses reflects this directly: the address book looks like a &#8220;little black book&#8221;, complete with tabs. </p>
<p>The iPhone uses some of the same metaphors &#8211; like the address book for contacts &#8211; but the representation is abstract, whereas the iPad UI is literal, using an actual image of a book. The abstraction is necessary on the iPhone in order for it to remain usable with a smaller screen. Compare the iPad and iPhone Contacts interfaces:</p>
<table>
<tr>
<td><div id="attachment_682" class="wp-caption alignnone" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/02/contacts_ipad_fullpage_small.png"><img src="http://www.voyce.com/wp-content/uploads/2010/02/contacts_ipad_fullpage_small-300x230.png" alt="The realistic looking address book application on the iPad" title="contacts_ipad_fullpage_small" width="300" height="230" class="size-medium wp-image-682" /></a><p class="wp-caption-text">The realistic looking address book application on the iPad</p></div>
</td>
<td><div id="attachment_684" class="wp-caption alignnone" style="width: 130px"><a href="http://www.voyce.com/wp-content/uploads/2010/02/contacts_iphone_small.png"><img src="http://www.voyce.com/wp-content/uploads/2010/02/contacts_iphone_small-156x300.png" alt="iPhone contacts interface" title="contacts_iphone_small" width="120" height="230" class="size-medium wp-image-684" /></a><p class="wp-caption-text">iPhone contacts interface</p></div></td>
</tr>
</table>
<p>The abstract to realistic continuum has been explored extensively in the world of icons (explained brilliantly <a href="http://ignorethecode.net/blog/2010/01/21/realism_in_ui_design/">here</a>), but less so in the interface as a whole. Obviously some apps don&#8217;t have any form of real world equivalent (think System Preferences.app), so they&#8217;re likely to stay in a more abstract form. </p>
<h2>Display fidelity</h2>
<p>Of course, it&#8217;s always been possible to <i>represent</i> real objects on the screen, but without a display capable of a decent resolution it probably won&#8217;t look real. So another enabler for naturalistic UI is display technology: the more pixels and colour depth the better when it comes to rendering physical things. Realism often relies on subtle lighting and rich textures to achieve the desired effect. Anyone who&#8217;s ever attempted to render wood grain using 8-bit colour will appreciate how much easier it is with a 32-bit 1024&#215;768 display. </p>
<p>The need for display quality goes hand-in-hand with a need for more processing power to push the pixels. If the processing &#8220;oomph&#8221; required to render your interface with sufficient quality means that it&#8217;s not responsive enough, then you&#8217;ve failed by any measure. The iPad seems to have reached a sweet spot where display capabilities, raw power and form-factor meet to make naturalistic UIs a feasible approach.   </p>
<h2>Direct manipulation</h2>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/03/Apple_Mouse_no.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/Apple_Mouse_no.png" alt="Apple_Mouse_no" title="Apple_Mouse_no" width="160" height="160" class="alignleft size-full wp-image-722" /></a>Up until the relatively recent introduction of direct manipulation technologies like touch-senstive displays, there&#8217;s a been a forced physical separation between users and their computer in the form of a mouse and keyboard. A drag operation using a mouse involves disconnected, abstract operations like pointing and clicking, which bear no relation to the object being acted upon. As such, there&#8217;s little use in having an extremely realistic representation of something to interact with, because the suspension-of-disbelief has already been broken. </p>
<p>But in the world of touch-based devices, our interactions are much closer to the physical actions we&#8217;d make, so having a closer visual representation to go along with it is beneficial. For instance, turning a page in an eBook and actually seeing the page flick over seems consistent when using a natural gesture like flicking a finger across the screen. Otherwise if you had to click a corner of the page and drag it across in a poor imitation of the physical action the visual aspects can quickly start to feel superfluous.   </p>
<p>Perhaps given the iPad&#8217;s larger interaction surface we can expect to see a wider and more expressive range of gestures supported?  </p>
<h2>History</h2>
<p>Of course, naturalistic UI isn&#8217;t really a new thing. It&#8217;s in use in quite a few applications already, albeit mostly in desktop apps, where capable hardware is more readily available. In fact, there was much a-twittering (not <i>all</i> of it from Will Shipley) about the similarity between the demo&#8217;d iPad apps and the interface of the fantastic Mac application <a href="http://delicious-monster.com/">Delicious Library</a>. I&#8217;m sure of course &#8211; how do they say it in the movie credits &#8211; the similarity is entirely coincidental&#8230;</p>
<table>
<tr>
<td valign="top"><div id="attachment_733" class="wp-caption alignnone" style="width: 303px"><img src="http://www.voyce.com/wp-content/uploads/2010/03/delicious_library_shrunk.png" alt="Delicious Library UI" title="delicious_library_shrunk" width="293" height="196" class="size-full wp-image-733" /><p class="wp-caption-text">Delicious Library UI</p></div></td>
<td><div id="attachment_734" class="wp-caption alignnone" style="width: 160px"><img src="http://www.voyce.com/wp-content/uploads/2010/03/ibooks_shrunk.png" alt="iBooks UI" title="ibooks_shrunk" width="150" height="199" class="size-full wp-image-734" /><p class="wp-caption-text">iBooks UI</p></div></td>
</tr>
</table>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/03/rebirth_knobs_crop.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/rebirth_knobs_crop.png" alt="rebirth_knobs_crop" title="rebirth_knobs_crop" width="250" height="110" class="alignleft size-full wp-image-717" /></a>One of the first widespread uses of naturalistic UI elements was in software synths. Guys like <a href="http://www.propellerheads.se/">Propellerheads</a> and <a href="http://www.native-instruments.com/">Native Instruments</a> set about creating exact software duplicates of well-known and well-loved bits of <a href="http://en.wikipedia.org/wiki/Roland_TB-303">mid-80&#8217;s audio hardware</a>. The UIs included virtual versions of a huge number of physical elements that had never been used before: including things like sliders, LEDs, toggle buttons, rotary knobs and rocker switches. These interface elements were probably first seen in software-based mixing desks, but the techniques used to make them feel real have gone on to be used in many different ways. Even the lowly push button in both Windows and MacOS got an upgrade by application of some of the 3D effects that they originated. </p>
<h2>Where Now?</h2>
<p>It will be interesting to see what other types of app are given the iPad realism makeover. It certainly looks like all of the standard Apple apps are being changed, including Notes, iCal, iBooks and Contacts, which were shown in the launch presentation, but how will 3rd-party developers manage? It undoubtedly takes extra effort to make something look convincing when it can be compared to the physical object itself. </p>
<p>Apple has previously managed to get a good level of consistency in its abstract UIs by providing the various interface elements ready-made, but will that approach scale to this kind of UI? No doubt the developers who take great pride in the interfaces now will continue to strive to create apps that sit comfortably alongside Apple&#8217;s own, but perhaps there&#8217;ll just be a more obvious visual distinction between those guys and the less polished application user interfaces than there has been in the past.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Highlights from onedotzero &#8211; wow+flutter</title>
		<link>http://www.voyce.com/index.php/2009/09/17/highlights-from-onedotzero-wowflutter/</link>
		<comments>http://www.voyce.com/index.php/2009/09/17/highlights-from-onedotzero-wowflutter/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:11:05 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[film]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=371</guid>
		<description><![CDATA[Some highlights from the onedotzero wow+flutter digital short film festival.]]></description>
			<content:encoded><![CDATA[<p>I took a trip down to London&#8217;s Southbank on Sunday evening to see wow+flutter, a showcase of short, digitally-themed animations that are part of <a href="http://www.onedotzero.com">onedotzero</a>, an annual festival and tour celebrating &#8220;adventures in moving image&#8221;. I&#8217;ve been several times before when it was based at the <a href="http://www.ica.org.uk/">ICA</a> (it&#8217;s now moved to the <a href="http://www.bfi.org.uk/whatson/bfi_southbank">BFI National Film Theatre</a>), and I always find it really inspiring. Normally, I can never remember the details of the films I&#8217;ve seen &#8211; it&#8217;s pretty intense; with over an hour of back-to-back shorts each lasting only 1-3 minutes &#8211; but this year they provided a list of the films details, so I can report on some of my highlights and provide links to some of the films.</p>
<p> <span id="more-371"></span></p>
<p>The wow+flutter programme concentrates on &#8220;progressive motion graphics&#8221;, which can include pretty much anything, while other parts of the festival are more specific: wavelength for music videos, j-star for japanese shorts etc. You can check out the entire list of w+f films are <a href="http://www.onedotzero.com/programme.php?id=373&#038;event=31216">here</a>, but these are my favourites:</p>
<p><b>Ubik: voxel</b><br />
I&#8217;m a fan of the augmented reality style when it&#8217;s done well; and it certainly is here. Striking abstract graphics combine with a haunting location.<br />
<object width="400" height="230"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4649345&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4649345&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="230"></embed></object></p>
<p><b>Impactist: Parallelostory</b><br />
A beautifully subtle animation style with a 50&#8217;s influenced colour and texture palette.<br />
<a href="http://www.impactist.com/projectpages/parallelostory/IMP_storyqt.html"><img src="http://www.voyce.com/wp-content/uploads/2009/09/IMPACTIST_para_still06-300x127.jpg" alt="IMPACTIST_para_still06" title="IMPACTIST_para_still06" width="300" height="127" class="alignleft size-medium wp-image-376" /></a><br />
<br clear="all"/></p>
<p><b>Bruno Dicolla: Return as an Animal</b><br />
This featured a striking high-contrast rotoscoped style that looked great on the big screen. Unfortunately the shimmering starfield effect is a little lost in the on-line version. I could almost hear art directors reaching for their iPhones to jot down &#8220;must copy this at next available opportunity&#8221;.<br />
<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=2022032&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=2022032&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object></p>
<p><b>Christian Schlaeffer: Agent Orange Ready</b><br />
A dark, disturbing animation in a comic style.<br />
<object width="853" height="505"><param name="movie" value="http://www.youtube.com/v/XbW486naKvk&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/XbW486naKvk&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object></p>
<h3>The Lows</h3>
<p>Ironically I found the most obviously &#8220;digital&#8221; films the most disappointing. There was a little too much in the Chris Cunningham inspired glitchy, razor-cut, super-shiny organic/mechanic vernacular. And there was also one film &#8211; which I won&#8217;t name &#8211; that looked shockingly like a Tia Maria commercial. Still, in general the signal to noise ratio was very good.</p>
<h3>The Laughs</h3>
<p>Some of the most memorable films are those with a punchline; the short film format is a great way of getting a laugh with a simple, funny idea. There&#8217;s no risk of stretching it too thin.</p>
<p><b>Mato Atom: Docking</b><br />
A laugh-out-loud concept executed nicely and succintly, and it even goes out with an anti-war punchline.<br />
<object width="853" height="505"><param name="movie" value="http://www.youtube.com/v/KqZnFiKE7aw&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/KqZnFiKE7aw&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object></p>
<p>So there you are; just 5 of the 30+ shorts that were shown. If you&#8217;re into animation or cutting-edge digital film-making, I&#8217;d recommend catching a onedotzero screening wherever you can, either in London or on one of the tour locations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/09/17/highlights-from-onedotzero-wowflutter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
