<?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>radikalFX &#187; HTML5</title>
	<atom:link href="http://radikalfx.com/tag/html5/feed/" rel="self" type="application/rss+xml" />
	<link>http://radikalfx.com</link>
	<description>In full FX</description>
	<lastBuildDate>Tue, 27 Dec 2011 11:44:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Animated website background with HTML5</title>
		<link>http://radikalfx.com/2009/10/17/html5-animated-background/</link>
		<comments>http://radikalfx.com/2009/10/17/html5-animated-background/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 13:05:04 +0000</pubDate>
		<dc:creator>cra5h</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://radikalfx.com/?p=83</guid>
		<description><![CDATA[After fooling around with some of the basic HTML5 Canvas features for my previous post, I decided to also work out some other ideas I had. Today I started implementing a simple animated background for a website.]]></description>
			<content:encoded><![CDATA[<p>After fooling around with some of the basic HTML5 Canvas features for my previous post, I decided to also work out some other ideas I had. Today I started implementing a simple animated background for a website.</p>
<div class="center">
<a href="/files/anibg/"><img src="http://radikalfx.com/wp-content/uploads/2009/10/anibg_screen.png" alt="Animated webpage background with HTML5"/></a><br />
<a href="/files/anibg/">Click here for the <strong>demo</strong></a>
</div>
<p><br/></p>
<p><strong>Using a Canvas Object as a background</strong><br />
Before actually getting to the animating of the background, I first had to setup Canvas as a background object. In order to do this. I have added the Canvas element in an absolute positioned div that is aligned to the top of the page. The reason for using a div around the Canvas is because the browsers don&#8217;t seem to want to put the Canvas in page at 100% without creating scrollbars.</p>
<p>After placing the background a div can be placed on top. When this div is created with a max-height of 100% and overflow set to auto. This layer will automatically give a scrollbar when necessary.</p>
<p>So that leaves us with the following HTML and CSS code:<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;body&gt;
	 &lt;div id=&quot;backgroundHolder&quot;&gt;
	 	 &lt;canvas id=&quot;backgroundCanvas&quot; width=&quot;800&quot; height=&quot;600&quot;&gt;&lt;/canvas&gt;
	 &lt;/div&gt;
	 &lt;div id=&quot;realbody&quot;&gt;
	 	 &lt;!-- Content --&gt;
	 &lt;/div&gt;
&lt;/body&gt;</pre></div></div>

<p>CSS:<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#backgroundHolder</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#realbody</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">max-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
canvas <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>Let the browser resize the Canvas</strong><br />
When I created the first setup for this demo. I started by setting the height and width of the Canvas to the height and width of the page. This soon turned out to be quite heavy on the CPU usage at higher resolutions. So I made the Canvas a static size and let the browser resize the area to 100%. This works and performs way better. And because the animated content is abstract it does not really matter that we loose the aspect ratio.</p>
<p>Once you have setup the Canvas behind the page. You can draw whatever you want in this Canvas and it will render behind the normal content in the browser.</p>
<p><strong>How to animate the background</strong><br />
Now that we have done the setup for the page, we can start to animate. I created some really simple code which doesn&#8217;t do very proper checking on the boundaries. It basicly switches 3 variables around to make the background animated: move the bars from right to left, change the rotation of the Canvas context from (&#960; / 32) to -(&#960; / 32), and fade the color between an array of colors.</p>
<p><strong>Drawing the bars</strong><br />
The bars are just drawn rectangles which are drawn a little bit above the canvas till a little bit below the Canvas, this is because of the rotation. In order to draw the bars I use the following code:<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> leftOffset<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">600</span><span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>BAR_WIDTH <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	context.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>canvas.<span style="color: #660066;">width</span> <span style="color: #009966; font-style: italic;">/ 2), 0 - (canvas.height /</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> BAR_WIDTH<span style="color: #339933;">,</span> canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
leftOffset <span style="color: #339933;">-=</span> BAR_SPEED<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>leftOffset <span style="color: #339933;">+</span> BAR_WIDTH <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">300</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	leftOffset <span style="color: #339933;">+=</span> BAR_WIDTH <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The BAR_SPEED is to move the initial leftOffset to the left all the time. Up till it reaches a certain value. Then the leftOffset is scaled up a little so that we don&#8217;t create more and more bars over time. The starting point of the context.fillRect might seem a bit weird. This is because the Canvas is translated to the center. So the starting point for drawing a bar is minus the width of the Canvas area.</p>
<p><strong>Rotating the bars</strong><br />
Rotating the bars is even simpler then the drawing of them. We can just use the context.rotate function to set the rotation of the content that we are drawing. Keep in mind that you might want to save the context state before rotating so you can restore it after the rotation. The JavaScript code for rotating is the following:<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">context.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">rotate</span><span style="color: #009900;">&#40;</span>angle <span style="color: #339933;">+=</span> angleAdjust<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Draw your content here</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>angle <span style="color: #339933;">&gt;</span> MAX_ANGLE <span style="color: #339933;">||</span> angle <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">-</span> MAX_ANGLE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	angleAdjust <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">-</span> angleAdjust<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the example above MAX_ANGLE is set to &#960; / 32. The variable angleAdjust is used to make sure that we either increase the angle or decrease the angle.</p>
<p><strong>Switching the colors</strong><br />
The effect to finish the whole thing of, is the switching of colors. For this demo I am using 6 colors that I just guessed some RGB values for. Blending the colors is done with this Color object in JavaScript:<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Color<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span>g<span style="color: #339933;">,</span>b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">r</span> <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">g</span> <span style="color: #339933;">=</span> g<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">b</span> <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">step</span> <span style="color: #339933;">=</span> COLOR_STEP<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">fadeTo</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>color<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">r</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">r</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color.<span style="color: #660066;">r</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">r</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">g</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">g</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color.<span style="color: #660066;">g</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">g</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">b</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">b</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>color.<span style="color: #660066;">b</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">b</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">step</span> <span style="color: #339933;">+=</span> COLOR_STEP<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">r</span> <span style="color: #339933;">==</span> color.<span style="color: #660066;">r</span> <span style="color: #339933;">&amp;&amp;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">g</span> <span style="color: #339933;">==</span> color.<span style="color: #660066;">g</span> <span style="color: #339933;">&amp;&amp;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">b</span> <span style="color: #339933;">==</span> color.<span style="color: #660066;">b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">step</span> <span style="color: #339933;">=</span> COLOR_STEP<span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getRGB</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">r</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;,&quot;</span> <span style="color: #339933;">+</span>
				Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">g</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;,&quot;</span> <span style="color: #339933;">+</span>
				Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Every time the fadeTo method is called, the color that is used will blend more to the color provided as an argument to the fadeTo method. If color provided as a parameter is the same as the color. Then this method will return true so the rest of the code can start providing another color to blend to.</p>
<p>The code to start running through the array of colors then becomes something like this:<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>activeColor.<span style="color: #660066;">fadeTo</span><span style="color: #009900;">&#40;</span>colors<span style="color: #009900;">&#91;</span>nextColorIndex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	activeColor <span style="color: #339933;">=</span> colors<span style="color: #009900;">&#91;</span>nextColorIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nextColorIndex <span style="color: #339933;">&gt;=</span> colors.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		nextColorIndex <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
context.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'rgb('</span> <span style="color: #339933;">+</span> activeColor.<span style="color: #660066;">getRGB</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #339933;">;</span></pre></div></div>

<p>After setting this demo up today, I have to conclude that doing animations like this is really not that difficult. I think within the next few months we will see more and more awesome website implementations with Canvas. </p>
]]></content:encoded>
			<wfw:commentRss>http://radikalfx.com/2009/10/17/html5-animated-background/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Dynamic image collage with HTML5 and Canvas</title>
		<link>http://radikalfx.com/2009/10/16/canvas-collage/</link>
		<comments>http://radikalfx.com/2009/10/16/canvas-collage/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 21:43:05 +0000</pubDate>
		<dc:creator>cra5h</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://radikalfx.com/?p=62</guid>
		<description><![CDATA[There is an update to this post that adds text support to the collage: http://radikalfx.com/2011/12/12/text-addition-for-image-collage-with-html5-and-canvas/ In the last couple of months the hype around web technology has really started to heat up. The HTML5 standard is getting a lot of attention from all major browser manufacturers and all my favorite browsers are starting to support [...]]]></description>
			<content:encoded><![CDATA[<div style="margin: 10px; padding: 10px; border: 2px solid red;">There is an update to this post that adds text support to the collage: <a href="http://radikalfx.com/2011/12/12/text-addition-for-image-collage-with-html5-and-canvas/">http://radikalfx.com/2011/12/12/text-addition-for-image-collage-with-html5-and-canvas/</a></div>
<p>In the last couple of months the hype around web technology has really started to heat up. The <a href="http://www.whatwg.org/specs/web-apps/current-work/">HTML5 standard</a> is getting a lot of attention from all major browser manufacturers and all my favorite browsers are starting to support all the nice new features coming in HTML5.</p>
<p>One of my favorite new features is Canvas, prime reason being my hope to finally make Flash obsolete, sorry Adobe. Because I wanted to check out the capabilities of Canvas, I decided to start coding some simple projects with Canvas.</p>
<div class="center">
<a href="/files/collage/demo.html"><img src="http://radikalfx.com/wp-content/uploads/2009/10/screen.png" alt="HTML5 Canvas Collage"/></a>
</div>
<p><br/></p>
<p>My first demo is a simple Canvas element which can be used to make a collage of images. <a href="/files/collage/demo.html">The <strong>demo</strong> can be found here.</a>, <em>you will need a Canvas compatible browser</em>.</p>
<p><strong>What does it do</strong><br />
The <a href="/files/collage/demo.html">demo</a> lets you search for images from <a href="http://www.flickr.com">Flickr</a>. When you have searched for some images, you can click any of the images there to add them to the Canvas part of the page. When the image is added to the Canvas then it&#8217;s automatically created as a new layer. Each layer can be manipulated in the following ways: move, scale, rotate, move layer up and down, remove layer, change opacity, change blending mode and enable or disable shadow.</p>
<p>The layout is a bit similar to image edit software, which I think is quite simple to understand. The code might still contain some bugs and do some unexpected things. <em>Rotating images and then scaling makes the whole thing kinda whobly!</em></p>
<p><strong>How does it work</strong><br />
The JavaScript code for this demo is split up into two parts. The first is a library that loads in all the proper calls for the Canvas element and that gives the page the ability to modify the layers in the collage. The second part of the JavaScript code, is the code to handle all the page interaction and to bind the HTML controls for the layers. I won&#8217;t go into the code for the user controls. But the canvas control might be interesting:<br />
<br/></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jCollage <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Collage<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#collage&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Create new collage Object with id of the Canvas tag</span>
&nbsp;
jCollage.<span style="color: #660066;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#fff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Set background color of collage</span>
jCollage.<span style="color: #660066;">setBackgroundImage</span><span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Set background image for the collage</span>
&nbsp;
jCollage.<span style="color: #660066;">redraw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Force redraw the collage</span>
&nbsp;
jCollage.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Add a new layer to the collage</span>
jCollage.<span style="color: #660066;">getLayer</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Get layer by id</span>
jCollage.<span style="color: #660066;">getLayers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Get Array if all layers</span>
jCollage.<span style="color: #660066;">removeLayer</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Remove layer based on id</span>
&nbsp;
jCollage.<span style="color: #660066;">moveLayerUp</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Move layer up in the array</span>
jCollage.<span style="color: #660066;">moveLayerDown</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Move layer down in the array</span>
&nbsp;
layer.<span style="color: #660066;">isVisible</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Is layer visible</span>
layer.<span style="color: #660066;">toggleVisible</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Toggle visibility</span>
layer.<span style="color: #660066;">hasShadow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Does layer have shadow</span>
layer.<span style="color: #660066;">toggleShadow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Toggle shadow</span>
layer.<span style="color: #660066;">setShadow</span><span style="color: #009900;">&#40;</span>boolean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Set shadow</span>
layer.<span style="color: #660066;">getOpacity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Get opacity of layer</span>
layer.<span style="color: #660066;">setOpacity</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Set opacity of layer</span>
layer.<span style="color: #660066;">getCompositeOperation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Set the composite operation</span>
layer.<span style="color: #660066;">setCompositeOperation</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Get the composite operation</span></pre></div></div>

<p>You can find the JavaScript code for this <a href="/files/collage/jcollage.js">here</a>. I might one day work this out as a jQuery plugin, but don&#8217;t know if that will be worth the extra effort.</p>
<p><strong>Conclusion</strong><br />
Getting up to speed on the Canvas element is quite easy and the information for the HTML5 standard is already enough to get you going. Because a lot of people have already been working with this feature, it&#8217;s also very simple to find more detailed information about problems and how to solve them.</p>
<p>The most difficult thing to get going was handling the collision interaction with the Objects, because I couldn&#8217;t use the normal mouse events based on the DOM. I had to figure out the math behind the collisions myself, this code is not very pretty. But after getting this demo running, I have to say that it was not very difficult to code and Canvas is definitely going into a direction were it could replace Flash functionality. I just hope that Internet Explorer starts supporting it some time soon as well!</p>
]]></content:encoded>
			<wfw:commentRss>http://radikalfx.com/2009/10/16/canvas-collage/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

