<?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>Devirtuoso &#187; Experimental</title>
	<atom:link href="http://www.devirtuoso.com/category/experimental/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devirtuoso.com</link>
	<description>Web Development Wickedness</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:16:01 +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>Canvas Image Manipulation Experiment</title>
		<link>http://www.devirtuoso.com/2011/09/canvas-image-manipulation-experiment/</link>
		<comments>http://www.devirtuoso.com/2011/09/canvas-image-manipulation-experiment/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 16:17:32 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Labs]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1350</guid>
		<description><![CDATA[There are plenty of cool things that HTML 5 has to offer. Here lies an experiment with the canvas and image manipulation. Oh what FUN! Canvas Experiment (Best viewed on Chrome / Safari) Just a brief description of what I built. We first pull in all the image data, and convert them to particles. Then [...]]]></description>
			<content:encoded><![CDATA[<p>There are plenty of cool things that <strong>HTML 5</strong> has to offer.  Here lies an experiment with the <strong>canvas</strong> and image manipulation. Oh what FUN!<br />
<span id="more-1350"></span></p>
<h2>Canvas Experiment (Best viewed on Chrome / Safari)</h2>
<p>Just a brief description of what I built.  We first pull in all the image data, and convert them to particles.  Then let the playing happen.  In this case I just made the particles jump away from the mouse, then jump back.  I heavily commented the code to help you look through it.</p>
<p><a class="Example" href="http://devirtuoso.com/Examples/ImageManipulation/" target="_blank"><img src="http://www.devirtuoso.com/wp-content/uploads/2011/09/imageManipulation.png" alt="Canvas Image Manipulation" /></a></p>
<h3 style="color: red;">Does not work locally! Image needs to be on server somewhere.</h3>
<p>If you try to load in a local image or an image from another domain you will get a javascript security error.  To get around this you can encode the image into base64.  <a href="http://www.greywyvern.com/code/php/binary2base64" target="_blank">Here is a handy tool for that&#8230;.very simple to use.</a></p>
<div class="resources"><a class="Download" href="http://devirtuoso.com/Examples/ImageManipulation/imageManipulation.zip" target="_blank">Download</a> <a class="Example" href="http://devirtuoso.com/Examples/ImageManipulation/" target="_blank">Example</a></div>
<p><a href="http://jsfiddle.net/devirtuoso/m2bbZ/embedded/result/" target="_blank">Play with the code on JSFiddle</a></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Canvas Image<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
&nbsp; body{<br />
&nbsp; &nbsp; background:black;<br />
&nbsp; }<br />
&nbsp; &nbsp; canvas{<br />
&nbsp; &nbsp; &nbsp; width:900px;<br />
&nbsp; &nbsp; &nbsp; height:200px;<br />
&nbsp; &nbsp; &nbsp; background:none;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #canvasSource{<br />
&nbsp; &nbsp; &nbsp; display:none;<br />
&nbsp; &nbsp; }<br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">&lt;!-- HTML Code --&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;canvasSource&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;picture.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Canvas Source&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;area&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;900&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;200&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span> &gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
//Image Manipulation Javascript will go here.<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">window.<span style="color: #000066;">onload</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><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Checks if a pixel is white or not<br />
&nbsp; &nbsp; * @param {Object} pixel A pixel with an rgb value<br />
&nbsp; &nbsp; * @returns Is the pixel white or not.<br />
&nbsp; &nbsp; * @type Boolean<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> isPixelWhite <span style="color: #009900;">&#40;</span>pixel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>pixel.<span style="color: #660066;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">&amp;&amp;</span> pixel.<span style="color: #660066;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">&amp;&amp;</span> pixel.<span style="color: #660066;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Converts an rgb value to hex<br />
&nbsp; &nbsp; * @param {Number} R The red value<br />
&nbsp; &nbsp; * @param {Number} G The green value<br />
&nbsp; &nbsp; * @param {Number} B The blue value<br />
&nbsp; &nbsp; * @returns A hex value based on the rgb given<br />
&nbsp; &nbsp; * @type String<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> rgbToHex<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> toHex<span style="color: #009900;">&#40;</span>R<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>toHex<span style="color: #009900;">&#40;</span>G<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>toHex<span style="color: #009900;">&#40;</span>B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * convert value from 0-255 to hex.<br />
&nbsp; &nbsp; * @param {Number} n Number between 0 and 255<br />
&nbsp; &nbsp; * @returns Hex value<br />
&nbsp; &nbsp; * @type String<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> toHex<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;n <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;00&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;n <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span><span style="color: #CC0000;">255</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;0123456789ABCDEF&quot;</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">-</span>n<span style="color: #339933;">%</span>16<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;0123456789ABCDEF&quot;</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">%</span>16<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Extends an array with the given options<br />
&nbsp; &nbsp; * @param {Object} obj The main object<br />
&nbsp; &nbsp; * @param {Object} extObj The extending object<br />
&nbsp; &nbsp; * @returns The merged objects<br />
&nbsp; &nbsp; * @type Object<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> extend <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>obj<span style="color: #339933;">,</span> extObj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> extObj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>extObj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;obj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> extObj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> obj<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Pixel Class<br />
&nbsp; &nbsp; * @author Shawn<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> Particle <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Default Values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#fff&quot;</span><span style="color: #339933;">,</span>x<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>width<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> angle<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; params <span style="color: #339933;">=</span> extend<span style="color: #009900;">&#40;</span>params<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Init Variables</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">color</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">originalX</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">originalY</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">angle</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">180</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speed</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">speed</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Sets x,y value based on current angle.<br />
&nbsp; &nbsp; * @returns <br />
&nbsp; &nbsp; * @type Void<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Particle.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getVector</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><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Sets the current angle<br />
&nbsp; &nbsp; * @param {Number} angle Angle to set it at<br />
&nbsp; &nbsp; * @returns Angle given, but rounded<br />
&nbsp; &nbsp; * @type Number<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Particle.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setAngle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Convert to radians, so it's useful.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span> <span style="color: #339933;">=</span> angle <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">180</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> angle <span style="color: #339933;">|</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Gets the current angle<br />
&nbsp; &nbsp; * @returns The current angle<br />
&nbsp; &nbsp; * @type Number<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Particle.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getAngle</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Converts angle from radians to angle then rounds it.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">angle</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">180</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Emits particles<br />
&nbsp; &nbsp; * @author Shawn<br />
&nbsp; &nbsp; * @requires Particle<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> Emitter <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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Initial values.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">maxParticles</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">20000</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">active</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Adds a particle to the emitter<br />
&nbsp; &nbsp; * @param {Object} options Particle options<br />
&nbsp; &nbsp; * @returns The particle just added<br />
&nbsp; &nbsp; * @type Particle<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Emitter.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addParticle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Make sure there is less particles than the max amount</span><br />
&nbsp; &nbsp; &nbsp; &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;">particles</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">maxParticles</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Set particle default values.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#fff&quot;</span><span style="color: #339933;">,</span>x<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span><span style="color: #339933;">,</span>y<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params <span style="color: #339933;">=</span> extend<span style="color: #009900;">&#40;</span>params<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Add particle to emitter.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> p <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Particle<span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> p<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Gets a particle at a given identifier<br />
&nbsp; &nbsp; * @param {Number} id Particles identifier<br />
&nbsp; &nbsp; * @returns A particle<br />
&nbsp; &nbsp; * @type Particle<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Emitter.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getParticle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span><span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Get how many particles there are.<br />
&nbsp; &nbsp; * @returns Number of particles<br />
&nbsp; &nbsp; * @type Number<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; Emitter.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getLength</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><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">particles</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp;* Paul Irish's method for requesting animation frame<br />
&nbsp; &nbsp;* @returns Animation Frame<br />
&nbsp; &nbsp;* @type Function<br />
&nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; window.<span style="color: #660066;">requestAnimFrame</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</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><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> &nbsp;window.<span style="color: #660066;">requestAnimationFrame</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">webkitRequestAnimationFrame</span> <span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">mozRequestAnimationFrame</span> &nbsp; &nbsp;<span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">oRequestAnimationFrame</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">msRequestAnimationFrame</span> &nbsp; &nbsp; <span style="color: #339933;">||</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-style: italic;">/* function */</span> callback<span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">/* DOMElement */</span> element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span>callback<span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Setup canvas.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;area&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> image <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;canvasSource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; ctx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>image<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//get Image data.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> imgData <span style="color: #339933;">=</span> ctx.<span style="color: #660066;">getImageData</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">900</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> pixels <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> mouseX<span style="color: #339933;">,</span> mouseY <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> affecetedArea <span style="color: #339933;">=</span> <span style="color: #CC0000;">70</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> emit <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Emitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Create a particle based on the image data.</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Image data is ordered like r,g,b,a,r,g,b,a...need to count by 4</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> imgData.<span style="color: #660066;">data</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">+=</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> pixel <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">r</span> <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">g</span> <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">b</span> <span style="color: #339933;">=</span> imgData.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">index</span> <span style="color: #339933;">=</span> i <span style="color: #339933;">/</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Setup columns and rows</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> pixel.<span style="color: #660066;">index</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">900</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pixel.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>pixel.<span style="color: #660066;">index</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">900</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//The white pixels are the only ones we want to animate.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isPixelWhite<span style="color: #009900;">&#40;</span>pixel<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Pick a random angle.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">360</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; emit.<span style="color: #660066;">addParticle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>rgbToHex<span style="color: #009900;">&#40;</span>pixel.<span style="color: #660066;">r</span><span style="color: #339933;">,</span>pixel.<span style="color: #660066;">g</span><span style="color: #339933;">,</span>pixel.<span style="color: #660066;">b</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span>x<span style="color: #339933;">:</span> pixel.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> pixel.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> angle<span style="color: #339933;">:</span>angle <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Mouse Move Handler...set the mouseX and MouseY variables<br />
&nbsp; &nbsp; * @param {Object} e Event Object<br />
&nbsp; &nbsp; * @returns Nothing<br />
&nbsp; &nbsp; * @type Void<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#area'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">offsetX</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX <span style="color: #339933;">=</span> e.<span style="color: #660066;">offsetX</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY <span style="color: #339933;">=</span> e.<span style="color: #660066;">offsetY</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">layerX</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX <span style="color: #339933;">=</span> e.<span style="color: #660066;">layerX</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY <span style="color: #339933;">=</span> e.<span style="color: #660066;">layerY</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Start animation loop.</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> animate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; requestAnimFrame<span style="color: #009900;">&#40;</span> animate <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; animate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> oldx<span style="color: #339933;">,</span>oldy<span style="color: #339933;">,</span>newx<span style="color: #339933;">,</span>newy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">/**<br />
&nbsp; &nbsp; * Draws each frame<br />
&nbsp; &nbsp; * @returns Nothing<br />
&nbsp; &nbsp; * @type Void<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">900</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Render each particle in the emitter.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> emit.<span style="color: #660066;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> p <span style="color: #339933;">=</span> emit.<span style="color: #660066;">getParticle</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Calculate the distance of the particle from the mouse.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> distx <span style="color: #339933;">=</span> p.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> mouseX<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> disty <span style="color: #339933;">=</span> p.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> mouseY<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> distance <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span>distx<span style="color: #339933;">*</span>distx <span style="color: #339933;">+</span> disty<span style="color: #339933;">*</span>disty<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//If it's within the affected area.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>distance <span style="color: #339933;">&lt;</span> affecetedArea<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Push the particle out of the way.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//p.x -= (Where the particle currently is - Where you want the particle to end up) / speed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">x</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">+</span> affecetedArea <span style="color: #339933;">*</span> distx <span style="color: #339933;">/</span> distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">y</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>mouseY <span style="color: #339933;">+</span> affecetedArea <span style="color: #339933;">*</span> disty <span style="color: #339933;">/</span> distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Return the particle to it's original place.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span> <span style="color: #339933;">!=</span> p.<span style="color: #660066;">originalX</span> <span style="color: #339933;">||</span> p.<span style="color: #660066;">y</span> <span style="color: #339933;">!=</span> p.<span style="color: #660066;">originalY</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">x</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> p.<span style="color: #660066;">originalX</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #660066;">y</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> p.<span style="color: #660066;">originalY</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Draw the particle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> p.<span style="color: #660066;">color</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">,</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">,</span>p.<span style="color: #660066;">width</span><span style="color: #339933;">,</span>p.<span style="color: #660066;">width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/09/canvas-image-manipulation-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Future of the Web is WebGL</title>
		<link>http://www.devirtuoso.com/2011/03/the-future-of-the-web-is-webgl/</link>
		<comments>http://www.devirtuoso.com/2011/03/the-future-of-the-web-is-webgl/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 16:18:25 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1317</guid>
		<description><![CDATA[So what&#8217;s in store for the web in the future?  Is it more bejeweled games? Or is it 3d first person shooters?A big shout out goes to Human Engines and Gregg Tavares.  This is a demo I came accross of WebGL in all it&#8217;s glory and had to share it.  The performance is pretty good [...]]]></description>
			<content:encoded><![CDATA[<p>So what&#8217;s in store for the web in the future?  Is it more bejeweled games? Or is it 3d first person shooters?<span id="more-1317"></span>A big shout out goes to Human Engines and Gregg Tavares.  This is a demo I came accross of WebGL in all it&#8217;s glory and had to share it.  The performance is pretty good considering all the reflections and volumetrics.  Very cool stuff.</p>
<p>You can check out the experiment at: <strong>THIS REQUIRES GOOGLE CHROME</strong></p>
<p><a href="http://webglsamples.googlecode.com/hg/aquarium/aquarium.html" target="_blank">http://webglsamples.googlecode.com/hg/aquarium/aquarium.html</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="390" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/9pM9LBcKxK4&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="390" src="http://www.youtube.com/v/9pM9LBcKxK4&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2011/03/the-future-of-the-web-is-webgl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Sphere</title>
		<link>http://www.devirtuoso.com/2009/09/google-sphere/</link>
		<comments>http://www.devirtuoso.com/2009/09/google-sphere/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 01:29:51 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[showcase]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1174</guid>
		<description><![CDATA[Once again Google is broken in this fantastic experiment.  From the maker of Google Gravity, this experiment takes Google and forms it into a sphere. Google Sphere I love Mr.doob’s work.  Big points for creativity. The best part about it is that the image search still works. Again this one requires Chrome to view it, [...]]]></description>
			<content:encoded><![CDATA[<p>Once again Google is broken in this fantastic experiment.  From the maker of <a title="Google Gravity" href="http://www.devirtuoso.com/2009/08/google-gravity/" target="_self">Google Gravity</a>, this experiment takes Google and forms it into a sphere.</p>
<p><span id="more-1174"></span></p>
<h3><a title="Google Sphere" href="http://mrdoob.com/projects/chromeexperiments/google_sphere/" target="_blank">Google Sphere</a></h3>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/ttQuzEEsHhg&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;feature=player_embedded&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/ttQuzEEsHhg&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;feature=player_embedded&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>I love Mr.doob’s work.  Big points for creativity. The best part about it is that the image search still works.</p>
<p>Again this one requires Chrome to view it, he uses the webkit to transform his Actionscript 3 3d engine into JavaScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/google-sphere/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Sphere Using jQuery</title>
		<link>http://www.devirtuoso.com/2009/09/3d-sphere-using-jquery/</link>
		<comments>http://www.devirtuoso.com/2009/09/3d-sphere-using-jquery/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 17:53:35 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1166</guid>
		<description><![CDATA[Ever wanted your tag cloud to resemble a ball?&#160; Of course you did.&#160; This tutorial will walk you through how to create a Sphere in jQuery. &#160; What We Are Building This one can bog down a system in a hurry, but that’s the fun with experimenting with JavaScript.&#160; We will be building a sphere [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted your tag cloud to resemble a ball?&#160; Of course you did.&#160; This tutorial will walk you through how to create a Sphere in jQuery.</p>
<p><span id="more-1166"></span></p>
<p>&#160;</p>
<h2>What We Are Building</h2>
<p>This one can bog down a system in a hurry, but that’s the fun with experimenting with JavaScript.&#160; We will be building a sphere that rotates depending on which way the mouse moves….exciting.</p>
<div class="resources">
	 <a href="http://www.devirtuoso.com/Examples/3D-Engine/sphere.zip"class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/3D-Engine/sphere.html"class="Example" target="_blank">Example</a>
</div>
<p><a title="3d sphere" href="http://www.devirtuoso.com/Examples/3D-Engine/sphere.html" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="sphere" border="0" alt="sphere" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image38.png" width="419" height="420" /></a> </p>
<p>&#160;</p>
<h2>Getting Started</h2>
<p>This tutorial is a continuation of a line of 3D jQuery posts.&#160; I would recommend you having a look at the previous post so you’re up to speed.</p>
<ul>
<li><a title="Making a 3D Engine in jQuery" href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank">Making a 3D Engine in jQuery</a> </li>
<li><a title="3D Plane for jQuery Engine" href="http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/" target="_blank">3D Plane for jQuery Engine</a> </li>
<li><a title="Creating a Wobbling 3D Carousel" href="http://www.devirtuoso.com/2009/09/creating-a-wobbling-3d-carousel/" target="_blank">Creating a Wobbling 3D Carousel</a> </li>
</ul>
<p>Now that is out of the way lets get started.&#160; For this project we’ll have 3 files.&#160; </p>
<ul>
<li>3DEngine.js</li>
<li>Sphere.js</li>
<li>sphere.html</li>
</ul>
<p>The 3DEngine.js is the same file that was in the previous posts so we won’t be covering that. The Sphere.js holds the Sphere class which is used by the 3D Engine.&#160; Lastly the html file puts everything together.</p>
<p>&#160;</p>
<h2>The Sphere</h2>
<p>With the sphere class we’ll be creating a set of 3d points (x,y,z) in an array.&#160; To build the sphere we’re simply going to create a whole bunch of rings that start off small, get larger, then small again.&#160; I’m not sure if this the best way of building a sphere, but it works so I’m not going to worry too much.</p>
<p>Here is the <strong>JavaScript</strong>:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Sphere <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>radius<span style="color: #339933;">,</span>sides<span style="color: #339933;">,</span> numOfItems<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Step through the number of rings.</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> sides <span style="color: #339933;">;</span> j <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Step through each point on a ring.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <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> numOfItems <span style="color: #339933;">/</span> sides<span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Space out each point evenly.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> i <span style="color: #339933;">*</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>numOfItems<span style="color: #339933;">/</span>sides<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angleB <span style="color: #339933;">=</span> j <span style="color: #339933;">*</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">/</span> sides<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Figure out the x,y,z co-ordinates of each point.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> &nbsp; Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angleB<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> &nbsp;Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angleB<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> z <span style="color: #339933;">=</span> &nbsp;Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>angleB<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span> radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Put the point in an array.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Need to extend class to work in 3d engine.</span><br />
Sphere.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>There are two loops.&#160; One for the number of rings, the other for the points within each ring.&#160; Inside the inner loop we first figure out where each point should lie, then figure out how that would translate into the x, y and z co-ordinates.</p>
<p>&#160;</p>
<h2>The jQuery / Html</h2>
<p>Not much has changed in our jQuery / HTML since the <a title="3d Plane" href="http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/" target="_blank">3d Plane</a> post.&#160; The only thing that has changed is we imported the Sphere.js and instead of adding a plane, we’re adding a sphere.</p>
<p>Here is the <strong>HTML</strong>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3DEngine.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sphere.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; //<span style="color: #404040;">&lt;![CDATA[</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; $(document).ready(function() {</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //Init Camera</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var camera = new Camera3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; camera.init(0,0,0,300);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var container = $(&quot;#item&quot;)</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //Create object holder</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var item = new Object3D(container);</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //Add sphere to the object holder</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; item.addChild(new Sphere(200,10,100));</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //Create scene</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var scene = new Scene3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //Add object holder to the scene</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; scene.addToScene(item);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var mouseX,mouseY = 0;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var offsetX = $(&quot;#item&quot;).offset().left;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var offsetY = $(&quot;#item&quot;).offset().top;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var speed = 6000;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //Figure out where the mouse is when the mouse is moved.</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; $().mousemove(function(e){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX = e.clientX - offsetX - (container.width() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY = e.clientY - offsetY - (container.height() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var animateIt = function(){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //rotate the sphere along the y axis when the mouse</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //mouse is moved left and right</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mouseX != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.y += (mouseX) / speed</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //rotate along the x axis when the mouse is moved</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //up and down.</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mouseY != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.x -= mouseY / speed;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Render the scene.</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.renderCamera(camera);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; };</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; setInterval(animateIt, 20);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; //]]&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>Disclaimer</h2>
<p>Be careful adding points on this one.&#160; Because the 3D engine doesn’t use html’s canvas just yet, it really can’t handle too many points. I can get away with 100 points on my machine without too much delay.&#160; Chrome handles it the best out of all the browsers I tried.&#160; So use it at your own discretion, you might have some angry viewers if you go too nuts.&#160; This is just meant to be experimental…and cool.</p>
<p>The next step will be to optimize the 3D Engine a bit using the canvas so there won’t be this problem in the future.</p>
<p>&#160;</p>
<p>Here is all the code together:</p>
<p><strong>JavaScript</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Sphere <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>radius<span style="color: #339933;">,</span>sides<span style="color: #339933;">,</span> numOfItems<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> sides <span style="color: #339933;">;</span> j <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <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> numOfItems <span style="color: #339933;">/</span> sides<span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> i <span style="color: #339933;">*</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>numOfItems<span style="color: #339933;">/</span>sides<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angleB <span style="color: #339933;">=</span> j <span style="color: #339933;">*</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">/</span> sides<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> &nbsp; Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angleB<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> &nbsp;Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angleB<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> z <span style="color: #339933;">=</span> &nbsp;Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>angleB<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span> radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Sphere.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p><strong>HTML</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>3d engine<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #item{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: relative;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ul{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #69c;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-weight: bold;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size:2em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3DEngine.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sphere.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; //<span style="color: #404040;">&lt;![CDATA[</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function() {</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var camera = new Camera3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camera.init(0,0,0,300);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var container = $(&quot;#item&quot;)</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var item = new Object3D(container);</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item.addChild(new Sphere(200,10,100));</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var scene = new Scene3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.addToScene(item);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var mouseX,mouseY = 0;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var offsetX = $(&quot;#item&quot;).offset().left;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var offsetY = $(&quot;#item&quot;).offset().top;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var speed = 6000;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $().mousemove(function(e){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX = e.clientX - offsetX - (container.width() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY = e.clientY - offsetY - (container.height() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var animateIt = function(){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mouseX != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.y += (mouseX) / speed</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mouseY != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.x -= mouseY / speed;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.renderCamera(camera);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setInterval(animateIt, 20);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //]]&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources">
	 <a href="http://www.devirtuoso.com/Examples/3D-Engine/sphere.zip"class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/3D-Engine/sphere.html"class="Example" target="_blank">Example</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/3d-sphere-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a Wobbling 3D Carousel</title>
		<link>http://www.devirtuoso.com/2009/09/creating-a-wobbling-3d-carousel/</link>
		<comments>http://www.devirtuoso.com/2009/09/creating-a-wobbling-3d-carousel/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 07:07:33 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[carousel]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1151</guid>
		<description><![CDATA[We’ve all seen a carousel in one form or another.&#160; This post will show how to create a carousel with a wobbling effect, much like an unbalanced wheel. &#160; What We’re Building We’ll be creating a carousel with the help of the 3d Engine we built in a previous post.&#160; The idea is we’ll create [...]]]></description>
			<content:encoded><![CDATA[<p>We’ve all seen a carousel in one form or another.&#160; This post will show how to create a carousel with a wobbling effect, much like an unbalanced wheel.</p>
<p><span id="more-1151"></span></p>
<p>&#160;</p>
<h2>What We’re Building</h2>
<p>We’ll be creating a carousel with the help of the <a title="3d engine jquery" href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank">3d Engine</a> we built in a previous post.&#160; The idea is we’ll create a ring by plotting points in 3d space, then we’ll rotate it so it’s almost perpendicular to the viewer.&#160; Because it’s not 100% flat, it will look like it’s wobbling up and down, giving your carousel a little more flavor.</p>
<div class="resources"> <a href="http://www.devirtuoso.com/Examples/3D-Engine/ring.zip" class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/3D-Engine/ring.html"class="Example" target="_blank">Example</a></div>
<p><a href="http://www.devirtuoso.com/Examples/3D-Engine/ring.html" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="carousel" border="0" alt="carousel" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image37.png" width="445" height="146" /></a></p>
<p>&#160;</p>
<h2>Building the Ring</h2>
<p>If you haven’t read up on the  <a href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank">3d Engine</a> just yet I recommend you do so.&#160; Creating objects for the engine isn’t overly complicated.&#160; It’s just an array of 3d points.&#160; With the ring, we’re going to use math to plot the points for us.&#160; We’re going to be creating a circle and plot it in 3d space.</p>
<p>Here is the <strong>JavaScript</strong>: (Ring.js)</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Ring <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>radius<span style="color: #339933;">,</span> numOfItems<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Step through each point on ring.</span><br />
&nbsp; &nbsp; <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> numOfItems <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Figure out where each point lies on the circle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> i <span style="color: #339933;">*</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">/</span> numOfItems<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Translate that point on the circle into x,y coordinates.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> &nbsp;Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> z <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Add the point to the array.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//You need to inherit the DisplayObject3D.</span><br />
Ring.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>The Ring class takes 2 parameters, the first is the radius of the ring, and the second is how many items are going to be on the ring.</p>
<p>We then proceed to step through all the points, and place them at equal distances around the ring.</p>
<p>&#160;</p>
<h2>The HTML </h2>
<p>There isn’t much too the html.&#160; We’re simply going to create a &lt;ul&gt; with a bunch of words in it.</p>
<p>Here is the <strong>HTML</strong>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>website<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>3D<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Ajax<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Design<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Flash<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Experimental<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Development<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>web<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Tutorial<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>ASP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>&#160;</p>
<h2>The jQuery</h2>
<p>There is not much changed from our previous post on <a title="how to create a 3d plane for jQuery 3D Engine" href="http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/" target="_blank">how to create a 3d plane for jQuery 3D Engine</a>.&#160; The only difference here is we’re going to give an initial value to the axisRotation x value.&#160; This will rotate the ring towards the viewer.&#160; Through trial and error I figured out the value that worked for me.</p>
<p>Then we’ll animate the axisRotation y value when the mouse moves left and right.</p>
<p>Here is the <strong>jQuery</strong>:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</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><br />
<br />
<span style="color: #006600; font-style: italic;">//setup camera.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> camera <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Camera3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
camera.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> container <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Setup 3d object holder.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object3D<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Add ring to 3d object holder.</span><br />
<span style="color: #006600; font-style: italic;">//The first argument for the ring is the radius.</span><br />
<span style="color: #006600; font-style: italic;">//The second argument for the ring is how many items</span><br />
<span style="color: #006600; font-style: italic;">//are on the ring. &nbsp;So we pass in how many items are in our list.</span><br />
<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Ring<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item ul li&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">//Create a scene.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> scene <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Scene3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Add 3d object holder to the scene.</span><br />
scene.<span style="color: #660066;">addToScene</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> mouseX<span style="color: #339933;">,</span>mouseY <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> offsetX <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">left</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> offsetY <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">6000</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Capturing mouse movements.</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; mouseX <span style="color: #339933;">=</span> e.<span style="color: #660066;">clientX</span> <span style="color: #339933;">-</span> offsetX <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>container.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; mouseY <span style="color: #339933;">=</span> e.<span style="color: #660066;">clientY</span> <span style="color: #339933;">-</span> offsetY <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>container.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Rotate ring so it's almost perpendicular to the viewer.</span><br />
axisRotation.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.5</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> animateIt <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><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//When the user moves the mouse left and right,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//rotate around the ring on the y axis.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; axisRotation.<span style="color: #660066;">y</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>mouseX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> speed<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; scene.<span style="color: #660066;">renderCamera</span><span style="color: #009900;">&#40;</span>camera<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<br />
setInterval<span style="color: #009900;">&#40;</span>animateIt<span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>Voila!</h2>
<p>That’s all there is too it.&#160; </p>
<p>Here is all the code together:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>3d engine<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; #item{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: relative;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; ul{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #69c;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-weight: bold;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size:1em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>website<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>jQuery<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>JavaScript<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>3D<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Ajax<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>CSS<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Design<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Flash<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Experimental<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Development<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>web<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>Tutorial<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span>ASP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3DEngine.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ring.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; //<span style="color: #404040;">&lt;![CDATA[</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; $(document).ready(function() {</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var camera = new Camera3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; camera.init(0,0,0,300);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var container = $(&quot;#item&quot;);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var item = new Object3D(container);</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; item.addChild(new Ring(200, $(&quot;#item ul li&quot;).length));</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var scene = new Scene3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; scene.addToScene(item);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var mouseX,mouseY = 0;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var offsetX = $(&quot;#item&quot;).offset().left;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var offsetY = $(&quot;#item&quot;).offset().top;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var speed = 6000;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; $().mousemove(function(e){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseX = e.clientX - offsetX - (container.width() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mouseY = e.clientY - offsetY - (container.height() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; axisRotation.x = 1.5;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; var animateIt = function(){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mouseX != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.y += (mouseX) / speed;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.renderCamera(camera);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; };</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; setInterval(animateIt, 20);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; //]]&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Ring.js:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Ring <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>radius<span style="color: #339933;">,</span> numOfItems<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <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> numOfItems <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> i <span style="color: #339933;">*</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">/</span> numOfItems<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> &nbsp;Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>angle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> radius<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> z <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Ring.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>Just a small tip. If you wanted to create a carousel that doesn’t wobble, your first instinct might be to adjust the axisRotation x value until you get it.&#160; You can do it this way, it just might take a bit to get it right on the money.&#160; The easier way is to adjust the Ring.js file, and switch the y and z values.&#160; This will create a totally flat ring and you don’t have to worry about using the axisRotation x value to try and flatten it out.</p>
<p>&#160;</p>
<div class="resources"> <a href="http://www.devirtuoso.com/Examples/3D-Engine/ring.zip" class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/3D-Engine/ring.html"class="Example" target="_blank">Example</a></div>
<p>&#160;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/creating-a-wobbling-3d-carousel/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>3D Plane for jQuery 3D Engine</title>
		<link>http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/</link>
		<comments>http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 18:11:23 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1142</guid>
		<description><![CDATA[In the last post we created a 3D Engine with jQuery.&#160; This time around we’re going to make a new shape and make it interact with the mouse. &#160; What We’re Making I decided not to tackle too tough a shape as I wanted to show how to interact with the mouse.&#160; We’ll be making [...]]]></description>
			<content:encoded><![CDATA[<p>In the last post we created a <a title="3D Engine with jQuery" href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank">3D Engine with jQuery</a>.&#160; This time around we’re going to make a new shape and make it interact with the mouse.</p>
<p><span id="more-1142"></span></p>
<p>&#160;</p>
<h2>What We’re Making</h2>
<p>I decided not to tackle too tough a shape as I wanted to show how to interact with the mouse.&#160; We’ll be making a plane that rotates the further you get from the center.</p>
<div class="resources"> <a href="http://www.devirtuoso.com/Examples/3D-Engine/plane.zip" class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/3D-Engine/plane.html"class="Example" target="_blank">Example</a></div>
</p>
<p><a title="Plane 3D" href="http://www.devirtuoso.com/Examples/3D-Engine/plane.html" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="plane rotating" border="0" alt="plane rotating" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image33.png" width="370" height="370" /></a> </p>
<p>&#160;</p>
<h2>Getting Started</h2>
<p>If you haven’t seen how the 3D engine works I recommend visiting <a title="Making a 3D Engine in jQuery" href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank">Making a 3D Engine in jQuery</a> and getting caught up.&#160; The first thing we’re going to tackle is the plane.&#160; We’re going to create a JavaScript file that we’ll import into our HTML file. The code isn’t too complicated.&#160; We’re creating an array of 3d points.&#160; </p>
<p>Lets look at the code.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Plane <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>size<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>size <span style="color: #339933;">===</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; size <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Plane.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>It’s pretty much the same as the Cube in the previous post.&#160; The only difference is it’s less points.&#160; This would be a good opportunity to walk you through how each point is placed.&#160; The Plane class has 1 argument.&#160; The size of the Plane.&#160; We’ll use this size to plot our points.&#160; Let’s look at the first point. (-size,size,0)&#160; So if we pass in a size of 100, then the 3d point would be (-100,100,0) Which puts a point 100 points to the left and 100 up.&#160; The z value is at zero because it’s a plane.&#160; All the points are going to sit line up along the z axis.&#160; The next point is (100,100,0). This is the top right point.&#160; (100,-100,0) is bottom left. Lastly (-100,-100,0)&#160; is bottom right.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="points" border="0" alt="points" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image34.png" width="370" height="370" /> </p>
<p>&#160;</p>
<h2>Mouse Interaction</h2>
<p>Now that we have our plane made, we’ll just import it into our html file.&#160; Just like our previous post we’ll have to create our Camera,Object holder, Object and Scene. Now we’ll tackle having it interact with the mouse.</p>
<p>Here is the new jQuery:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">//Mouse x and y </span><br />
<span style="color: #003366; font-weight: bold;">var</span> mouseX<span style="color: #339933;">,</span>mouseY <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//x and y value of container</span><br />
<span style="color: #003366; font-weight: bold;">var</span> offsetX <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">left</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> offsetY <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//rotation speed</span><br />
<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">6000</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//when the mouse moves...</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Figure out how far it is from the center of the container</span><br />
&nbsp; &nbsp; mouseX <span style="color: #339933;">=</span> e.<span style="color: #660066;">clientX</span> <span style="color: #339933;">-</span> offsetX <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>container.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; mouseY <span style="color: #339933;">=</span> e.<span style="color: #660066;">clientY</span> <span style="color: #339933;">-</span> offsetY <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>container.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> animateIt <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><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Rotate along the y axis when the mouse is moved left and right</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mouseX <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; axisRotation.<span style="color: #660066;">y</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>mouseX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> speed<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Rotate along the x axis when the mouse moves up and down.</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mouseY <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; axisRotation.<span style="color: #660066;">x</span> <span style="color: #339933;">-=</span> mouseY <span style="color: #339933;">/</span> speed<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Render the scene.</span><br />
&nbsp; &nbsp; scene.<span style="color: #660066;">renderCamera</span><span style="color: #009900;">&#40;</span>camera<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//keep calling function every 20 milliseconds.</span><br />
setInterval<span style="color: #009900;">&#40;</span>animateIt<span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="code explained" border="0" alt="code explained" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image35.png" width="420" height="420" /> </p>
<p> Anytime the mouse moved we would figure out how far the mouse is from the center of the object.&#160; Then we assign it to variables that will be used in a function that is called at set intervals.&#160; In that function we simply divide the mouse value by a speed variable and apply it to the axisRotation.&#160; You can adjust the sensitivity of the mouse by increasing or decreasing the speed value.&#160; You might be wondering why we’re applying the mouseX to the y value of axisRotation.&#160; This is because we want to control rotating on the y axis with our mouse moving left and right.&#160; Kind of like opening and closing a door.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="axis" border="0" alt="axis" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image36.png" width="420" height="420" /> </p>
<p>&#160;</p>
<p>Here is the code all together:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>3d engine<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; #item{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: relative;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; ul{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #69c;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-weight: bold;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size:2em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3DEngine.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Plane.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; //<span style="color: #404040;">&lt;![CDATA[</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">$(document).ready(function() {</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; var camera = new Camera3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; camera.init(0,0,0,300);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; var container = $(&quot;#item&quot;)</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; var item = new Object3D(container);</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; item.addChild(new Plane(100));</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; var scene = new Scene3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; scene.addToScene(item);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; var mouseX,mouseY = 0;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; var offsetX = $(&quot;#item&quot;).offset().left;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; var offsetY = $(&quot;#item&quot;).offset().top;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; var speed = 6000;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; $().mousemove(function(e){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; mouseX = e.clientX - offsetX - (container.width() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; mouseY = e.clientY - offsetY - (container.height() / 2);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; var animateIt = function(){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; if (mouseX != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.y += (mouseX) / speed</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; if (mouseY != undefined){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.x -= mouseY / speed;</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; scene.renderCamera(camera);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; };</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; setInterval(animateIt, 20);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; //]]&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>Next Step</h2>
<p>Now that the mouse Interaction is taken care of.&#160; The next shape I’m going to take a stab at is the ring.&#160; Stay tuned for more 3D shapes.</p>
<p>&#160;</p>
<div class="resources"> <a href="http://www.devirtuoso.com/Examples/3D-Engine/plane.zip" class="Download" target="_blank">Download</a>  <a href="http://www.devirtuoso.com/Examples/3D-Engine/plane.html"class="Example" target="_blank">Example</a></div>
<p>&#160;</p>
<h3>Related</h3>
<p> <a href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank">3D Engine</a><br />
  <a href="http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/" target="_blank"><img src="http://www.devirtuoso.com/wp-content/uploads/2009/09/3D-Engine.jpg" alt="" title="" width="100" height="100" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making a 3D Engine in jQuery</title>
		<link>http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/</link>
		<comments>http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 14:48:49 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1124</guid>
		<description><![CDATA[In the previous post &#8220;3D tag cloud&#8221; I received quite a few requests for different shapes besides the ring. The problem is how the tag cloud was created it doesn&#8217;t lend itself to different shapes very well. So this post will show how to create a 3D engine in jQuery / JavaScript for those more [...]]]></description>
			<content:encoded><![CDATA[<p>
	In the previous post &#8220;<a href="http://www.devirtuoso.com/2009/08/how-to-create-a-3d-tag-cloud-in-jquery/" target="_blank">3D tag cloud</a>&#8221; I received quite a few requests for different shapes besides the ring.<br />
	The problem is how the tag cloud was created it doesn&#8217;t lend itself to different shapes very well. So<br />
	this post will show how to create a 3D engine in jQuery / JavaScript for those more exciting shapes.
</p>
<p><span id="more-1124"></span></p>
<p>&#160;</p>
<h2>What We&#8217;re Building</h2>
<p>We&#8217;re going to create a 3D engine that will allow us to create shapes simply by creating an array of points. This engine will have a Camera, a Scene and an Object. It&#8217;ll work pretty well the same as in real life. The closer the camera is to the object the larger it gets. This won&#8217;t be a complete rendering engine, as this won&#8217;t render multiple objects at this point.</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/3D-Engine/example.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/3D-Engine/" target="_blank">Example</a></div>
<p>&#160;<a href="http://www.devirtuoso.com/Examples/3D-Engine/" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Cube" border="0" alt="cube 3d" src="http://www.devirtuoso.com/wp-content/uploads/2009/09/image_thumb1.png" width="431" height="449" /></a> </p>
<p>&#160;</p>
<h2>Display Object</h2>
<p>The Display Object is more or less a way to give each object a set of properties and methods. Say I wanted to create a cube, it would first have to inherit the DisplayObject3D class for it to work. It gives the object the tools it needs to get the job done. Kind of like a tool box for a handy man.</p>
<p>Here is the JavaScript Class:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> DisplayObject3D <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><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
DisplayObject3D.<span style="color: #660066;">prototype</span>._x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>._y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create 3d Points</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">make3DPoint</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> point <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> point<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create 2d Points</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">make2DPoint</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span> depth<span style="color: #339933;">,</span> scaleFactor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> point <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">depth</span> <span style="color: #339933;">=</span> depth<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">scaleFactor</span> <span style="color: #339933;">=</span> scaleFactor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> point<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Holds the container</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">container</span> <span style="color: #339933;">=</span> undefined<span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Holds an array of 3d points.</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">pointsArray</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">// Set the container and create place holders if </span><br />
<span style="color: #006600; font-style: italic;">// there is no &lt;ul&gt; in the container</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">containerId</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//if there isn't a ul than it creates a list of +'s</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>container<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;:has(ul)&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;b id=&quot;item'</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;+&lt;/b&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>If this seems a little foreign to you, you might want to check out the post <a title="Object Oriented Programming with JavaScript" href="http://www.devirtuoso.com/2009/09/object-oriented-programming-with-javascript/" target="_blank">Object Oriented Programming with JavaScript</a>.</p>
<h4>Make 3d/2d Points</h4>
<p>These functions basically create objects, one meant for 3d (x,y,z) and one meant for 2d(x,y,depth).&#160; These will come in handy when the scene is rendered.</p>
<h4>Initialization</h4>
<p>The init function assigns a variable to the container passed in.&#160; The container is where ever you want the 3d object to display.&#160; There is also a part of this function that checks to see if the container has an unordered list.&#160; If it doesn’t it just creates a bunch of +’s&#160; Really these lines aren’t necessary, I just put it in so I don’t always have to create a unordered list to see if my object is rendering.</p>
<p>&#160;</p>
<h2>Camera</h2>
<p>I’m guessing from the name you can probably figure out what this class does.&#160; It’s just like a real life camera.&#160; It basically creates a point of reference.</p>
<p>Here is the Camera Class:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Camera3D <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: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//The x,y,z of the camera</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Determines the zoom</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Figure out how large the object should be in</span><br />
<span style="color: #006600; font-style: italic;">//reference to the camera.</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">scaleRatio</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">focalLength</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Initialize the camera with values.</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #339933;">,</span>focalLength<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">=</span> focalLength<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>The focal length basically determines how large the object is going to look in reference to how close it is from the camera.&#160; Think of it like a zoom lens.&#160; You can zoom in, or zoom out.</p>
<p>The scaleRatio does the magic. It figures out how large the item should be in reference to the camera.</p>
<p>&#160;</p>
<h2>Object 3D</h2>
<p>This class isn’t overly important.&#160; I basically made this class so I can add more than one object in the future.&#160; Right now the engine can only deal with one object at a time. Object3D is a glorified array.&#160; Anytime you add an item to the array, it runs the init function on that item. </p>
<p>Here is the code:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// class creates an array of objects to</span><br />
<span style="color: #006600; font-style: italic;">// be rendered, and initializes them.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> Object3D <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Object3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">objects</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Add object to the list of objects.</span><br />
Object3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addChild</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>object3D<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">objects</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>object3D<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; object3D.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> object3D<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h2>Scene</h2>
<p>This is where all the complicated stuff happens.&#160; I won’t get into great detail with the mathematics.&#160; High school math was boring enough <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> &#160; I will give you a high overview of what the code does though, so at least you have an understanding of what it does.</p>
<p>Here is the Scene Class:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Scene3D <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: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">sceneItems</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Adds objects to the list of items to be rendered.</span><br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addToScene</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">sceneItems</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">//Converts a 3d point into a 2d point.</span><br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">Transform3DPointsTo2DPoints</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>points<span style="color: #339933;">,</span> axisRotations<span style="color: #339933;">,</span>camera<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> TransformedPointsArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> sx <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cx <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> sy <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cy <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> sz <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cz <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #339933;">,</span> xy<span style="color: #339933;">,</span>xz<span style="color: #339933;">,</span> yx<span style="color: #339933;">,</span>yz<span style="color: #339933;">,</span> zx<span style="color: #339933;">,</span>zy<span style="color: #339933;">,</span> scaleFactor<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> points.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">=</span> points<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">=</span> points<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; z <span style="color: #339933;">=</span> points<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">z</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// rotation around x</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xy <span style="color: #339933;">=</span> cx<span style="color: #339933;">*</span>y <span style="color: #339933;">-</span> sx<span style="color: #339933;">*</span>z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xz <span style="color: #339933;">=</span> sx<span style="color: #339933;">*</span>y <span style="color: #339933;">+</span> cx<span style="color: #339933;">*</span>z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// rotation around y</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; yz <span style="color: #339933;">=</span> cy<span style="color: #339933;">*</span>xz <span style="color: #339933;">-</span> sy<span style="color: #339933;">*</span>x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; yx <span style="color: #339933;">=</span> sy<span style="color: #339933;">*</span>xz <span style="color: #339933;">+</span> cy<span style="color: #339933;">*</span>x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// rotation around z</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; zx <span style="color: #339933;">=</span> cz<span style="color: #339933;">*</span>yx <span style="color: #339933;">-</span> sz<span style="color: #339933;">*</span>xy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; zy <span style="color: #339933;">=</span> sz<span style="color: #339933;">*</span>yx <span style="color: #339933;">+</span> cz<span style="color: #339933;">*</span>xy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; scaleFactor <span style="color: #339933;">=</span> camera.<span style="color: #660066;">focalLength</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>camera.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">+</span> yz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">=</span> zx<span style="color: #339933;">*</span>scaleFactor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">=</span> zy<span style="color: #339933;">*</span>scaleFactor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; z <span style="color: #339933;">=</span> yz<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> displayObject <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TransformedPointsArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> displayObject.<span style="color: #660066;">make2DPoint</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> <span style="color: #339933;">-</span>z<span style="color: #339933;">,</span> scaleFactor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> TransformedPointsArray<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">//Takes the converted 2d and applies the appropriate CSS.</span><br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">renderCamera</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>camera<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Loop through all objects in the scene.</span><br />
&nbsp; &nbsp; <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> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">sceneItems</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">sceneItems</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">objects</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//transform the points in the object to 2d points.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> screenPoints <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Transform3DPointsTo2DPoints</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">pointsArray</span><span style="color: #339933;">,</span> axisRotation<span style="color: #339933;">,</span> camera<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//does the container have a ul inside of it.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> hasList <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">containerId</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Cycle through each point in the object.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>k<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> obj.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> currItem <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//if the container has a list then select the lis</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hasList<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">containerId</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;li&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//otherwise select whatever is there.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">containerId</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//If there are items to render then...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currItem<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem._x <span style="color: #339933;">=</span> screenPoints<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem._y <span style="color: #339933;">=</span> screenPoints<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">scale</span> <span style="color: #339933;">=</span> screenPoints<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">scaleFactor</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Render the CSS.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">position</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">top</span> <span style="color: #339933;">=</span> currItem._y<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">left</span> <span style="color: #339933;">=</span> currItem._x<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">fontSize</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">*</span>currItem.<span style="color: #660066;">scale</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'%'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>currItem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>currItem.<span style="color: #660066;">scale</span><span style="color: #339933;">-</span>.5<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Center for rotation</span><br />
<span style="color: #003366; font-weight: bold;">var</span> axisRotation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<h4>Add To Scene</h4>
<p>First thing you’ll see is the addToScene function.&#160; This basically populates the array that is used to render the scene.&#160; If you object is in this array it will get rendered, if it isn’t….it missed the bus.</p>
<p>&#160;</p>
<h4>Transform 3D point to 2D</h4>
<p>Next is the Transform3DPointsTo2DPoints function.&#160; This is probably the most important part of the engine.&#160; What it does is it takes a 3D point in space (x,y,z) and through a little magic converts it into a 2D point that can be displayed on screen.</p>
<p>&#160;</p>
<h4>Render Camera</h4>
<p>The renderCamera function doesn’t do anything too complicated.&#160; It’s sole purpose is to display the items on screen.&#160; It does this by looping through the objects in the scene, and passes each one into the Transform3DPointsTo2DPoints function.&#160; The function will return a 2D point that can be plotted using CSS.&#160; You might have noticed I’m using JavaScript for the CSS and selecting of the DOM instead of jQuery.&#160; Initially I used jQuery but found the browser was crawling, so I went back to the old fashion way.</p>
<p>&#160;</p>
<h2>The Cube</h2>
<p>I’ve put the Cube class in a separate file so you can import objects as you need them instead of having to load ones you aren’t using.&#160; </p>
<p>The class isn’t overly complicated.&#160; It’s creating an array and placing all the points on the cube into that array.&#160; It uses the make3DPoint function from the DisplayObject3D class to create each point. </p>
<p>Here is the code:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Cube <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>size<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//if the size is not set then give a default</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>size <span style="color: #339933;">===</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; size <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Create a 3d point for every point on the cube.</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//make3dpoint is a function inherited from</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//DisplayObject3D</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Inherit DisplayObject3d methods and properties</span><br />
Cube.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>&#160;</p>
<h2>Using the 3D Engine</h2>
<p>There are a few steps that need to be done in order for this to work.&#160;&#160; First we’ll need some HTML. I’ll just create a div with an id and place a &lt;ul&gt; full of smiley faces.&#160; If you wanted you can leave the div blank and it will automatically create a bunch of +’s for you.</p>
<p>Here is the HTML:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- List of smiley faces --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3DEngine.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #808080; font-style: italic;">&lt;!-- </span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; Each 3d object is a seperate js so you only </span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; have to import what you need.</span><br />
<span style="color: #808080; font-style: italic;">--&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Cube.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>Next comes the jQuery. There are a couple of steps you need to do:</p>
<ol>
<li>Create a camera and initialize it. </li>
<li>Create an Object Holder (Object3D) </li>
<li>Create an Object and put it in the holder. </li>
<li>Create a Scene and put the holder in it. </li>
</ol>
<p>Here is the jQuery:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</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><br />
<br />
<span style="color: #006600; font-style: italic;">//Create a camera</span><br />
<span style="color: #003366; font-weight: bold;">var</span> camera <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Camera3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//initialize it.</span><br />
camera.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create an object holder.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object3D<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//add a new cube.</span><br />
<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">addChild</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Cube<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">//Create a scene</span><br />
<span style="color: #003366; font-weight: bold;">var</span> scene <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Scene3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Place the object Holder in the scene.</span><br />
scene.<span style="color: #660066;">addToScene</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Animates the cube.</span><br />
<span style="color: #003366; font-weight: bold;">var</span> animateIt <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><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//rotates on the y and x axis.</span><br />
&nbsp; &nbsp; axisRotation.<span style="color: #660066;">y</span> <span style="color: #339933;">+=</span> .01<br />
&nbsp; &nbsp; axisRotation.<span style="color: #660066;">x</span> <span style="color: #339933;">-=</span> .01<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Render the scene.</span><br />
&nbsp; &nbsp; scene.<span style="color: #660066;">renderCamera</span><span style="color: #009900;">&#40;</span>camera<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
setInterval<span style="color: #009900;">&#40;</span>animateIt<span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<p>I didn’t get a chance to make it interact with the mouse. You can do that just by adjusting the axisRotation x, y and z values when the mouse moves.&#160; Perhaps I’ll do this in my next post.</p>
<p>&#160;</p>
<h2>That’s All For Now</h2>
<p>Stay tuned for the next couple of posts.&#160; I plan to make a couple different shapes for this.&#160; If you feel frisky by all means try and create your own shapes.&#160; Just create an array with a bunch of 3D Points.&#160;&#160; </p>
<p>There are still a couple of kinks to work out, but for now here is all the code together.</p>
<p>3DEngine.js</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">/*<br />
* DisplayObject3D ----------------------------------------------<br />
*/</span><br />
<span style="color: #003366; font-weight: bold;">var</span> DisplayObject3D <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><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
DisplayObject3D.<span style="color: #660066;">prototype</span>._x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>._y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create 3d Points</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">make3DPoint</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> point <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> point<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">//Create 2d Points</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">make2DPoint</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span> depth<span style="color: #339933;">,</span> scaleFactor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> point <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">depth</span> <span style="color: #339933;">=</span> depth<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; point.<span style="color: #660066;">scaleFactor</span> <span style="color: #339933;">=</span> scaleFactor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> point<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">container</span> <span style="color: #339933;">=</span> undefined<span style="color: #339933;">;</span><br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">pointsArray</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
DisplayObject3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">containerId</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//if there isn't a ul than it creates a list of +'s</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>container<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;:has(ul)&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;b id=&quot;item'</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;+&lt;/b&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>&nbsp; <br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* DisplayObject3D End ----------------------------------------------<br />
*/</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* Camera3D ----------------------------------------------<br />
*/</span><br />
<span style="color: #003366; font-weight: bold;">var</span> Camera3D <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: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span><br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span><br />
<br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">scaleRatio</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">focalLength</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Camera3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #339933;">,</span>focalLength<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">=</span> focalLength<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* Camera3D End ----------------------------------------------<br />
*/</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* Object3D ----------------------------------------------<br />
*/</span><br />
<span style="color: #003366; font-weight: bold;">var</span> Object3D <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Object3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">objects</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
Object3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addChild</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>object3D<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">objects</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>object3D<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; object3D.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> object3D<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* Object3D End ----------------------------------------------<br />
*/</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* Scene3D ----------------------------------------------<br />
*/</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> Scene3D <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: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">sceneItems</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addToScene</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">sceneItems</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">Transform3DPointsTo2DPoints</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>points<span style="color: #339933;">,</span> axisRotations<span style="color: #339933;">,</span>camera<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> TransformedPointsArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> sx <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cx <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> sy <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cy <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> sz <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cz <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>axisRotations.<span style="color: #660066;">z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #339933;">,</span> xy<span style="color: #339933;">,</span>xz<span style="color: #339933;">,</span> yx<span style="color: #339933;">,</span>yz<span style="color: #339933;">,</span> zx<span style="color: #339933;">,</span>zy<span style="color: #339933;">,</span> scaleFactor<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> points.<span style="color: #660066;">length</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">=</span> points<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">=</span> points<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; z <span style="color: #339933;">=</span> points<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">z</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// rotation around x</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xy <span style="color: #339933;">=</span> cx<span style="color: #339933;">*</span>y <span style="color: #339933;">-</span> sx<span style="color: #339933;">*</span>z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xz <span style="color: #339933;">=</span> sx<span style="color: #339933;">*</span>y <span style="color: #339933;">+</span> cx<span style="color: #339933;">*</span>z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// rotation around y</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; yz <span style="color: #339933;">=</span> cy<span style="color: #339933;">*</span>xz <span style="color: #339933;">-</span> sy<span style="color: #339933;">*</span>x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; yx <span style="color: #339933;">=</span> sy<span style="color: #339933;">*</span>xz <span style="color: #339933;">+</span> cy<span style="color: #339933;">*</span>x<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// rotation around z</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; zx <span style="color: #339933;">=</span> cz<span style="color: #339933;">*</span>yx <span style="color: #339933;">-</span> sz<span style="color: #339933;">*</span>xy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; zy <span style="color: #339933;">=</span> sz<span style="color: #339933;">*</span>yx <span style="color: #339933;">+</span> cz<span style="color: #339933;">*</span>xy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; scaleFactor <span style="color: #339933;">=</span> camera.<span style="color: #660066;">focalLength</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>camera.<span style="color: #660066;">focalLength</span> <span style="color: #339933;">+</span> yz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">=</span> zx<span style="color: #339933;">*</span>scaleFactor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">=</span> zy<span style="color: #339933;">*</span>scaleFactor<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; z <span style="color: #339933;">=</span> yz<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> displayObject <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TransformedPointsArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> displayObject.<span style="color: #660066;">make2DPoint</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> <span style="color: #339933;">-</span>z<span style="color: #339933;">,</span> scaleFactor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> TransformedPointsArray<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Scene3D.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">renderCamera</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>camera<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <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> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">sceneItems</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">sceneItems</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">objects</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> screenPoints <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Transform3DPointsTo2DPoints</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">pointsArray</span><span style="color: #339933;">,</span> axisRotation<span style="color: #339933;">,</span> camera<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> hasList <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">containerId</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>k<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> obj.<span style="color: #660066;">pointsArray</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> currItem <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hasList<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">containerId</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;li&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">containerId</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currItem<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem._x <span style="color: #339933;">=</span> screenPoints<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem._y <span style="color: #339933;">=</span> screenPoints<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">scale</span> <span style="color: #339933;">=</span> screenPoints<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">scaleFactor</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">position</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">top</span> <span style="color: #339933;">=</span> currItem._y<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">left</span> <span style="color: #339933;">=</span> currItem._x<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currItem.<span style="color: #660066;">style</span>.<span style="color: #660066;">fontSize</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">*</span>currItem.<span style="color: #660066;">scale</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'%'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>currItem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>currItem.<span style="color: #660066;">scale</span><span style="color: #339933;">-</span>.5<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">/*<br />
* Scene3D End ----------------------------------------------<br />
*/</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">//Center for rotation</span><br />
<span style="color: #003366; font-weight: bold;">var</span> axisRotation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Cube.js</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Cube <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>size<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>size <span style="color: #339933;">===</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; size <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pointsArray</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,-</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">make3DPoint</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>size<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
Cube.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DisplayObject3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>index.html</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Untitled Page<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #item{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:100px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin:0 auto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:300px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: relative;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ul{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list-style-type: none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #111;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #69c;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, &quot;MS Trebuchet&quot;, sans-serif;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-weight: bold;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size:2em;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">style</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><span style="color: #ddbb00;">&amp;#x263A;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">li</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">ul</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3DEngine.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Cube.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; //<span style="color: #404040;">&lt;![CDATA[</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function() {</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var camera = new Camera3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camera.init(0,0,0,300);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var item = new Object3D($(&quot;#item&quot;));</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item.addChild(new Cube(100));</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var scene = new Scene3D();</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.addToScene(item);</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var animateIt = function(){</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.y += .01</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; axisRotation.x -= .01</span><br />
<br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scene.renderCamera(camera);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setInterval(animateIt, 20);</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span><br />
<span style="color: #404040;">&nbsp; &nbsp; &nbsp; &nbsp; //]]&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>&#160;</p>
<div class="resources"><a class="Download" href="http://www.devirtuoso.com/Examples/3D-Engine/example.zip" target="_blank">Download</a> <a class="Example" href="http://www.devirtuoso.com/Examples/3D-Engine/" target="_blank">Example</a></div>
<p>&#160;</p>
<h3>Related</h3>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td>
			<a href="http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/" target="_blank">3D Plane</a><br />
 <a href="http://www.devirtuoso.com/2009/09/3d-plane-for-jquery-3d-engine/" target="_blank"><img src="http://www.devirtuoso.com/wp-content/uploads/2009/09/3d-plane.jpg" alt="3d Plane" title="3d Plane" width="100" height="100" /></a>
		</td>
<td>
			 <a href="http://www.devirtuoso.com/2009/09/creating-a-wobbling-3d-carousel/" target="_blank">Wobbling Carousel</a><br />
 <a href="http://www.devirtuoso.com/2009/09/creating-a-wobbling-3d-carousel/" target="_blank"> <img src="http://www.devirtuoso.com/wp-content/uploads/2009/09/wobbling-carousel.jpg" width="100" height="100" alt="wobbling carousel" title="wobbling carousel" /></a></p>
</td>
<td>
 <a href="http://www.devirtuoso.com/2009/09/3d-sphere-using-jquery/" target="_blank">3D Sphere</a><br />
			 <a href="http://www.devirtuoso.com/2009/09/3d-sphere-using-jquery/" target="_blank"><img src="http://www.devirtuoso.com/wp-content/uploads/2009/09/3d-sphere.jpg" alt="3d sphere" width="100" height="100" title="3d sphere" /></a>
		</td>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/making-a-3d-engine-in-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JavaScript Experiment &#8211; Browser Ball</title>
		<link>http://www.devirtuoso.com/2009/09/javascript-experiment-browser-ball/</link>
		<comments>http://www.devirtuoso.com/2009/09/javascript-experiment-browser-ball/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 14:45:18 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[showcase]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1111</guid>
		<description><![CDATA[I killed about 20 minutes playing with this one.&#160; We’ve all seen physics experiments with balls in a browser window.&#160; This is the first one that I’ve seen that uses multiple windows. Try it out &#160; My hat goes off to Mark Mahoney for this one.&#160; It was done really well. Fantastic work. If you [...]]]></description>
			<content:encoded><![CDATA[<p>I killed about 20 minutes playing with this one.&#160; We’ve all seen physics experiments with balls in a browser window.&#160; This is the first one that I’ve seen that uses multiple windows.</p>
<p> <span id="more-1111"></span>
</p>
<h3></h3>
<h3><a href="http://experiments.instrum3nt.com/markmahoney/ball/" target="_blank">Try it out</a></h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:71679ff5-6a05-4c53-a540-6562dae857c5" class="wlWriterEditableSmartContent">
<div><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/3al8prbfK5o&amp;hl=en"></param><embed src="http://www.youtube.com/v/3al8prbfK5o&amp;hl=en" type="application/x-shockwave-flash" width="425" height="355"></embed></object></div>
</div>
<p>&#160;</p>
<p>My hat goes off to <a href="http://www.weareinstrument.com/#/team/mark-mahoney" target="_blank">Mark Mahoney</a> for this one.&#160; It was done really well.</p>
<p>Fantastic work.</p>
<p>If you know of any other experimental developments that are worth a look, don’t hesitate to contact us.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/09/javascript-experiment-browser-ball/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experimental JavaScript &#8211; Wavy Scrollbars</title>
		<link>http://www.devirtuoso.com/2009/08/experimental-javascript-wavy-scrollbars/</link>
		<comments>http://www.devirtuoso.com/2009/08/experimental-javascript-wavy-scrollbars/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 01:33:11 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Experimental]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.devirtuoso.com/?p=1024</guid>
		<description><![CDATA[This is by far the most creative use of scrollbars that I’ve seen.  Who would have thought to create an interactive wave with scrollbars.  Fantastic work. The experiment can be viewed here : http://the389.com/experiment/ It requires that you have safari 4 or google chrome.  In case you don’t have either one, here is a video [...]]]></description>
			<content:encoded><![CDATA[<p>This is by far the most creative use of scrollbars that I’ve seen.  Who would have thought to create an interactive wave with scrollbars.  Fantastic work.</p>
<p><span id="more-1024"></span></p>
<p>The experiment can be viewed here : <a href="http://the389.com/experiment/">http://the389.com/experiment/</a></p>
<p>It requires that you have safari 4 or google chrome.  In case you don’t have either one, here is a video of the experiment.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="307" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=3794595&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="307" src="http://vimeo.com/moogaloop.swf?clip_id=3794595&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a href="http://vimeo.com/3794595">Scrollbars Experiment</a></p>
<p>Much respect goes out to the author.  This is the kind of work that makes my day.  I’m just sad I didn’t think of it first <img src='http://www.devirtuoso.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.devirtuoso.com/2009/08/experimental-javascript-wavy-scrollbars/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.devirtuoso.com @ 2012-02-04 14:39:24 -->
