<?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>Mon, 13 Feb 2012 18:28:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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>while (time &lt; 1){
    // 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 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>L = thisComp.layer("STAR POWER");
curFrame = 0;
hitCount = 0;

while (curFrame &lt;= timeToFrames(time)){
    if (L.transform.position.valueAtTime(framesToTime(curFrame))[1] &lt;= 300){
        hitCount++;
    }
    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 goves 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/zld/ForWhileDo.aep" target="_blank">ForWhileDo.aep</a> (229kb)</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>

