<?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>Jens Arps &#187; animation</title>
	<atom:link href="http://jensarps.de/tag/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://jensarps.de</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 16:16:34 +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>Working with the Curve &#8211; Advanced Animation with Dojo</title>
		<link>http://jensarps.de/2010/01/22/working-with-the-curve-advanced-animation-with-dojo/</link>
		<comments>http://jensarps.de/2010/01/22/working-with-the-curve-advanced-animation-with-dojo/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 21:03:16 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[Dojo Love]]></category>
		<category><![CDATA[Experiments in Web]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[dojox]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=170</guid>
		<description><![CDATA[If you use animations, you probably use them to animate CSS properties. But this post is about some real bareknuckle animation – using the dojo toolkit. We&#8217;ll have a look into dojo.Animation and talk about the curve, the line, easing and rate, and we&#8217;ll check out (the somehow undocumented) dojox.fx._core – and see how to [...]]]></description>
			<content:encoded><![CDATA[<p>If you use animations, you probably use them to animate CSS properties. But this post is about some <em>real bareknuckle animation</em> – using the dojo toolkit. We&#8217;ll have a look into dojo.Animation and talk about the curve, the line, easing and rate, and we&#8217;ll check out (the somehow undocumented) dojox.fx._core – and see how to work with multidimensional lines.</p>
<p><span id="more-170"></span></p>
<p><strong>The Curve</strong></p>
<p>Every dojo.Animation needs a curve. If you call <code>animateProperty</code> or it&#8217;s shorthand <code>anim</code>, you don&#8217;t have to provide the curve for yourself, dojo will do it for you – if you build an animation using <code>new dojo.Animation()</code>, you have to provide your own curve. You can think of the curve as of a line that the animation walks on. The line is already present before the animation starts to walk it, and it can always take a break and pause in the middle and eventually continue walking where it had stopped. To create a curve, you need to call <code>new dojo._Line(start, end)</code>. In return, you get an object with three properties: <code>end</code>, <code>start</code> and a <code>getValue()</code> method.</p>
<pre>var anim = new dojo.Animation({
	curve: new dojo._Line(0,100)
});</pre>
<p><strong>Easing</strong></p>
<p>The curve will then be modified by a easing function. By default, this is the linear <code>dojo._defaultEasing</code>. Easing breathes a bit of life into the curve, you can say. Other properties of dojo.Animation that affect the curve are <code>rate</code> and <code>duration</code>. <code>rate</code> is the timespan between two frames. To calculate the targeted fps, use <code>(1000/rate)</code>. By default, dojo aims at 50 fps.</p>
<pre>var anim = new dojo.Animation({
	curve: new dojo._Line(0,100),
	easing: dojo.fx.easing.quadInOut
});</pre>
<p><strong>Waking Life</strong></p>
<p>To get some numbers out of <code>dojo.Animation</code>, let&#8217;s let it go wild and <code>play()</code>. When using <code>animateProperty</code> or the likes, you just fire and forget. In our case, we need to get the numbers. To achieve this, we connect to our animation&#8217;s <code>onAnimate</code> event. This is fired on every frame of the animation. When your connected function is called, you get – who would have guessed – the current value of the curve. Now you have a function called at a given rate, for a given period of time and you get get a numeric value that is already calculated for you. Decent!</p>
<pre>dojo.connect(anim,'onAnimate',function(curveValue){
	// do something
});</pre>
<p>To see some curves in action, go to <a href="http://jensarps.de/tests/dojo_tests/animation.html" target="_blank">this test page</a>, open the console and type <code>play(1);</code> and <code>play(2);</code> and check the source code to see what&#8217;s happening.</p>
<p><strong>Multidimensional Curves</strong></p>
<p><code>dojo._Line</code> generates only one-dimensional curves. But, there is <code>dojox.fx._core</code>, which contains an (old) version of <code>dojox.fx._Line</code>, which is capable of creating multi-dimensional curves. To use it, you have to explicitely <code>dojo.require("dojox.fx._core")</code>. It&#8217;s a bit odd, but the _core file contains only the _Line, and it is not loaded when requiring &#8220;dojox.fx&#8221;. Well, whatever, you can pass arrays of numbers into <code>dojox.fx._Line</code>:</p>
<pre>new dojox.fx._Line([0,2],[100,6]);</pre>
<p>Now you have a multi-dimensional curve. Or, if you could say, you have two curves in one. You can (technically) pass an unlimited amount of numbers into <code>dojox.fx._Line</code>. When you hand this curve to a <code>dojo.Animation</code>, it will animate all dimensions of the curve. And it will modify all dimensions of the curve according to easing, rate and duration. If you connect a function to <code>onAnimate</code>, it will now recieve an array of numbers.</p>
<pre>var anim = new dojo.Animation({
	curve: new dojox.fx._Line([0,2],[100,6]),
	easing: dojo.fx.easing.quadInOut
});</pre>
<p>Head over to the <a href="http://jensarps.de/tests/dojo_tests/animation.html">test page</a> again, and type <code>play(3);</code> into the console. Now, the width of the bars is also animated – by the same animation function that calculates the height of the bars.</p>
<p><strong>What now?</strong></p>
<p>If your mind is still not blown away with ideas about how to use this, let me give you a start:</p>
<ul>
<li>animate position, width and height of a browser window and use it as a screensaver for some unknowing, yet thankful visitor…</li>
<li>take some CSS 2D and 3D transisitions/transforms and animate away…</li>
<li>canvas! No need to say another word…</li>
<li>Still too banal? Go WebGL! Grab some 3DContext and animate an evil ball of jelly jumping around!</li>
</ul>
<p>In short: dojo&#8217;s animation system allows you to not only animate CSS properties, but gives you a good tool for  animations in general. You get the curves on the one hand, but you also get the &#8220;player&#8221; for these curves, including play/pause/stop/gotoPercent methods. And dojo.fx.easing has a lot of easing functions in stock.</p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2010/01/22/working-with-the-curve-advanced-animation-with-dojo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

