<?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>Zack Lovatt</title>
	<atom:link href="http://zacklovatt.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zacklovatt.com</link>
	<description>Motion Design &#38; Compositing</description>
	<lastBuildDate>Sun, 13 May 2012 22:38:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Snapping to Hex Grid</title>
		<link>http://zacklovatt.com/2012/05/snapping-to-hex-grid/</link>
		<comments>http://zacklovatt.com/2012/05/snapping-to-hex-grid/#comments</comments>
		<pubDate>Fri, 11 May 2012 05:19:32 +0000</pubDate>
		<dc:creator>zack</dc:creator>
				<category><![CDATA[expressions]]></category>
		<category><![CDATA[hexagons]]></category>
		<category><![CDATA[position]]></category>

		<guid isPermaLink="false">http://zacklovatt.com/?p=355</guid>
		<description><![CDATA[The Idea So last year about this time I was doing some motion &#38; comp work for a pair of cinematics for a big ol&#8217; video game. One of my shots involved having these indicators moving across a screen with &#8230; <a href="http://zacklovatt.com/2012/05/snapping-to-hex-grid/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2 style="text-align: center;"><strong>The Idea</strong></h2>
<p>So last year about this time I was doing some motion &amp; comp work for a <a href="http://www.youtube.com/watch?v=7BHh3EwC1Pw">pair</a> of <a href="http://www.youtube.com/watch?feature=player_detailpage&amp;v=geyanyqPiWA#t=212s">cinematics</a> for a <a href="http://en.wikipedia.org/wiki/RAGE">big ol&#8217; video game</a>. One of my shots involved having these indicators moving across a screen with a hexagonal tile grid, and the art director wanted the indicators to snap from one tile to the next, giving it a much choppier, digital feel.</p>
<p>It took a while (longer than I&#8217;d care to admit, but alas) to get this expression put together. I won&#8217;t claim that it&#8217;s the best (or even most efficient) way, but if anyone has any suggestions on how I can optimize it please let me know!</p>
<p>&nbsp;</p>
<h2 style="text-align: center;"><strong>The Code</strong></h2>
<p></p><pre class="crayon-plain-tag">L = thisComp.layer(&quot;Control&quot;);
P = thisComp.layer(&quot;Motion Path - Hex&quot;);

xPos = P.transform.position[0];
yPos = P.transform.position[1];

cSize = L.effect(&quot;Cell Size&quot;)(&quot;Slider&quot;);
xOffset = L.effect(&quot;X Offset&quot;)(&quot;Slider&quot;);
yOffset = L.effect(&quot;Y Offset&quot;)(&quot;Slider&quot;);

// Convert size value into distance values between cells
cWidth = cSize*.75;
cHeight = cSize*13/15;

// Find new X and Y positions
yNew = yPos - yPos % cHeight + cHeight/2;
xNew = xPos - (xPos % cWidth) + (((yNew - cHeight/2).toFixed(2)/cHeight).toFixed(2) % 1) * (cWidth/2);

// Check for even/odd column, adjust properly
if (!(xNew % (cWidth*2) == 0)) yNew += cHeight/2;

// Implement offset
[xNew + xOffset, yNew+yOffset]</pre><p></p>
<h2 style="text-align: center;"></h2>
<p>&nbsp;</p>
<h2 style="text-align: center;"><strong>The Explanation</strong></h2>
<p>One thing to note is that this is using <a href="http://aescripts.com/yy_hextex/">YY_HexTex</a> by <a href="http://twitter.com/andrewYY">Andrew Yang</a> to generate the hexagonal grid. As such, it&#8217;s adapted specifically for it though it&#8217;s fairly easy to swap it out for a premade grid.</p>
<p>The way this works is by looking at the current position, snapping the values to the centre of a grid, then checking to see whether you&#8217;re in an even or odd column and adjusting the y-value again accordingly. At the very end, we add in the user-controlled offset so that our layer lines up with the grid properly.</p>
<p>Another thing to notice is that line 17 invokes two uses of <a href="http://zacklovatt.com/2012/03/limiting-decimal-points/">toFixed()</a>. If they&#8217;re not included, AE has trouble working with some really long decimals and the results tend to go a bit awry. This looks messy in the code, but it&#8217;s the only fix I could find.</p>
<h2 style="text-align: center;"></h2>
<p>&nbsp;</p>
<h2 style="text-align: center;"><strong>The Application</strong></h2>
<p style="text-align: left;"><img class="size-full wp-image-366 alignleft" style="margin: 10px;" title="Example__NoSnap" src="http://zacklovatt.com/wp-content/uploads/2012/05/Example__NoSnap.gif" alt="" width="150" height="150" /><img class="size-full wp-image-367 alignright" style="margin: 10px;" title="Example__Snap" src="http://zacklovatt.com/wp-content/uploads/2012/05/Example__Snap.gif" alt="" width="150" height="150" />To the left, you can see that without snapping, our snazzy little man will just spin around the path&#8211; that&#8217;s what  we&#8217;d expect.</p>
<p style="text-align: left;">To the right, Mr. Tieman will still follow the path, although now it&#8217;ll keep its movement constrained to the hex grid. Stay classy, Tieman.</p>
<p style="text-align: left;">This can be used for all sorts of FUI/interface work, as hex grids seem to be ubiquitous these days. Or, you know, for your latest and greatest Settlers of Catan fan vid, if you&#8217;re into that sort of thing.</p>
<p style="text-align: left;">If you want to use this on a 3d layer, it&#8217;ll take some rejigging to get it to put together, but it should prove an adequate challenge for anyone familiar with expression work.</p>
<h2></h2>
<h2 style="text-align: center;"></h2>
<p>&nbsp;</p>
<h2 style="text-align: center;"><strong>The AEP</strong></h2>
<p>Here’s the link: <a onclick="ss_te(event,1)" href="http://work.zacklovatt.com/blog/aep/ZL_SnapToHex.zip">ZL_SnapToHex.zip</a> (22kb). This was created in CS5.5, but I saved out a CS5 version and included it in the zip.</p>
<p>Once you have it open, play with the &#8220;Control&#8221; layer sliders to explore different results. You&#8217;ll have to adjust the offset values to fit the grid properly.</p>
<p><strong>This AEP requires <a href="http://aescripts.com/yy_hextex/">YY_HexTex</a> to work.</strong> If you&#8217;re interested in a plugin-free solution, leave a comment or email me and I&#8217;ll set something up.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://zacklovatt.com/2012/05/snapping-to-hex-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Points Along a Line</title>
		<link>http://zacklovatt.com/2012/04/points-along-a-line/</link>
		<comments>http://zacklovatt.com/2012/04/points-along-a-line/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 22:27:37 +0000</pubDate>
		<dc:creator>zack</dc:creator>
				<category><![CDATA[expressions]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[position]]></category>

		<guid isPermaLink="false">http://zacklovatt.com/?p=305</guid>
		<description><![CDATA[Things have been busy! I&#8217;m working on several cool projects at the moment, one of which led me to share some cool math with you guys. I&#8217;ve got two expressions that produce similar (yet different!) results&#8211; both define the position &#8230; <a href="http://zacklovatt.com/2012/04/points-along-a-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Things have been busy! I&#8217;m working on several cool projects at the moment, one of which led me to share some cool math with you guys.</p>
<p>I&#8217;ve got two expressions that produce similar (yet different!) results&#8211; both define the position for a point along a line, though one is controlled by % completion from one point to the next (0-1), the other by the distance (in pixels) from the start point.</p>
<p>Here&#8217;s the code.</p>
<h1 style="text-align: center;"><span style="text-decoration: underline;"><strong>% Along A Line</strong></span></h1>
<p style="text-align: center;"><a href="http://zacklovatt.com/wp-content/uploads/2012/04/PointAlongLine_Percentage.gif"><img class="size-full wp-image-309 aligncenter" title="PointAlongLine_Percentage" src="http://zacklovatt.com/wp-content/uploads/2012/04/PointAlongLine_Percentage.gif" alt="" width="350" height="100" /></a></p>
<p></p><pre class="crayon-plain-tag">p1 = thisComp.layer(&quot;Point_01&quot;).transform.position;
p2 = thisComp.layer(&quot;Point_02&quot;).transform.position;
mult = thisComp.layer(&quot;HELPER&quot;).effect(&quot;Percent&quot;)(&quot;Slider&quot;);

p1 + mult * (p2-p1);</pre><p></p>
<p style="text-align: left;">The first three lines are just setting up our links; first to the points, then to our controller. The math here is that last line. This is essentially taking the the line as a vector, scaling its length based on the multiplier, then moves it to the first point.</p>
<p>&nbsp;</p>
<h1 style="text-align: center;"><span style="text-decoration: underline;"><strong>Distance Along A Line</strong></span></h1>
<p style="text-align: center;"><a href="http://zacklovatt.com/wp-content/uploads/2012/04/PointAlongLine_Distance.gif"><img class="size-full wp-image-310 aligncenter" title="PointAlongLine_Distance" src="http://zacklovatt.com/wp-content/uploads/2012/04/PointAlongLine_Distance.gif" alt="" width="350" height="100" /></a></p>
<p></p><pre class="crayon-plain-tag">p1 = thisComp.layer(&quot;Point_01&quot;).transform.position;
p2 = thisComp.layer(&quot;Point_02&quot;).transform.position;
mult = thisComp.layer(&quot;HELPER&quot;).effect(&quot;Distance&quot;)(&quot;Slider&quot;);

p1 + mult*(p2-p1)/length(p1,p2);</pre><p>In this example, we&#8217;re normalizing the vector by dividing it by its length so that it uses units / pixels as opposed to %. This way we can have a point, say, 200 pixels away from another, along a line.</p>
<p>&nbsp;</p>
<p>In the first example, our new point moves relative to the other two, whereas the distance-based on will always be that same distance along the line, regardless of how close or far the lines are. Without any sort of limiting, your points in both examples can go beyond either point along that same line&#8211; I&#8217;ve included a solution for this in my AEP, but that&#8217;s just one way to do it.</p>
<p>Here’s the link: <a onclick="ss_te(event,1)" href="http://work.zacklovatt.com/blog/aep/PointAlongLine.aep">PointAlongLine.aep</a> (406kb)</p>
]]></content:encoded>
			<wfw:commentRss>http://zacklovatt.com/2012/04/points-along-a-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>toFixed() &#8211; Limiting decimal points</title>
		<link>http://zacklovatt.com/2012/03/limiting-decimal-points/</link>
		<comments>http://zacklovatt.com/2012/03/limiting-decimal-points/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 02:29:51 +0000</pubDate>
		<dc:creator>zack</dc:creator>
				<category><![CDATA[expressions]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://zacklovatt.com/?p=273</guid>
		<description><![CDATA[So, I wrote this up a month ago but forgot to post it. Whoops. &#8211; 05/03/12 In today&#8217;s thrilling post I&#8217;m going to cover how to limit the number of digits after a decimal while working with expressions. While I &#8230; <a href="http://zacklovatt.com/2012/03/limiting-decimal-points/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>So, I wrote this up a month ago but forgot to post it. Whoops. &#8211; 05/03/12<br />
</em></p>
<p>In today&#8217;s thrilling post I&#8217;m going to cover how to limit the number of digits after a decimal while working with expressions. While I know of a few ways to go about doing this, I&#8217;m going to cover the <strong>toFixed</strong> method.</p>
<blockquote><p>(As an aside, another option is <strong>toPrecision()</strong> which limits the number of <a href="http://en.wikipedia.org/wiki/Significant_digits">significant digits</a>, but the practical applications of using over <strong>toFixed()</strong> are few and far.)</p></blockquote>
<p>So. Simply,<strong> toFixed(<em>x</em>)</strong> limits the number of digits <em></em>to after its decimal point to <strong><em>x</em></strong>, by rounding up; let&#8217;s take a look, using random. I&#8217;m going to give sample results, by the way, for the sake of showing examples.</p><pre class="crayon-plain-tag">random(1);
// Result: 0.66781947055548</pre><p>We&#8217;ve got a really long number here, and that&#8217;s damned unseemly. Let&#8217;s say you were doing some interface work and needed a number to change every frame&#8211; this <em>probably</em> wouldn&#8217;t work. Too many digits! Don&#8217;t worry&#8211; that&#8217;s where <strong>toFixed()</strong> comes in.</p><pre class="crayon-plain-tag">random(1).toFixed(3);
// Result: 0.668</pre><p>See, now that we&#8217;ve added toFixed, and told it to limit the result to 3 digits post-decimal, our result looks much, much cleaner.</p>
<p>This doesn&#8217;t just work with random numbers, though! Pretty much any number can be shortened this way.</p><pre class="crayon-plain-tag">// position is [967.337125645, 541]
transform.position[0].toFixed(3);
// Result: 967.337</pre><p>That&#8217;s all I really wanted to go over for today&#8211; if you&#8217;ve got any questions about this stuff, feel free to leave a comment / send an email!</p>
]]></content:encoded>
			<wfw:commentRss>http://zacklovatt.com/2012/03/limiting-decimal-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>For / While Loops</title>
		<link>http://zacklovatt.com/2012/02/for-while-loops/</link>
		<comments>http://zacklovatt.com/2012/02/for-while-loops/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 19:10:26 +0000</pubDate>
		<dc:creator>zack</dc:creator>
				<category><![CDATA[expressions]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[loops]]></category>

		<guid isPermaLink="false">http://zacklovatt.com/?p=268</guid>
		<description><![CDATA[In class yesterday, one of my students asked about using for / while loops in expressions. As this isn&#8217;t something I&#8217;ve had to use before, I spent the evening playing around with it. The main concern is that AE evaluates &#8230; <a href="http://zacklovatt.com/2012/02/for-while-loops/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In class yesterday, one of my students asked about using for / while loops in expressions. As this isn&#8217;t something I&#8217;ve had to use before, I spent the evening playing around with it.</p>
<p>The main concern is that AE evaluates the entire expression at every frame&#8211; there&#8217;s no persistence. So any for or while loop will run through in its entirety <em>per frame</em>. If you tried, say, to execute some code while the time is less than 1 second:</p><pre class="crayon-plain-tag">while (time &amp;lt; 1){
&nbsp;&nbsp; &nbsp;// code
}</pre><p>You&#8217;d find AE caught in an infinite loop&#8211; on the first frame of your comp, the time will ALWAYS be less than 1 second in&#8211; and so it&#8217;ll time out. From my poking about online, the majority of uses seem to be accumulating data from prior frames.</p>
<p>I&#8217;ve created a mockup of how this works. It counts (and displays) the number of frames a layer is spent above [note: I mean <em>above</em> visually, not greater-than or less-than] a certain y-value. While not the most practical thing around, it should give you a good sense of how to use it.</p>
<p>Here&#8217;s the code:</p><pre class="crayon-plain-tag">L = thisComp.layer(&quot;STAR POWER&quot;);
curFrame = 0;
hitCount = 0;

while (curFrame &amp;lt;= timeToFrames(time)){
&nbsp;&nbsp; &nbsp;if (L.transform.position.valueAtTime(framesToTime(curFrame))[1] &amp;lt;= 300){
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;hitCount++;
&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;curFrame++;
}

hitCount</pre><p>Let&#8217;s break it down.</p>
<p><a href="http://zacklovatt.com/wp-content/uploads/2012/02/ForWhileDo.gif"><img class="size-full wp-image-279 alignright" style="margin: 0px 0px 15px 15px;" title="ForWhileDo" src="http://zacklovatt.com/wp-content/uploads/2012/02/ForWhileDo.gif" alt="" width="150" height="150" /></a>First, we establish the target layer (&#8220;STAR POWER&#8221;), and we create a variable for the hit count (the number of times the layer goes above 300), and another for the iterations of the loop.</p>
<p>We then create the while loop. It keeps incrementing the counter until it&#8217;s at the same frame the comp is currently on– that&#8217;s how it runs.</p>
<p>Inside that loop, it looks at the the position of the target layer at all previous frames, and if the y-value is above 300, it increments the hit counter and displays that.</p>
<p>If you were so inclined, you could rewrite the same loop as either a <em>for</em> loop or a <em>do while</em> loop. Below you&#8217;ll find a link to download an AEP with comps containing <em>all three for the price of none</em>!</p>
<p>&nbsp;</p>
<p>Here&#8217;s the link: <a onclick="ss_te(event,1)" href="http://work.zacklovatt.com/blog/aep/ForWhileDo.aep" target="_blank">ForWhileDo.aep</a> (352kb)</p>
]]></content:encoded>
			<wfw:commentRss>http://zacklovatt.com/2012/02/for-while-loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Post!</title>
		<link>http://zacklovatt.com/2012/01/first-post/</link>
		<comments>http://zacklovatt.com/2012/01/first-post/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 03:25:31 +0000</pubDate>
		<dc:creator>zack</dc:creator>
				<category><![CDATA[meta]]></category>

		<guid isPermaLink="false">http://zacklovatt.com/?p=159</guid>
		<description><![CDATA[Hi there! New site, new reel, new blog. This space will mostly be used to showcase AE expressions that I&#8217;ve written and/or adapted for my use, and to discuss projects and problems I&#8217;m working. With that in mind, I&#8217;ll try &#8230; <a href="http://zacklovatt.com/2012/01/first-post/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi there!</p>
<p>New <a href="http://zacklovatt.com">site</a>, new <a href="http://vimeo.com/zlovatt/reel">reel</a>, new <a href="http://zacklovatt.com/blog/">blog</a>.</p>
<p>This space will <em>mostly</em> be used to showcase AE expressions that I&#8217;ve written and/or adapted for my use, and to discuss projects and problems I&#8217;m working.</p>
<p>With that in mind, I&#8217;ll try to release AEPs with anything I discuss.</p>
<p>If there&#8217;s anything you&#8217;d like to see covered (expressions or otherwise), let me know in a comment or <a href="zack@zacklovatt.com">email</a> and I&#8217;ll try to get to it as soon as possible!</p>
<p>As ever, feedback&#8217;s welcome.</p>
<p>&nbsp;</p>
<p>Zack</p>
]]></content:encoded>
			<wfw:commentRss>http://zacklovatt.com/2012/01/first-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

