<?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>Official Steve Kane Music Site and Web Development Ideas</title>
	<atom:link href="http://stevekane.com.au/feed/" rel="self" type="application/rss+xml" />
	<link>http://stevekane.com.au</link>
	<description>Songs and web development ideas from Steve Kane</description>
	<lastBuildDate>Tue, 07 Feb 2012 08:42:40 +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>HTML5 Canvas Throw Physics</title>
		<link>http://stevekane.com.au/2011/03/html5-canvas-throw-physics/</link>
		<comments>http://stevekane.com.au/2011/03/html5-canvas-throw-physics/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 12:17:44 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Event Listeners]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Throw Physics]]></category>

		<guid isPermaLink="false">http://stevekane.com.au/?p=249</guid>
		<description><![CDATA[Here&#8217;s a little fun one that I made this evening. I&#8217;ve used some Flash code that I found and turned it into JS. Every time I do one of these I realise how much easier things are in ActionScript. But that&#8217;s not why I&#8217;m doing it of course! Still not working 100% in IE. excanvas.js ]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little fun one that I made this evening. I&#8217;ve used some Flash code that I found and turned it into JS. Every time I do one of these I realise how much easier things are in ActionScript. But that&#8217;s not why I&#8217;m doing it of course! Still not working 100% in IE. excanvas.js is doing its job and getting the canvas element plus the bouncing ball to show up in IE8, however it&#8217;s not playing nicely with the event listeners. Will explore it in more detail soon. Pun intended.</p>
<p>Anyway, here is what I have so far:</p>
<p><a href="http://www.stevekane.com.au/test/canvas/throw.html">http://www.stevekane.com.au/test/canvas/throw.html</a></p>
<p>- Stevo</p>
]]></content:encoded>
			<wfw:commentRss>http://stevekane.com.au/2011/03/html5-canvas-throw-physics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Canvas &#8211; Angle bounce using some rotational maths</title>
		<link>http://stevekane.com.au/2011/02/html5-canvas-angle-bounce-using-some-rotational-maths/</link>
		<comments>http://stevekane.com.au/2011/02/html5-canvas-angle-bounce-using-some-rotational-maths/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 09:51:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Ball Bounce]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Trigonometry]]></category>

		<guid isPermaLink="false">http://stevekane.com.au/?p=231</guid>
		<description><![CDATA[OK here we go. I&#8217;ll try and explain this one a little bit. I looked everywhere for a good tutorial on performing angled bounces with an object in the &#60;canvas&#62; element but found nothing specific enough. So after a lot of late nights, I finally found one that was written in ActionScript. I&#8217;ve adapted it ]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.stevekane.com.au/test/canvas/bouncing_ball_physics.html"><img class="aligncenter size-full wp-image-232" title="Rotating line with angle bounce" src="http://stevekane.com.au/wp-content/uploads/2011/02/physics_pong.jpg" alt="Rotating line with angle bounce" width="400" height="526" /></a></p>
<p>OK here we go. I&#8217;ll try and explain this one a little bit. I looked everywhere for a good tutorial on performing angled bounces with an object in the <code>&lt;canvas&gt;</code> element but found nothing specific enough. So after a lot of late nights, I finally found one that was written in ActionScript. I&#8217;ve adapted it back to JavaScript (which is basically the same thing) to further play with what the new HTML5 features give us.</p>
<p>I won&#8217;t go into detail about the movement of the ball or the paddle&#8230; If you want me to &#8211; <a href="mailto:steve@stevekane.com.au">email me</a>.</p>
<p>Please excuse my variable names. They&#8217;re horrible &#8211; I know&#8230; Just bare with them for now. posx and posy are the positions of the ball. x1 and y1 are the starting positions of the line and x2 and y2 are the end of the line.</p>
<p>cos and sin are tricky ones. I haven&#8217;t shown the whole code here (obviously) but further up I have made these into sort of a shortcut.</p>
<pre><code>var angle = lineAngle * Math.PI / 180;
var cos = Math.cos(angle);
var sin = Math.sin(angle);
</code></pre>
<p>For all this rotational stuff to work your degrees need to be converted to radians. pi / 180 will convert that for you.</p>
<p>I have commented most of the code in the actual HTML page(click the picture at the top to get there).</p>
<p>Right, below is where all the magic happens&#8230; I think the math is based on a 3&#215;3 rotational matrix, that isn&#8217;t something I&#8217;m very familiar with so apologies if that&#8217;s not 100% correct. If there is anyone that has a better explanation of rotational matrices than the ones currently online please let me know!</p>
<p>The reason it looks messy is because you need to rotate everything(ball position, the line position and the velocity of the ball) to (0,0) coordinates. Then run the test to see if the ball has hit the line, if it has, make the ball bounce in the other direction and rotate everything back, if not, just rotate everything back and carry on as before with the ball traveling in the same direction. Next <span style="text-decoration: underline;">frame</span>, rotate it all and test again. That&#8217;s right! So 25 times a second it is rotating all the elements to (0,0), testing if something happens, then rotating it all back. Seems criminally inefficient right? That&#8217;s just how it works.</p>
<h3>Hope this is easy enough to follow:</h3>
<p>get position of ball, relative to line<br />
x1 y1 &#8211; Start point of line and x2 y2 &#8211; end point</p>
<pre><code>newposx = posx - x1;
newposy = posy - y1;
newposx2 = posx - x2;
newposy2 = posy - y2;</code></pre>
<p>rotate coordinates giving the rotated position of the ball<br />
relative to the line</p>
<pre><code>rotposx = cos * newposx + sin * newposy;
rotposy = cos * newposy - sin * newposx;
rotposx2 = cos * newposx2 + sin * newposy2;
rotposy2 = cos * newposy2 - sin * newposx2;</code></pre>
<p>rotate velocity<br />
vx1 vy1</p>
<pre>rotvelx = cos * velx + sin * vely;
rotvely = cos * vely - sin * velx;</pre>
<p>perform bounce with rotated values<br />
if ball hits on top of the line</p>
<pre>if (rotposy &gt;  -  r &amp;&amp; rotposy &lt; 0 - (r / 2) &amp;&amp;
    newposx &gt; 0 &amp;&amp; newposx &lt; 100)
{
	rotvely *=  bounce;
	rotposy =  -  r;
}</pre>
<p>if ball hits on the bottom of the line</p>
<pre>if (rotposy &lt;  r &amp;&amp; rotposy &gt; 0 + (r / 2) &amp;&amp;
    newposx &gt; 0 &amp;&amp; newposx &lt; 100)
{
	rotvely *=  bounce;
	rotposy =  r;
}</pre>
<p>rotate everything back;</p>
<pre>newposx = cos * rotposx - sin * rotposy;
newposy = cos * rotposy + sin * rotposx;
newposx2 = cos * rotposx2 - sin * rotposy2;
newposy2 = cos * rotposy2 + sin * rotposx2;
velx = cos * rotvelx - sin * rotvely;
vely = cos * rotvely + sin * rotvelx;
posx = x1 + newposx;
posy = y1 + newposy;</pre>
<p>As you can see, when rotating everything back, you are simply changing the + to a &#8211; in the cos and sin equations. I&#8217;ll look at optimising this code a little bit too when I get some free time. I&#8217;m sure there&#8217;s a few shortcuts that I could have taken. But you get the general idea of how the physics work.</p>
<p>I hope you have got something beneficial out it.</p>
<p>- Stevo</p>
]]></content:encoded>
			<wfw:commentRss>http://stevekane.com.au/2011/02/html5-canvas-angle-bounce-using-some-rotational-maths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canvas &#8211; Pong Game</title>
		<link>http://stevekane.com.au/2010/08/canvas-pong-game/</link>
		<comments>http://stevekane.com.au/2010/08/canvas-pong-game/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 13:11:23 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Ball Bounce]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Pong]]></category>

		<guid isPermaLink="false">http://stevekane.com.au/?p=165</guid>
		<description><![CDATA[O.K. One more for good luck. This one is very similar to the bricks game. I used most of the collision detection code from that one with some slightly different values in the array and a little different how the array is used. Instead of the mouse to change the direction I have assigned some ]]></description>
			<content:encoded><![CDATA[<p>O.K. One more for good luck. This one is very similar to the bricks game. I used most of the collision detection code from that one with some slightly different values in the array and a little different how the array is used. Instead of the mouse to change the direction I have assigned some keys.</p>
<p>I&#8217;ll try my hand at adding another key that rotates the angle of the paddle to change the angle of the ball bouncing back. <code>&lt;canvas&gt;</code> is quite limited in its controls so this seemingly easy idea is not that easy to code. We&#8217;ll see. Anyway, like the other nonsense games that I&#8217;ve done &#8211; ENJOY!</p>
<p><a href="http://stevekane.com.au/test/canvas/pong.html"><img class="aligncenter size-full wp-image-166" title="Pong!" src="http://stevekane.com.au/wp-content/uploads/2010/08/pong.jpg" alt="Pong HTML5  canvas game" width="458" height="456" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://stevekane.com.au/2010/08/canvas-pong-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML 5 &#8211; Bricks Game</title>
		<link>http://stevekane.com.au/2010/08/html-5-bricks-game/</link>
		<comments>http://stevekane.com.au/2010/08/html-5-bricks-game/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 13:38:36 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Ball Bounce]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Hit Detection]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://stevekane.com.au/?p=157</guid>
		<description><![CDATA[This will be the last &#60;canvas&#62; demo for a while. I&#8217;m playing a little more with jQuery at the moment so the next few posts will be related to that. I made a cool fading image switcher with a few simple lines of JS. I&#8217;ll post that soon. For now, enjoy the bricks game! Special ]]></description>
			<content:encoded><![CDATA[<p>This will be the last <code>&lt;canvas&gt;</code> demo for a while. I&#8217;m playing a little more with jQuery at the moment so the next few posts will be related to that. I made a cool fading image switcher with a few simple lines of JS. I&#8217;ll post that soon. For now, enjoy the bricks game! Special thanks to <a href="http://www.xhva.net">Andy</a> for co-coding this with me. If you want a challenge, the harder version (faster ball) can be found <a href="http://www.stevekane.com.au/test/canvas/bricks/bricks_hard.html">here</a>.</p>
<p>It is buggy &#8211; yes, I know. Collision detection in JS isn&#8217;t an easy thing to do. If you move the mouse too quickly it can skip over the frame where the ball collides with the paddle. I&#8217;ve commented the code on the <a href="http://www.stevekane.com.au/test/canvas/bricks/bricks_hard.html">hard</a> version (mostly). This will briefly explain what all the code does. I&#8217;ll finish it soon when I get a little more free time.</p>
<p><a href="http://stevekane.com.au/test/canvas/bricks/bricks_easy.html"><img class="aligncenter size-full wp-image-158" title="Bricks Game" src="http://stevekane.com.au/wp-content/uploads/2010/08/bricks.png" alt="Bricks Game in Canvas" width="458" height="461" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://stevekane.com.au/2010/08/html-5-bricks-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML 5 &#8211; Ping Pong Ball Bounce!</title>
		<link>http://stevekane.com.au/2010/06/html-5-ping-pong-ball-bounce/</link>
		<comments>http://stevekane.com.au/2010/06/html-5-ping-pong-ball-bounce/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 10:48:02 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://stevekane.com.au/?p=150</guid>
		<description><![CDATA[This one is not quite finished.. 90% there. I need to fix the sound of the ball once it has finished bouncing. You&#8217;ll quickly hear what I mean, this is why I have added a stop button below the canvas. This is my first play around with animation, as I learn more I&#8217;ll tweak this ]]></description>
			<content:encoded><![CDATA[<p>This one is not quite finished.. 90% there. I need to fix the sound of the ball once it has finished bouncing. You&#8217;ll quickly hear what I mean, this is why I have added a stop button below the canvas. This is my first play around with animation, as I learn more I&#8217;ll tweak this as I go. Maybe adding a paddle to hit the ball with etc.</p>
<p><a href="http://stevekane.com.au/test/canvas/bouncing_ball_mouse.html"><img class="aligncenter size-full wp-image-151" title="Ping Pong Table" src="http://stevekane.com.au/wp-content/uploads/2010/06/pingpong.jpg" alt="Ping Pong Table" width="458" height="460" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://stevekane.com.au/2010/06/html-5-ping-pong-ball-bounce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

