<?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>Joshua Ho&#039;s Blog</title>
	<atom:link href="http://www.josh-ho.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.josh-ho.com</link>
	<description>A Developer&#039;s Blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 15:06:49 +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>QR Code Generator</title>
		<link>http://www.josh-ho.com/qr-code-generator/</link>
		<comments>http://www.josh-ho.com/qr-code-generator/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 14:42:13 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[QR]]></category>
		<category><![CDATA[QR code generator]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/?p=430</guid>
		<description><![CDATA[I found some time to work on a QR code generator.  QR codes are similar to barcodes, but can contain words, or URL&#8217;s.  They are growing in popularity around the world.  I recently learned that Google has an API that developers can use to generate a QR code. I built a simple QR code generator [...]]]></description>
			<content:encoded><![CDATA[<p>I found some time to work on a QR code generator.  QR codes are similar to barcodes, but can contain words, or URL&#8217;s.  They are growing in popularity around the world.  I recently learned that Google has an API that developers can use to generate a QR code.</p>
<p>I built a simple QR code generator to use.  Simply enter a URL and my script would automatically generate a QR code for you:</p>
<div class="qrContainer">
<div class="qrOptions removelineBreak"><label>Enter a website URL:</label></p>
<input type="text" /><label>Shorten URL?</label></p>
<input type="checkbox" />
<input type="button" value="Generate QR Code" /></div>
<div id="generatedQRCode"></div>
</div>
<p><script type="text/javascript">// <![CDATA[
      $( document ).ready( function() {  	QrCodeGenerator.init(); } );
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/qr-code-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vimeo Class</title>
		<link>http://www.josh-ho.com/vimeo-class/</link>
		<comments>http://www.josh-ho.com/vimeo-class/#comments</comments>
		<pubDate>Wed, 25 May 2011 01:41:02 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Froogaloop]]></category>
		<category><![CDATA[Moogaloop]]></category>
		<category><![CDATA[Vimeo]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/?p=400</guid>
		<description><![CDATA[Over a past while I have noticed that I want to start integrating Vimeo players on websites and provide full functionality based on various circumstances. Vimeo has an API open to the public &#8211; http://vimeo.com/api/docs/player. Now I find that the Vimeo API, quite challenging to use and I figured that writing a wrapper class would [...]]]></description>
			<content:encoded><![CDATA[<p>Over a past while I have noticed that I want to start integrating Vimeo players on websites and provide full functionality based on various circumstances. Vimeo has an API open to the public &#8211; <a href="http://vimeo.com/api/docs/player" onclick="pageTracker._trackPageview('/outgoing/vimeo.com/api/docs/player?referer=');">http://vimeo.com/api/docs/player</a>.</p>
<p>Now I find that the Vimeo API, quite challenging to use and I figured that writing a wrapper class would make my life much easier. I found working directly with the Vimeo Moogaloop Flash player much easier to work with and directly called methods to the Moogaloop Flash Player.</p>
<p>You can download my class here. <a href="http://labs.josh-ho.com/vimeo/Vimeo.js" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/vimeo/Vimeo.js?referer=');">Vimeo Class</a>. SWFobject is also required and can be downloaded here: <a href="http://code.google.com/p/swfobject/downloads/list" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/swfobject/downloads/list?referer=');">http://code.google.com/p/swfobject/downloads/list</a></p>
<p>Implementing my Vimeo class is quite easy<br />
<code><br />
&lt;script type="text/javascript" src="swfobject.js"&gt;<br />
&lt;script type="text/javascript" src="Vimeo.js"&gt;<br />
&lt;div id="vimeoPlayer"&gt;&lt;/div&gt;</code></p>
<p>&lt;script type=&#8217;text/javascript&#8217;&gt;<br />
var vimeo;<br />
vimeo = new Vimeo( &#8220;vimeoPlayer&#8221;, 480, 320, &#8220;vimeo&#8221; );<br />
vimeo.loadVideo( &#8217;24198254&#8242; );<br />
vimeo.addEventListener( vimeo.VIMEO_FINISH, videoFinished );</p>
<p>function videoFinished() {<br />
//video finished playing<br />
}<br />
&lt;/script&gt;</p>
<p>In order to start the Vimeo Class we need to setup the basics. We have to load in both the Vimeo class and swfobject. We also need a &lt;div&gt; tag to contain the Vimeo player.</p>
<p>Once we have that setup, we can call the Vimeo class and load in our video. In order to do so we have to initialize the Vimeo class and pass in the following parameters . Div container ID, video width dimensions, video height dimensions, variable name, show title of video, show by line of video, show user portrait, allow fullscreen, and video player colour.</p>
<p>Not all of these parameters are required. The only required parameters are: Div container ID, video width dimensions, video height dimensions, and variable name.</p>
<p>We can tell the class to load a specific video by calling loadVideo and pass in the video ID.</p>
<p>I bubbled all of the events the Moogaloop player dispatches out to the class for users. In my example, when the video has finished playing it calls our own function &#8216;videoFinished()&#8217; and we can do whatever we want from there.</p>
<p>A finished example of this Vimeo class looks like this:<br />
<script type="text/javascript" src="http://labs.josh-ho.com/vimeo/swfobject.js"></script><br />
<script type="text/javascript" src="http://labs.josh-ho.com/vimeo/Vimeo.js"></script></p>
<div id="vimeoPlayer"></div>
<p><script type="text/javascript">// <![CDATA[
var vimeo;
vimeo = new Vimeo( "vimeoPlayer", 480, 320, "vimeo" );
vimeo.loadVideo( '24198254' );
vimeo.addEventListener( vimeo.VIMEO_FINISH, videoFinished );
function videoFinished() {
  //video finished
}
// ]]&gt;</script></p>
<p>Below is a full documentation on my wrapper class methods:<br />
- Constructor<br />
- container &#8211; the html element that the vimeo player would be located in<br />
- width &#8211; the vimeo player width<br />
- height &#8211; the vimeo player height<br />
- variableName &#8211; the variable name of the vimeo player<br />
- showTitle (Boolean) &#8211; (optional) displays the title of the vimeo video. Default is true.<br />
- showByline (Boolean) &#8211; (optional) displays the by line of the vimeo video. Default is true.<br />
- showPortrait (Boolean) - (optional) displays the user portrait of the vimeo video. Default is true.<br />
- fullScreen (Boolean) - (optional) allows users to watch Vimeo video in fullscreen. Default is true.<br />
- playerColour (uint) &#8211; (optional) change the Vimeo video player colour. Default is the Vimeo blue (hex: #00adef)</p>
<p>- Event Types<br />
- VIMEO_PLAYING &#8211; Fires when the vimeo player started to play.<br />
- VIMEO_PAUSED &#8211; Fires when the vimeo player is paused.<br />
- VIMEO_FINISH &#8211; Fires when the vimeo video is finished playing.<br />
- VIMEO_PROGRESS &#8211; Fires as the vimeo video is playing and returns the position in seconds.<br />
- VIMEO_LOAD_PROGRESS &#8211; Fires as the vimeo player is loading.<br />
- VIMEO_LOAD_COMPLETE &#8211; Fires when the vimeo player has been loaded.<br />
- VIMEO_SEEK &#8211; Fires when the user seeks through the video and returns the position in seconds.</p>
<p>- Public Functions<br />
- addEventListener ( type, callback ) &#8211; A method that listens for events triggered by the Vimeo Player and calls the specific callback function as each event fires.<br />
- type:String &#8211; The event that is being listened for<br />
- callback:Function &#8211; The function that is called when the event is fired<br />
- removeEventListener ( type, callback ) &#8211; A method that removes the callback function for a particular event type.<br />
- type:String &#8211; The event that is being listened for<br />
- callback:Function &#8211; The function that is called when the event is fired<br />
- loadVideo ( vimeoID ) &#8211; Loads a specific video based on the Vimeo ID.<br />
- vimeoID:String &#8211; The Vimeo video ID<br />
- playVideo &#8211; Plays the loaded Vimeo video.<br />
- pauseVideo &#8211; Pauses the loaded Vimeo video.<br />
- seek( seekTime ) &#8211; Seeks the Vimeo video to the provided time.<br />
- seekTime:String &#8211; The duration to seek the video to. This seekTime is based per second.<br />
- volume( volumeLevel ) &#8211; Sets the volume level of the Vimeo player.<br />
- volumeLevel:String &#8211; Sets the volume of the video. 0 is the lowest, 1 is the highest.<br />
- changeVimeoColour( colour ) &#8211; Changes the Vimeo player colour.<br />
- colour:String &#8211; This is a hexadecimal string that changes the colour of the Vimeo Video Player.<br />
- unloadVideo &#8211; unloads the video.<br />
- setVideoDimensions ( width, height ) &#8211; Sets the Vimeo video player&#8217;s width and height.<br />
- width:Number &#8211; The width of the video player in pixels<br />
- height:Number &#8211; The height of the video player in pixels</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/vimeo-class/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Blackberry Playbook</title>
		<link>http://www.josh-ho.com/blackberry-playbook/</link>
		<comments>http://www.josh-ho.com/blackberry-playbook/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 16:06:21 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Application]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Burrito]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Playbook]]></category>
		<category><![CDATA[Whiteboard]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=388</guid>
		<description><![CDATA[*Update I have received a confirmation from RIM that my application has been approved.* *second edit* I have the first iteration out for everyone to download: Whiteboard App. I am working on a fix for the save feature as part of my second update. Stay tuned. Research in Motion is offering one free Playbook to [...]]]></description>
			<content:encoded><![CDATA[<p>*Update I have received a confirmation from RIM that my application has been approved.*</p>
<p>*second edit* I have the first iteration out for everyone to download: <a href="http://appworld.blackberry.com/webstore/content/25763?lang=en" onclick="pageTracker._trackPageview('/outgoing/appworld.blackberry.com/webstore/content/25763?lang=en&amp;referer=');">Whiteboard App</a>.  I am working on a fix for the save feature as part of my second update.  Stay tuned.</p>
<p>Research in Motion is offering one free Playbook to developers who develop an application on their Blackberry Playbook platform. Link: <a href="http://us.blackberry.com/developers/tablet/playbook_offer.jsp" onclick="pageTracker._trackPageview('/outgoing/us.blackberry.com/developers/tablet/playbook_offer.jsp?referer=');">http://us.blackberry.com/developers/tablet/playbook_offer.jsp</a>  I think it is a neat incentive to build interest in the Playbook.</p>
<p>I have recently developed an application and currently waiting its status by Blackberry&#8217;s admin.  The application is a whiteboard note taking application where users can draw or write notes.  It is ideal for the classroom where you can draw along aside your notes to illustrate and provide more of a full note taking experience.  It is a pretty neat application for tablets.  I will keep everyone posted on its status as the application progresses through the Blackberry approval.</p>
<p>The Playbook is quite interesting.  Right off the bat, the major selling point for the Playbook are the applications already included with the tabet.  It comes with a lot of neat applications, ranging from games to productivity to photo and web browsing.  It is light weight, but powerful enough to play some graphic intensive games.  My major gripe, as with many tablets is that the screen is a magnet for fingerprints.  I plan and suggest investing in a cover or a screen for any type of tablet for the future.</p>
<div align="center"><img src="http://www.josh-ho.com/blog/Images/bb_1.jpg" alt="Blackberry Playbook Homescreen" /></div>
<p>Blackberry packed quite a lot of power.  It is very responsive; I was able to play some graphic intensive games with Need for Speed and Tetris without noticing any lag.  I find it great to use when watching TV; the Playbook is quick to turn on and allows me to check my emails and update blog posts quickly.  The Playbook is quite bright and I was able to surf without having the need to turn on the light.</p>
<div align="center"><img src="http://www.josh-ho.com/blog/Images/bb_2.jpg" alt="Playbook with my blog" /></div>
<p>I like the size and the feel of the Playbook.  The size is not large enough that it is a hassle to bring anywhere, but the screen resolution is comparable to market where you do not have to squint in order to read small text.  The matte feel of the back feels comfortable to hold for quite a while.  I was shocked at the weight when I initially picked up the Playbook, but after a while I have adjusted to its weight.  As I type this blog post, it is noticeable that typing is quite hard, I have not found a good position to type.  I have to put the tablet down on a table in order to type fast.  However if I am sitting and relaxing, I am unable to type as fast as I hoped.</p>
<div align="center"><img src="http://www.josh-ho.com/blog/Images/bb_3.jpg" alt="Blackberry Playbook Back" /></div>
<p>Overall the Playbook is quite a remarkable tablet.  If you are looking for a tablet, I would suggest to look at the Blackberry Playbook.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/blackberry-playbook/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML &#8211; Geolocation</title>
		<link>http://www.josh-ho.com/html-geolocation/</link>
		<comments>http://www.josh-ho.com/html-geolocation/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 19:08:19 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Bing]]></category>
		<category><![CDATA[Bing Maps]]></category>
		<category><![CDATA[Geolocation]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Latitude]]></category>
		<category><![CDATA[Longitude]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[navigator]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=358</guid>
		<description><![CDATA[As part of the new web specifications, the W3C have outlined new specifications for browsers to access geographical location information. Getting the exact location of where a person is not 100% accurate. However, with geolocation information, developers can develop applications based on their geographical locaiton. For example, tourism companies could provide information to the user [...]]]></description>
			<content:encoded><![CDATA[<p>As part of the new web specifications, the W3C have outlined new specifications for browsers to access geographical location information. Getting the exact location of where a person is not 100% accurate. However, with geolocation information, developers can develop applications based on their geographical locaiton.  For example, tourism companies could provide information to the user about a specific location.  </p>
<p>This example would demonstrates the use of Geolocation with an open source map software to locate an approximate the user&#8217;s position.</p>
<p>We will be using both Google Maps and Bing Maps for this demonstration.  The final result would look like this:<br />
<a href="http://labs.josh-ho.com/geolocation/google/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/geolocation/google/?referer=');">Google Maps</a><br />
<a href="http://labs.josh-ho.com/geolocation/bing/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/geolocation/bing/?referer=');">Bing Maps</a></p>
<p>Both Google and Bing require developers to import their library.</p>
<p>Google:<br />
<code><br />
&lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">&lt;/script><br />
</code></p>
<p>Bing:<br />
<code><br />
&lt;script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2">&lt;/script><br />
</code></p>
<p>Note with Bing, the default map size is 600px by 400px and requires an extra two lines to adjust the width and height.  More about this later.</p>
<p>Both maps require a container where the maps would be loaded into.<br />
<code><br />
&lt;div id="mapContainer">&lt;/div><br />
</code></p>
<p>We now have an empty &#038;ltdiv> container to load in our map.  From here on end we will primarily focus on Javascript. We need to first determine if we can grab the user&#8217;s geolocation. We can do this by calling a property of the navigator object &#8211; more specifally the geolocation property.  This is a boolean that would return if the user has provided access for the browser to collect the user&#8217;s geographical location or not.  If the user grants the browser access, we can call the getCurrentPosition method to grab the latitude and longitude of the user.</p>
<p><code><br />
&lt;script type="text/javascript"><br />
function success(position) {</p>
<p>}</p>
<p>function error(msg) {</p>
<p>}</p>
<p>if (navigator.geolocation) {<br />
	navigator.geolocation.getCurrentPosition(success, error);<br />
} else {<br />
	error('not supported');<br />
}<br />
&lt;/script><br />
</code></p>
<p>The getCurrentPosition() method requires two functions &#8211; a success function and an error function. If the getCurrentPosition() method is able to provide the user&#8217;s latitude and longitude it would call the success function otherwise it would call the error function.  Inside each function I am requesting an object being passed in.  This object is important as it contains the information that we want &#8211; the latitude and longitude or an error message.  If we write an alert( position.coords.latiude ) or alert( position.coords.longitude ) inside the success function we should get the latitude and longitude coordinates of where we are.</p>
<p>We want to pass this information along to our maps.</p>
<p>With Bing maps, we need to initialize their map.  I normally stored this initalization inside a variable so I can call other methods down the road. As part of the initalization requirements, we need to provide Bing with the &#038;ltdiv> container created earlier.</p>
<p><code><br />
var myMap = null;<br />
... more code ...</p>
<p>myMap = new VEMap( "mapContainer" );<br />
</code></p>
<p>Google Maps works a bit differently.  We need to set the properties &#8211; such as latitude and longitude and any other map options, first before initializing Google Maps.</p>
<p>For both Bing and Google Maps, we need to pass in the latitude and longitude the browser was able to retreive in the success() function.</p>
<p>Google:<br />
<code><br />
var mapContainer = document.getElementById('mapContainer');</p>
<p>mapContainer.style.width = '1024px';<br />
mapContainer.style.height = '768px';<br />
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);<br />
var myOptions = {<br />
    zoom: 15,<br />
    center: latlng,<br />
    mapTypeControl: false,<br />
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},<br />
    mapTypeId: google.maps.MapTypeId.ROADMAP<br />
};<br />
var map = new google.maps.Map( mapContainer, myOptions );<br />
</code></p>
<p>What this code does is set the mapContainer &#038;ltdiv> to 1024px by 768px.  We created a Latitude and Longitude object &#8211; in that order,  and passed in the coordinates.  I wanted to set the zoom to relatively close, used the small navigation control style used Google&#8217;s roadmap, and have google center to my location.  The last part is optional, it is not necessary to use the options, but for this demonstration we are using it to show where we are.  Finally we initialize Google Maps with the mapContainer &#038;ltdiv> and the options that we want.</p>
<p>Bing:<br />
Bing works a bit differently but has the same concept.  We need to create a Latitude and Longitude object using the VELatLong() class with the proper altitude and pass that into the LoadMap() function to load the map onto the browser.  As stated earlier, Bing maps loads 800px by 600px and if you want to change the dimensions we need to call the Resize() method.  The Resize() method only tells Bing to load in more information to fill the size required.  If the Resize() method is not called, Bing presumes that you are using the default 800px x 600px, which would not properly center your location and load in the incorrect data displaying some grey gaps on the map.</p>
<p><code><br />
var mapContainer = document.getElementById('mapContainer');<br />
var altitude = 1;<br />
var latLongInfo = new VELatLong(position.coords.latitude, position.coords.longitude, altitude, VELatLong.RelativeToGround);<br />
myMap.LoadMap(latLongInfo, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);<br />
myMap.Resize(1024, 768);<br />
mapContainer.style.width = '1024px';<br />
mapContainer.style.height = '768px';</p>
<p>var pinPoint = myMap.GetCenter();<br />
</code></p>
<p>For Bing we are using the same options as Google Maps &#8211; using road maps on a 2d surface and centering the map. Again this is optional and can be adjusted to fit your needs.  The pinPoint object is the center of the map, which we will need to add the marker on the Bing map &#8211; see below.</p>
<p>Finally we can add a marker to indicate where we are. </p>
<p>Google:<br />
<code><br />
var marker = new google.maps.Marker({<br />
            position: latlng,<br />
            map: map,<br />
            title:"This is where you are"<br />
});<br />
</code></p>
<p>Bing:<br />
<code><br />
var pin = myMap.AddPushpin(pinPoint);<br />
pin.SetTitle("You are located &#038;ltspan style=color:red>Here</span>");<br />
pin.SetDescription("This is a demonstration of the HTML geolocation spec in use.");<br />
pin.SetCustomIcon("&lt;img src='logo.png' />");<br />
pin.SetMoreInfoURL("http://www.josh-ho.com/blog/");<br />
</code></p>
<p>Google adds markers differently than Bing, but the concept is the same.  We have to provide Google with the latitude and longitude &#8211; from the Latitude and Longitude object, the map and a description of what we want to say.</p>
<p>Bing maps require developers to call the AddPushpin() method and pass in the pinPoint object from before.  The AddPushPin allows us to set the title, description, a custom icon and a URL for more information.  I added some text to illustrate this, and this can be changed accordingly.</p>
<p>And there we have it, we now can show an accurate location of where the user is using the new W3C geolocation standard.</p>
<p>See the final result here:<br />
<a href="http://labs.josh-ho.com/geolocation/google/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/geolocation/google/?referer=');">Google Maps</a><br />
<a href="http://labs.josh-ho.com/geolocation/bing/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/geolocation/bing/?referer=');">Bing Maps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/html-geolocation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Canvas &#8211; Green Screen</title>
		<link>http://www.josh-ho.com/html-canvas-green-screen/</link>
		<comments>http://www.josh-ho.com/html-canvas-green-screen/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 19:00:24 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Chroma Key]]></category>
		<category><![CDATA[Green]]></category>
		<category><![CDATA[Green Screen]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=354</guid>
		<description><![CDATA[Green screen is a technique where you compose two images into one. The technique uses a contrasting colour &#8211; normally green or blue, and removes that colour from the frame, replcaing it with another image. With the Canvas getImageData() and putImageData() methods we can write a Green Screen script. Please note, this is an extension [...]]]></description>
			<content:encoded><![CDATA[<p>Green screen is a technique where you compose two images into one. The technique uses a contrasting colour &#8211; normally green or blue, and removes that colour from the frame, replcaing it with another image.  With the Canvas getImageData() and putImageData() methods we can write a Green Screen script.  Please note, this is an extension of my previous tutorial (<a href="http://www.josh-ho.com/blog/?p=346">HTML 5 &#8211; getImageData() and putImageData()</a>).  This demonstration illustrates how we can use the canvas element to create a green screen.</p>
<p>The end result should look like this:<br />
<a href="http://labs.josh-ho.com/greenscreen/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/greenscreen/?referer=');">Green Screen</a></p>
<p>We will need 4 canvases and load in 3 images.  The first image would be the overlay image.  This image would be the image that replaces the green portion of the image.  The second image is the green screen image.  Here we have an image with a green background and a scribble in front of it.  The third image is the green screen colour.  This is the colour that we will be using as the knockout colour.  </p>
<p>The way we want to build out this script is to grab all of the canvas context image data. We would loop through the green screen image and replace each pixel of the knockout colour with the overlay image. </p>
<p><code><br />
function greenScreen( gSContext, overlayContext, knockoutContext ) {<br />
		var greenScreenMergedArray = gSContext.getImageData( 0, 0, gSContext.canvas.width, gSContext.canvas.height );<br />
		var overlayScreenMergedArray = overlayContext.getImageData( 0, 0, overlayContext.canvas.width, overlayContext.canvas.height );<br />
		var knockoutScreenMergedArray = knockoutContext.getImageData( 0, 0, knockoutContext.canvas.width, knockoutContext.canvas.height );<br />
		var greenScreenMergedData = greenScreenMergedArray.data;<br />
		var overlayScreenMergedData = overlayScreenMergedArray.data;</p>
<p>		var knockoutR = ( knockoutScreenMergedArray.data[0] - 170 > 0 ) ? knockoutScreenMergedArray.data[0] - 170 : 0;<br />
		var knockoutG = ( knockoutScreenMergedArray.data[1] - 170 > 0 ) ? knockoutScreenMergedArray.data[1] - 170 : 0;<br />
		var knockoutB = ( knockoutScreenMergedArray.data[2] - 170 > 0 ) ? knockoutScreenMergedArray.data[2] - 170 : 0;</p>
<p>		var i;<br />
		for( i = 0; i < greenScreenMergedData.length; i+=4 ) {<br />
			var r = greenScreenMergedData[i];<br />
			var g = greenScreenMergedData[i+1];<br />
			var b = greenScreenMergedData[i+2];<br />
			var a = greenScreenMergedData[i+3];</p>
<p>			if( parseInt(r) >= knockoutR &#038;&#038; parseInt(g) >= knockoutG &#038;&#038; parseInt(b) >= knockoutB ) {<br />
				//greenScreenMergedData[i+3] = 0;<br />
				var overlayR = overlayScreenMergedData[i];<br />
				var overlayG = overlayScreenMergedData[i+1];<br />
				var overlayB = overlayScreenMergedData[i+2];<br />
				var overlayA = overlayScreenMergedData[i+3];</p>
<p>				greenScreenMergedData[i] = overlayR;<br />
				greenScreenMergedData[i+1] = overlayG;<br />
				greenScreenMergedData[i+2] = overlayB;<br />
				greenScreenMergedData[i+3] = overlayA;<br />
			}<br />
		}</p>
<p>		return greenScreenMergedArray;<br />
	}<br />
</code></p>
<p>This code is intended to take the green screen image and replace the green with the background.  Once all of the processing is completed, I am returning the newly merged green screen image for any additional image modifications or to place it back in the canvas.  I have a static number of 170 as I find that it is the most accurate removing the green from gradients.  I plan on including a threshold forumla to replace the static 170.</p>
<p>See this code in action:<br />
<a href="http://labs.josh-ho.com/greenscreen/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/greenscreen/?referer=');">Green Screen</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/html-canvas-green-screen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML &#8211; Canvas getImageData() and putImageData()</title>
		<link>http://www.josh-ho.com/html-canvas-getimagedata-and-putimagedata/</link>
		<comments>http://www.josh-ho.com/html-canvas-getimagedata-and-putimagedata/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 19:36:04 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[getImageData]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Pixel Bender]]></category>
		<category><![CDATA[Pixel Manipulation]]></category>
		<category><![CDATA[putImageData]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=346</guid>
		<description><![CDATA[The W3C outlined a couple of new methods for the Canvas element called getImageData() and putImageData(). getImageData() is a pretty neat method for image and video manipulation. These new methods allow developers to write scripts to adjust image data similar to Adobe Pixel Bender where you can manipulate images on a pixel basis. This article [...]]]></description>
			<content:encoded><![CDATA[<p>The W3C outlined a couple of new methods for the Canvas element called getImageData() and putImageData().  getImageData() is a pretty neat method for image and video manipulation.  These new methods allow developers to write scripts to adjust image data similar to Adobe Pixel Bender where you can manipulate images on a pixel basis.  This article is a basic demonstration of the getImageData() and putImageData() method.</p>
<p>At the end of this demonstration we should have a simple picture where we can adjust the contract, brightness and opacity values.</p>
<p>Link <a href="http://labs.josh-ho.com/getImageData/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/getImageData/?referer=');">http://labs.josh-ho.com/getImageData/</a></p>
<p>We will first start off by loading in an image into our canvas. In order to use the getImageData() method we need to load the image into the canvas.  In order to do so, we will use Javascript to create an image element, load in the image, then draw the image into the canvas.</p>
<p><code><br />
&lt;canvas id="imageCanvas">Your Browser cannot render the Canvas element&lt;/canvas></p>
<p>&lt;script></p>
<p>var canvasObj = document.getElementById( 'imageCanvas' );<br />
var canvasContext = canvasObj.getContext( '2d' );<br />
var imageObj = document.createElement( 'img' );<br />
imageObj.addEventListener( 'load', function() {<br />
	canvasObj.width = this.width;<br />
	canvasObj.height = this.height;<br />
	canvasContext.drawImage( this, 0, 0 );<br />
});<br />
imageObj.src = 'photo.jpg';</p>
<p>&lt;/script><br />
</code></p>
<p>Now if we upload the HTML we should see the image loaded onto the browser.</p>
<p>Lets add a slider to the HMTL code so we can adjust the Opacity levels of the image.  Form sliders are new to HTML, and should suffice for our demonstration.  To display a slider we need a form element and set the input type to &#8216;range&#8217;.  I am setting the minimum and maximum value so that it would correspond to the alpha values of the image.</p>
<p><code><br />
&lt;form name="manipulationForm" id="manipulationForm"><br />
    &lt;p>Opacity:&lt;/p><br />
    &lt;input type="range" id="opacitySliderObj"  min="0" max="255" value="255" style="vertical-align:middle;"/> &lt;p id="opacityValue" style="display:inline;">100&#37;&lt;/p><br />
&lt;/form><br />
</code></p>
<p>We are going to add some javascript functionality so that these sliders can function.  I added a
<p> tag so when we adjust the value of the slider we can see the percentage displayed.  We will need to add an event listener to listen for when the user changes the slider value.  When the slider has changed, we want to show the change in colour percentages so we will adjust the tag accordingly.</p>
<p><code><br />
var opacityValue = document.getElementById( 'opacitySliderObj' ).value;</p>
<p>document.getElementById( 'manipulationForm' ).addEventListener( 'change', formEventListener, false );</p>
<p>function formEventListener( evt ) {<br />
	opacityValue = evt.target.value;<br />
	document.getElementById( 'opacityValue' ).innerHTML = String(Math.floor((evt.target.value / evt.target.max) * 100)) + "&#37;";<br />
}<br />
</code></p>
<p>I added a new variable &#8211; opacityValue to the variable list so that we can store the value of the slider for the image manipulation process.</p>
<p>We will now need the image data information before we can start to manipulate the pixel information.  To do so we will use the getImageData() method which can be accessed throught the canvas context object.  I placed this line of code inside the image &#8216;load&#8217; event listener so that it will grab the image data as soon as the image is loaded into the canvas.</p>
<p><code><br />
var imageArray;<br />
imageArray = canvasContext.getImageData( 0, 0, canvasContext.canvas.width, canvasContext.canvas.height );<br />
</code></p>
<p>You will need to define the x, y, width, and height of the data to collect.  Now that we have the image data stored, we can write a function to loop through the data and adjust each pixel accordingly. Each pixel is broken up into 4 values &#8211; one for the red, green, blue and alpha values.  In this demonstration we only want to adjust the alpha value of each pixel.  We will adjust the alpha values based on the slider&#8217;s value (stored in the opacityValue variable) and return the image array back.</p>
<p><code><br />
function adjustImage( iArray ){<br />
	var imageData = iArray.data;<br />
	var i;<br />
	for( i = 0; i < imageData.length; i+= 4 ) {<br />
		imageData[i+3] = opacityValue;<br />
	}</p>
<p>	return iArray;<br />
}<br />
</code></p>
<p>We need to update the context with the new pixel data.  The w3C have defined another method called putImageData() which would take the image data and replace the canvas context with the new data.  I placed this call inside the formEventListener() function so that you will see the changes at run time.</p>
<p><code><br />
canvasContext.putImageData( adjustImage( imageArray ), 0, 0 );<br />
</code></p>
<p>And there you have it we have a basic opacity change using the new methods</p>
<p>Feel free to look at my demonstration here:<br />
link <a href="http://labs.josh-ho.com/getImageData/" onclick="pageTracker._trackPageview('/outgoing/labs.josh-ho.com/getImageData/?referer=');">http://labs.josh-ho.com/getImageData/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/html-canvas-getimagedata-and-putimagedata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML 5 Drag and Drop File Upload</title>
		<link>http://www.josh-ho.com/html-5-drag-and-drop-file-upload/</link>
		<comments>http://www.josh-ho.com/html-5-drag-and-drop-file-upload/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 15:00:59 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[drag and drop]]></category>
		<category><![CDATA[file uploading]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[New Media]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=320</guid>
		<description><![CDATA[Back on April 15th, 2010 Google announced that you could drag and drop attachments in their mail client &#8211; Gmail. (http://gmailblog.blogspot.com/2010/04/drag-and-drop-attachments-onto-messages.html). I thought that was a pretty neat idea and went searching for answers. After some research I managed to create my own Drag and Drop File Uploading system with HTML 5 and the latest [...]]]></description>
			<content:encoded><![CDATA[<p>Back on April 15th, 2010 Google announced that you could drag and drop attachments in their mail client &#8211; Gmail. (<a href="http://gmailblog.blogspot.com/2010/04/drag-and-drop-attachments-onto-messages.html" onclick="pageTracker._trackPageview('/outgoing/gmailblog.blogspot.com/2010/04/drag-and-drop-attachments-onto-messages.html?referer=');">http://gmailblog.blogspot.com/2010/04/drag-and-drop-attachments-onto-messages.html</a>).  I thought that was a pretty neat idea and went searching for answers.  After some research I managed to create my own Drag and Drop File Uploading system with HTML 5 and the latest W3C standards.</p>
<p><strong> Please note not all browsers are HTML 5 capable.  Based on my research Safari 5 (on the mac), Chrome 6 and Firefox 3.6+ have the right methods and are HTML 5 capable of the Drag and Drop Upload</strong></p>
<p>For this to work, I plan on using the &lt;canvas> tag &#8211; I have a previous post explaining the canvas tag here (<a href="http://www.josh-ho.com/blog/?p=314">http://www.josh-ho.com/blog/?p=314</a>).<br />
<code><br />
&lt;canvas id="myCanvas">Your browser does not support the canvas tag</canvas><br />
</code></p>
<p>According to the W3C, I can apply a dragenter, dragleave, dragover and a drop event on objects with Javascript.  In that case I applied an event listener to my canvas for those events.<br />
<code><br />
var canvas = document.getElementById("myCanvas");<br />
canvas.addEventListener("drop", drop, false );<br />
canvas.addEventListener("dragenter", dragEnter, false);<br />
canvas.addEventListener("dragleave", dragExit, false);<br />
canvas.addEventListener("dragover", dragOver, false);</p>
<p>function dragEnter(evt) {<br />
	evt.stopPropagation();<br />
	evt.preventDefault();<br />
}</p>
<p>function dragExit(evt) {<br />
	evt.stopPropagation();<br />
	evt.preventDefault();<br />
	try{<br />
		canvas.style.opacity = 1;<br />
		canvas.style.MozOpacity = 1;<br />
		canvas.filters.alpha = 100;<br />
	} catch(err){}<br />
}</p>
<p>function dragOver(evt) {<br />
	evt.stopPropagation();<br />
	evt.preventDefault();<br />
	try{<br />
		canvas.style.opacity = 0.5;<br />
		canvas.style.MozOpacity = 0.5;<br />
		canvas.filters.alpha = 50;<br />
	} catch(err){}<br />
}</p>
<p>function drop(evt) {<br />
      evt.stopPropagation();<br />
      evt.preventDefault()<br />
}<br />
</code></p>
<p>There are 4 event listener functions that I created for each of the Event Listeners.  When I drag anything I want to make sure that no other events are being fired so I have to call evt.stopPropagation and evt.preventDefault.  What these two event methods do is stop other events from bubbling to the top and causing a misfired or unintended fire event.  I also wanted to make my &lt;canvas> element to replicate a similar functionality where the canvas opacity / alpha dims down to 50% when you drag your file over, and return back to normal when your mouse leaves the canvas.</p>
<p>The browser knows if you are dragging an object inside of the browser and if you are dragging a File into the browser.  Which is what we want to do.  To grab the file we can use the dataTransfer Interface to return the object to us.  In our case it would return the file that we dragged into the browser.<br />
<code><br />
var file = evt.dataTransfer.files[0];<br />
</code><br />
(The code above only gets the first file the user dragged.  If the user is dragging multiple files, you can run a loop to loop through the file index).</p>
<p>We now have to turn our attention to the drop function.  Here is where we are using the new methods outlined by the W3C to upload a file.  I have found that Firefox handles file uploading differently than Chrome and Safari. In order for this to work on the different browsers, I ended up writing to different versions of the File Upload in javascript and used a browser detect to determine which code to use.  However as more and more browsers become HTML 5 ready, and browers start to implement the W3C standards, this may end up being unnecessary and one way to write the code would suffice.</p>
<p>Each of the browsers needed to call an XMLHTTPRequest and provide a URL to the request to submit the data to.  This is no different than calling the &lt;form> object and passing in the URL for the action property.  I created a variable called file which would contain the first file that you dropped on my canvas.<br />
<code><br />
var url = "upload.php";<br />
var request = new XMLHttpRequest();<br />
var file = evt.dataTransfer.files[0];<br />
request.open( "POST", url, true ); // open asynchronous post request</p>
<p>request.onreadystatechange=function(evt) {<br />
    if (request.readyState==4 &#038;&#038; request.status==200) {<br />
        playlist( request.responseText, file.fileName);<br />
    }<br />
}</p>
<p>... more code to follow</p>
<p>function playlist(location, name) {<br />
	var newobj = document.createElement('p');<br />
	newobj.innerHTML = '&lt;a href="' + location + '">' + name + "&lt;/a>";<br />
	playListElement.appendChild(newobj);<br />
}<br />
</code><br />
When the XMLHTTPRequest is complete, I intend on allowing the user to click on a link so that they could download the file that they have uploaded.</p>
<p>Now earlier I stated that Firefox is different than Chrome and Safari in terms of uploading files.</p>
<p>For Firefox I had to create the multiformboundary, which is the information the &lt;form> uses when it passes data through the POST or GET method.  In the multiformboundary I attached the file and the file name so in the backend, I can grab the file.  Once I created the file I can call the sendAsBinary method, pass in my newly created multiformboundary and send away.  This method is only limited to Firefox and cannot be used by other browsers.<br />
<code><br />
var boundary = '------multipartformboundary' + (new Date).getTime();<br />
		var dashdash = '--';<br />
		var crlf     = '\r\n';<br />
		var builder = '';</p>
<p>		builder += dashdash;<br />
		builder += boundary;<br />
		builder += crlf;<br />
		builder += 'Content-Disposition: form-data; name="user_file"';<br />
		if (file.fileName) {<br />
			builder += '; filename="' + file.fileName + '"';<br />
		}<br />
		builder += crlf;<br />
		builder += 'Content-Type: application/octet-stream';<br />
		builder += crlf;<br />
		builder += crlf; </p>
<p>		/* Append binary data. */<br />
		builder += file.getAsBinary();<br />
		builder += crlf;</p>
<p>		/* Write boundary. */<br />
		builder += dashdash;<br />
		builder += boundary;<br />
		builder += crlf;</p>
<p>		/* Mark end of the request. */<br />
		builder += dashdash;<br />
		builder += boundary;<br />
		builder += dashdash;<br />
		builder += crlf;</p>
<p>		/* FOR FIREFOX 3.6 ONLY */<br />
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");<br />
		request.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary); // make sure to set a boundary<br />
		request.setRequestHeader("Connection", "close");<br />
		request.sendAsBinary(builder);<br />
</code></p>
<p>For both Chrome and Safari I was able to use a new method called FormData.  What FormData does is that it handles all of the multiformboundary and all I need to do is attach my variable name and my object.  Now there is a big difference in what the new XMLHTTPRequest and the old XMLHTTPRequest can do.  Prior to the W3C standards update, the XMLHTTPRequest could only take in strings.  Now after the standards update, the XMLHTTPRequest can accept blob = binary large object.  As a result we are now able to pass in our FormData through the XMLHttpRequest.<br />
<code><br />
var formData = new FormData();<br />
formData.append("user_file", file);<br />
request.send(formData);<br />
</code></p>
<p>Now we are pretty much done.  All of the javascript and HTML code has been written out.  All we need to do is write a PHP file upload script that would take the file we sent it and actually upload the file.  This would be our &#8220;upload.php&#8221; as defined in our variable &#8216;url&#8217;.  What this code will do is print out the path of where the file is so when the XMLHTTPRequest is completed I can use the path of the file as a way to link the user to download their file that they have just uploaded.<br />
<code><br />
<?php<br />
	$target_path = "upload/".$_FILES['user_file']['name'];<br />
	if(move_uploaded_file($_FILES['user_file']['tmp_name'], $target_path)) {<br />
		echo $target_path;<br />
	}<br />
?><br />
</code></p>
<p>And there we have it.  An HTML 5 Drag and Drop Upload that works.<br />
I have attached my own file that you can download if you want &#8211; <a href="http://www.josh-ho.com/blog/Files/draganddropupload.zip">Drag and Drop Upload</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/html-5-drag-and-drop-file-upload/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>HTML 5 &#8211; Canvas</title>
		<link>http://www.josh-ho.com/html-5-canvas/</link>
		<comments>http://www.josh-ho.com/html-5-canvas/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 02:08:33 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=314</guid>
		<description><![CDATA[HTML 5 brings a lot of new elements and tags and hands them to developers / designers to develop websites. Previously I wrote about the &#60;video> tag and how to create a video element and playing a video &#8211; Blog post can be found here. In this post, I&#8217;m going to explore the &#60;canvas> tag. [...]]]></description>
			<content:encoded><![CDATA[<p>HTML 5 brings a lot of new elements and tags and hands them to developers / designers to develop websites.  Previously I wrote about the &lt;video> tag and how to create a video element and playing a video &#8211; <a href="http://www.josh-ho.com/blog/?p=292">Blog post can be found here</a>.  In this post, I&#8217;m going to explore the &lt;canvas> tag.  The Canvas element is an HTML object that allows for dynamic objects to be rendered on a webpage.</p>
<p>We can start of an HTML 5 document as follows:<br />
<code><br />
&lt;!DOCTYPE HTML><br />
&lt;html><br />
&lt;head><br />
&lt;title>HTML 5 Canvas Tag Test&lt;/title><br />
&lt;/head><br />
&lt;body><br />
... code goes in here<br />
&lt;/body><br />
&lt;/html><br />
</code></p>
<p>To create the canvas tag we just call &lt;canvas>.  There are 3 important parameters that we can apply to the &lt;canvas> tag</p>
<table>
<tr>
<td width='150'>id
<td>
<td>assigns an identifer to the &lt;canvas> tag</td>
</tr>
<tr>
<td>width
<td>
<td>defines the width of the canvas tag</td>
</tr>
<tr>
<td>height
<td>
<td>defines the height of the canvas tag</td>
</tr>
</table>
<p>With that in mind we apply those properties on our tag as follows.  In this example we are going to designate the canvas as a 400&#215;400 pixel canvas.<br />
<code><br />
&lt;canvas id="myCanvas" width="400" height="400">&lt;/canvas><br />
</code></p>
<p>If we save everything and upload the file now, we would not see anything from our &lt;canvas> tag.  The only problem is, we did not assign anything to be rendered inside that canvas object and thus nothing is displayed.</p>
<p>In order to draw an object we can use javascript to draw a box inside of our object.  In our case we want to draw a 200&#215;200 pixel red box inside our canvas object.<br />
<code><br />
&lt;script><br />
var canvas = document.getElementById('myCanvas');<br />
var canvasContext = canvas.getContext("2d");<br />
canvasContext.fillStyle="#FF0000";<br />
canvasContext.fillRect(0,0,200,200);<br />
&lt;/script><br />
</code></p>
<p>What we have done is accessed the canvas tag and applied the getContext object on the canvas.  getContext() is a built in HTML 5 object that can create objects inside the canvas.  We apply the getContext() in our canvasContext variable and with that we can assign the colour &#8211; fillStyle; red (#FF0000), and what object to draw &#8211; fillRect; (x, y, width, height &#8211; 0, 0, 200, 200).  If we want to move the rectangle we can adjust the x and y values in the fillRect, which would change the x and y location of the red box we have just created.</p>
<p>That is it, we now can draw on our canvas using HTML 5 and Javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/html-5-canvas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML 5 &#8211; Video Tag</title>
		<link>http://www.josh-ho.com/html-5-video-tag/</link>
		<comments>http://www.josh-ho.com/html-5-video-tag/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 16:06:21 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=292</guid>
		<description><![CDATA[The W3C &#8211; The World Wide Web Consortium has started updating the HTML standard for displaying objects on the web. They are the ones that define how HTML tags should work. With HTML 5, the W3C is starting to move away from the reliance on plugins to play video or audio objects, while also creating [...]]]></description>
			<content:encoded><![CDATA[<p>The W3C &#8211; The World Wide Web Consortium has started updating the HTML standard for displaying objects on the web.  They are the ones that define how HTML tags should work.  With HTML 5, the W3C is starting to move away from the reliance on plugins to play video or audio objects, while also creating new HTML tags that are commonly used on websites &#8211; such as footers, or navigation.  More importantly, HTML 5 came out with new API&#8217;s that are available for use.</p>
<p>In this example we will take a look at one of the new tags &#8211; video.  And use the new API&#8217;s defined in HTML 5 to play / pause the video.</p>
<p>Creating an HTML 5 document is not hard. It is the same as creating the HTML 4 standard.<br />
<code><br />
&lt;!DOCTYPE HTML><br />
&lt;html><br />
&lt;head><br />
&lt;title>HTML 5 Video Tag Test&lt;/title><br />
&lt;/head><br />
&lt;body><br />
... code goes in here<br />
&lt;/body><br />
&lt;/html><br />
</code></p>
<p>Now we want to add the video tag.  According to the W3C &#8211; <a href="http://dev.w3.org/html5/spec/Overview.html#video" onclick="pageTracker._trackPageview('/outgoing/dev.w3.org/html5/spec/Overview.html_video?referer=');">http://dev.w3.org/html5/spec/Overview.html#video</a> we can define a video tag by using &lt;video&gt;.  There are some attributes that we can use to define the video tag:</p>
<table>
<tr>
<td width='150'>src
<td>
<td>defines the video source</td>
</tr>
<tr>
<td>width and height
<td>
<td>defines the width and height of the video object</td>
</tr>
<tr>
<td>loop
<td>
<td>allows the video object to loop at the end of the video</td>
</tr>
<tr>
<td>autoplay
<td>
<td>defines if the video should play once the video tag has been loaded</td>
</tr>
<tr>
<td>controls
<td>
<td>defines if the video controls should be displayed</td>
</tr>
<tr>
<td>preload
<td>
<td>defines if the video should preload the file when the website loads</td>
</tr>
</table>
<p>In our example we want to use the src and the controls so we can start and stop playing.  To do so we have to include the video tag in our code.  We must define controls as &#8220;controls&#8221; so that the browser would display the basic, play / pause buttons.<br />
<code><br />
&lt;video controls="controls" src="myvideo.ogg"><br />
 your browser does not support the video tag<br />
&lt;/video><br />
</code></p>
<p>As you can see I have a simple copy inside the video tag that claims that the user&#8217;s browser does not support the video tag.  With HTML 5 still being worked on, not all browsers can view the HTML 5 standard.  As a result, those browsers would not be able to render the video tag.  Instead they would see the copy &#8220;your browser does not support the video tag&#8221;.</p>
<p>Also note, because HTML 5 has not been fully standardized yet, the video tag is still up in the air.  Different browsers can only play different video types.  Firefox and Opera browsers can play .ogg files &#8211; more commonly known as Ogg Vorbis, while Safari can play H264 videos.  Chrome can play both ogg and H264 files.  The debate on which video files to play is still underway.  Ogg Vorbis is open source while H264 is not.  However since the video tag has not been fully standardized yet, this debate still continues.</p>
<p>In our case we are going with the .ogg format.  Now if you are on a Safari browser, you can change the src to a .mp4 file format, which uses the H264 video.</p>
<p>Now we do not need to use the browser&#8217;s controls to play / pause the video.  We can use the HTML 5 Video API for that.</p>
<p>We can add a couple of anchor tags to our code so we can play or pause the video.</p>
<p><code><br />
&lt;a href="#" onClick="myControlFunction('play');">Play&lt;/a><br />
&lt;a href="#" onClick="myControlFunction('pause');">Pause&lt;/a><br />
</code></p>
<p>We can use javascript to control the video tag and use the HTML 5 Video API.  According to the W3C we can tell the video object to play and pause by using the play() and pause() methods.</p>
<p><code><br />
&lt;script><br />
function myControlFunction(videoSelect){<br />
&nbsp;&nbsp;var video = document.querySelector('video');<br />
&nbsp;&nbsp;if( videoSelect == "play" ) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;video.play();<br />
&nbsp;&nbsp;} else if( videoSelect == "pause" ){<br />
&nbsp;&nbsp;&nbsp;&nbsp;video.pause();<br />
&nbsp;&nbsp;}<br />
}<br />
&lt;/script><br />
</code></p>
<p>What this code does is that it searches for the video tag and sets it in the variable I designated called &#8220;video&#8221;.  With the object in my &#8220;video&#8221; variable, I can use the Video API methods of play() and pause(), to play or pause the video.  I passed in a small variable into my function which would tell me which button was pressed.  If the play button was pressed, I want the video to play and vice versa.</p>
<p>And there we have it, a simple play pause video demo using HTML 5 and the Video HTML 5 API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/html-5-video-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seize The Summer with Molson Canadian</title>
		<link>http://www.josh-ho.com/seize-the-summer-with-molson-canadian/</link>
		<comments>http://www.josh-ho.com/seize-the-summer-with-molson-canadian/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 19:18:16 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Website Lauched]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.josh-ho.com/blog/?p=279</guid>
		<description><![CDATA[The summer is here and we have lunched a new Facebook application with Molson Canadian. It is a pretty neat application where people can earn badges for doing things the love and eventually win prizes for doing those things. I am pretty excited for this application, it is a very fun application. We utilized the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.josh-ho.com/blog/Images/sts.jpg" alt="Molson Canadian Seize The Summer" /></p>
<p>The summer is here and we have lunched a new Facebook application with Molson Canadian.  It is a pretty neat application where people can earn badges for doing things the love and eventually win prizes for doing those things.  I am pretty excited for this application, it is a very fun application.  We utilized the Facebook API fully and integrated with our own customized API to produce a Facebook application we are happy to showcase.</p>
<p>Check it out</p>
<p><a href="http://apps.facebook.com/seizethesummer" onclick="pageTracker._trackPageview('/outgoing/apps.facebook.com/seizethesummer?referer=');">Molson Canadian Seize The Summer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josh-ho.com/seize-the-summer-with-molson-canadian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

