<?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>Milburn &#187; JavaScript</title>
	<atom:link href="http://instantsolve.net/blog/category/webdesign/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://instantsolve.net/blog</link>
	<description>The Life and Work of Thomas Milburn</description>
	<lastBuildDate>Wed, 14 Oct 2009 10:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Mandelbrot Revisited</title>
		<link>http://instantsolve.net/blog/2009/04/mandelbrot-revisited/</link>
		<comments>http://instantsolve.net/blog/2009/04/mandelbrot-revisited/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 21:28:00 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=155</guid>
		<description><![CDATA[In my last post about the mandelbrot set I said: I would put the Mandelbrot explorer script online however it is very computationally intense. It takes around 5 seconds to generate 1 image. Now I have created a new explorer which you can use. I tried to find a way of replicating my original PHP [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_156" class="wp-caption alignleft" style="width: 330px"><img src="http://instantsolve.net/blog/wp-content/uploads/2009/04/canvas.png" alt="Canvas" title="canvas" width="320" height="240" class="size-full wp-image-156" /><p class="first-child " class="wp-caption-text">&#09;The Mandelbrot Set</p></div>
<p><span title="I" class="cap"><span>I</span></span>n my last post about the mandelbrot set I said:</p>
<blockquote><p>I would put the Mandelbrot explorer script online however it is very computationally intense. It takes around 5 seconds to generate 1 image.</p></blockquote>
<p>Now I have created a <a href="http://instantsolve.net/mandelbrot.htm">new explorer</a> which you can use.</p>
<p>I tried to find a way of replicating my original PHP script in JavaScript. That way the processing is all done on the client computer and not my server. For a while I didn&#8217;t think it was possible until today I came across pixel manipulation using the Canvas element. Internet Explorer users will be disappointed to know that the Canvas element doesn&#8217;t work on their browser and this therefore won&#8217;t work.<span id="more-155"></span></p>
<p>The code is almost the same as the PHP code except that it uses the<br />
<tt>getImageData</tt> and <tt>putImageData()</tt> functions. These functions extract the pixel data from the image and allow it to be manipulated before being saved again, extremely useful.</p>
<p>Why not <a href="http://instantsolve.net/mandelbrot.htm">explore the Mandelbrot Set</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/04/mandelbrot-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Anaglyph Maker</title>
		<link>http://instantsolve.net/blog/2009/04/javascript-anaglyph-maker/</link>
		<comments>http://instantsolve.net/blog/2009/04/javascript-anaglyph-maker/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 14:56:55 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=144</guid>
		<description><![CDATA[My own anaglyph maker uses PHP to make anaglyphs from two images uploaded by a user. But I&#8217;ve found someone who has gone one step further. They&#8217;ve managed to make them using JavaScript alone. Unfortunately Internet Explorer fails miserably on this task. This is because his method uses the canvas object which so far is [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><img src="http://instantsolve.net/blog/wp-content/uploads/2009/04/mars-300x225.png" alt="mars" title="mars" width="300" height="225" class="alignright size-medium wp-image-152" /> <span title="M" class="cap"><span>M</span></span>y own <a href="http://instantsolve.net/anaglyph/">anaglyph maker</a> uses PHP to make anaglyphs from two images uploaded by a user. But I&#8217;ve found someone who has gone one step further. They&#8217;ve managed to make them <a href="http://svay.com/blog/index/post/2009/04/03/G%C3%A9n%C3%A9rer-des-anaglyphes-avec-javascript-et-canvas">using JavaScript alone</a>. Unfortunately Internet Explorer fails miserably on this task. This is because his method uses the canvas object which so far is only supported by Firefox, Safari and Opera.</p>
<p>It simply loads the two images into two canvas elements and extracts the red channel from one of them and inserts that red channel into the other canvas. Hey presto you get a simple anaglyph. This method has another flaw. Modifying an images data channels can only be done from an image on the same domain to obey the same domain security policy. A small proxy sorts that out but means the solution isn&#8217;t all JavaScript.<span id="more-144"></span></p>
<p>Here&#8217;s the source code for his anaglyph generator:</p>
<p><code>&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript"</span>&gt;<br />
&lt;!--<br />
Anaglyph = {<br />
imgLeft : null,<br />
imgRigt : null,<br />
//Load images<br />
load : function(left, right) {<br />
//console.log('Load');<br />
Anaglyph.imgLeft = document.createElement('img');<br />
Anaglyph.imgLeft.src = left;<br />
Anaglyph.imgRight = document.createElement('img');<br />
Anaglyph.imgRight.src = right;<br />
Anaglyph.wait();<br />
},<br />
//Wait for images to load<br />
wait: function() {<br />
if (Anaglyph.imgLeft.complete &amp;&amp; Anaglyph.imgRight.complete) {<br />
Anaglyph.make();<br />
} else {<br />
setTimeout('Anaglyph.wait()', 100);<br />
}<br />
},<br />
//Actually make the anaglyph with some canvas magic<br />
make: function() {<br />
//console.log('Make');<br />
var w = 640;<br />
var h = 480;<br />
var canvas = document.getElementsByTagName('canvas')[0];<br />
try {<br />
//Left image in temporary canvas<br />
var canvasLeft = document.createElement('canvas');<br />
canvasLeft.width = w;<br />
canvasLeft.height = h;<br />
var ctxLeft = canvasLeft.getContext('2d');<br />
ctxLeft.drawImage(Anaglyph.imgLeft, 0, 0, w, h);<br />
var dataLeft = ctxLeft.getImageData(0,0, w, h);<br />
//Right image in result canvas<br />
canvas.width = w;<br />
canvas.height = h;<br />
var ctx = canvas.getContext('2d');<br />
ctx.drawImage(Anaglyph.imgRight, 0, 0, w, h);<br />
var data = ctx.getImageData(0,0, w, h);<br />
for (var i=0,l=dataLeft.data.length/4; i&lt;l; i++) {<br />
data.data[i * 4 + 0] = dataLeft.data[i * 4 + 0];<br />
}<br />
ctx.putImageData(data, 0, 0);<br />
//console.log('Done!');<br />
} catch (e) {<br />
//console.log('FAIL!')<br />
}<br />
document.getElementById('result').className = '';<br />
}<br />
}<br />
function getQueryParameter(name) {<br />
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");<br />
var regexS = "[\\?&amp;]"+name+"=([^&amp;#]*)";<br />
var regex = new RegExp( regexS );<br />
var results = regex.exec( window.location.href );<br />
if( results == null ) {<br />
return "";<br />
} else {<br />
return results[1];<br />
}<br />
}<br />
window.onload = function() {<br />
if ('' != getQueryParameter('left') &amp;&amp; '' != getQueryParameter('right')) {<br />
var left = getQueryParameter('left');<br />
var right = getQueryParameter('right');<br />
document.getElementById('result').className = 'loading';<br />
Anaglyph.load(<br />
'image.php?url='+left,<br />
'image.php?url='+right<br />
);<br />
}<br />
}<br />
--&gt;<br />
&lt;/<span class="end-tag">script</span>&gt;</code></p>
<p>The canvas element can do so many things and my guess is we&#8217;ll be seeing it even more in the next few years.</p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/04/javascript-anaglyph-maker/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Instant Star Rating</title>
		<link>http://instantsolve.net/blog/2009/02/instant-star-rating/</link>
		<comments>http://instantsolve.net/blog/2009/02/instant-star-rating/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 18:11:22 +0000</pubDate>
		<dc:creator>milburn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://instantsolve.net/blog/?p=129</guid>
		<description><![CDATA[Released earlier this week was my star rating tool. I&#8217;d actually started this about a year ago but only remembered last weekend that I had it gathering dust in my hard drive. Instant Star Rating allows you to create 5 star ratings in several different styles to go on your website. Unlike other star raters [...]]]></description>
			<content:encoded><![CDATA[<p class="first-child "><span title="R" class="cap"><span>R</span></span>eleased earlier this week was my <a href="http://instantsolve.net/rating/">star rating tool</a>. I&#8217;d actually started this about a year ago but only remembered last weekend that I had it gathering dust in my hard drive.</p>
<p>Instant Star Rating allows you to create 5 star ratings in several different styles to go on your website. Unlike other star raters it doesn&#8217;t use Ajax. This is because Ajax doesn&#8217;t work across domains. Instead it uses the dynamic script method. When the user clicks on a star it loads a new script from the server.<span id="more-129"></span></p>
<p>The tool actually gave me some grief since I checked it worked in Firefox and failed to check in IE presuming that it would work in IE too. This was not to be, the rating javascript failed in IE due to an obscure DOM issue. IE doesn&#8217;t support innerHTML on style elements. So I tried to look for an alternative. IE has a property called styleSheet which isn&#8217;t supported by other browsers. CSS can be written to this using the cssText method. An interesting find!</p>
<p>I therefore used the following method to add dynamic CSS:</p>
<p><code>IR1_h=document.getElementsByTagName("head")[0]<br />
IR1_l=document.createElement("style")<br />
IR1_l.type='text/css'<br />
IR1_h.appendChild(IR1_l)<br />
if(IR1_l.styleSheet){<br />
	IR1_l.styleSheet.cssText='#rate1{padding:10px 0}'<br />
}else{<br />
	IR1_l.innerHTML='#rate1{padding:10px 0}'<br />
}<br />
</code></p>
<p>Please try out <a href="http://instantsolve.net/rating/">instant star rating</a>, it is completely free and should work on almost any website. Check out the example below:</p>
<p><script src="http://instantsolve.net/rating/rating.php?id=10"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://instantsolve.net/blog/2009/02/instant-star-rating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

