<?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; canvas</title>
	<atom:link href="http://jensarps.de/tag/canvas/feed/" rel="self" type="application/rss+xml" />
	<link>http://jensarps.de</link>
	<description></description>
	<lastBuildDate>Tue, 07 Sep 2010 14:11:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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>
		<item>
		<title>3D Canvas Walker revisited</title>
		<link>http://jensarps.de/2009/08/27/3d-canvas-walker-revisited/</link>
		<comments>http://jensarps.de/2009/08/27/3d-canvas-walker-revisited/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 20:01:26 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[Experiments in Web]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=12</guid>
		<description><![CDATA[One of the things that fascinated me most about computers since I was a teen, was their ability to simulate a three-dimensional space where one could move around in.
That&#8217;s why I was so intrigued when I read Jacob Seidelin&#8217;s post about “Creating pseudo 3D Games“. I had to play around with it, as I wanted ]]></description>
			<content:encoded><![CDATA[<div id="attachment_22" class="wp-caption alignleft" style="width: 160px"><a href="http://jensarps.de/wp-content/uploads/2009/08/walker-screenshot.jpg"><img class="size-thumbnail wp-image-22 " title="walker-screenshot" src="http://jensarps.de/wp-content/uploads/2009/08/walker-screenshot.jpg" alt="Screenshot" width="150" /></a><p class="wp-caption-text">Screenshot</p></div>
<p>One of the things that fascinated me most about computers since I was a teen, was their ability to simulate a three-dimensional space where one could move around in.</p>
<p>That&#8217;s why I was so intrigued when I read Jacob Seidelin&#8217;s post about “<a href="http://dev.opera.com/articles/view/creating-pseudo-3d-games-with-html-5-can-1/">Creating pseudo 3D Games</a>“. I had to play around with it, as I wanted to have mouse control in it, but performance was so bad that it was impossible. So I laid aside that idea. Eventually, he <a href="http://dev.opera.com/articles/view/3d-games-with-canvas-and-raycasting-part/">continued this project</a> and used it for something pretty awesome called “<a href="http://blog.nihilogic.dk/2008/07/wolfenflickr-3d-unlikely-mashup.html">WolfenFlickr</a>&#8220;, where you can walk around and look at Flickr photos, attached to walls. As I said, pretty awesome.</p>
<p>Anyway, what I wanted was mouse navigation and strafe keys, as you have it in shooters – this kind of moving around always gives me the feeling of being “free“ in a way. Experiencing that freedom in a web page (w/o flash, of course) was still on my mind.</p>
<p><span id="more-12"></span></p>
<p>And the I stumbled upon Ben Joffe&#8217;s <a href="http://www.benjoffe.com/code/demos/canvascape/textures">textured Canvascape 3D-Walker</a>. The performance of the canvas element drawing the image slices was better than letting the browser render single elements for each slice – much better. In fact, the idea of mouse control immeadiately popped up again and I had to give it a try. And – it worked! Of course it has some drawbacks (that is, when the cursor leaves the browser window, there&#8217;s no more control…), but it gave me that feeling of freedom while moving around!</p>
<p>Fooling around with the canvas element was fun and tought me about it&#8217;s image methods. And I hope to find more time to take it further…</p>
<p>Of course there&#8217;s an aweful lot of work ahead if one would want this to be pretty (it&#8217;s all bricks now, no interaction, perspective issues, no smooth movement on strafe, and so on…) and performance is still an issue with high-res textures, but it is a lot of fun moving around.</p>
<p>Here&#8217;s what I added to Ben Joffe&#8217;s Walker:</p>
<ul>
<li>mouse control</li>
<li>strafe movement</li>
<li>walk and crouch</li>
<li>high-res textures</li>
</ul>
<p>I dropped IE-Support for this and disabled the mini map for performance reasons.</p>
<p>You&#8217;ll need <a href="http://www.google.com/chrome" target="_blank">Chrome</a>/<a href="http://code.google.com/intl/de-DE/chromium/" target="_blank">Chromium</a> to see it in action in high details mode, but it&#8217;s definitely worth it!</p>
<p><a href="http://jensarps.de/tests/canvas/textures.html" target="_blank">Go give it try!</a> Move the mouse cursor into the center of your browser window, press “M“ and enjoy!</p>
<p>PS: Chromium builds for Mac can be found <a href="http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/">here</a>.</p>
<p>Note: The modifications are all just minor, all credits for this go out to <a href="http://www.benjoffe.com/">Ben Joffe</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2009/08/27/3d-canvas-walker-revisited/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
