<?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>amrosama</title>
	<atom:link href="http://amrosama.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://amrosama.com</link>
	<description>The unholy methods of  javascript</description>
	<lastBuildDate>Sat, 17 Mar 2012 20:34:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Lyrics Dog</title>
		<link>http://amrosama.com/2012/02/10/lyrics-dog/</link>
		<comments>http://amrosama.com/2012/02/10/lyrics-dog/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 18:15:10 +0000</pubDate>
		<dc:creator>amrosama</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[android market]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lyrics]]></category>
		<category><![CDATA[lyricsdog]]></category>

		<guid isPermaLink="false">http://amrosama.com/?p=59</guid>
		<description><![CDATA[I&#8217;ve finally finished working on Lyrics Dog Android Application and published it on android market. It basically reads the android media store records for listing your artists, albums and songs so you can select a song and view its&#8217; lyrics that&#8217;s stored on the mp3 file tags. I know there are tons of application that searches [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_76" class="wp-caption alignleft" style="width: 160px"><a href="https://play.google.com/store/apps/details?id=com.lyricsdog"><img class=" wp-image-76 " title="ld_logo" src="http://amrosama.com/wp-content/uploads/2012/03/ld_logo.jpg" alt="" width="150" height="150" /></a><p class="wp-caption-text">Lyrics Dog</p></div>
<p>I&#8217;ve finally finished working on <a title="Lyrics Dog" href="https://play.google.com/store/apps/details?id=com.lyricsdog" target="_blank">Lyrics Dog</a> Android Application and published it on android market.<br />
It basically reads the android media store records for listing your artists, albums and songs so you can select a song and view its&#8217; lyrics that&#8217;s stored on the mp3 file tags.</p>
<p><span id="more-59"></span></p>
<div style="clear: both;"></div>
<div style="clear: both;"></div>

<a href='http://amrosama.com/2012/02/10/lyrics-dog/2-albums/' title='2 albums'><img width="150" height="150" src="http://amrosama.com/wp-content/uploads/2012/03/2-albums-150x150.png" class="attachment-thumbnail" alt="2 albums" title="2 albums" /></a>
<a href='http://amrosama.com/2012/02/10/lyrics-dog/1-main-screen/' title='1 main screen'><img width="150" height="150" src="http://amrosama.com/wp-content/uploads/2012/03/1-main-screen-150x150.png" class="attachment-thumbnail" alt="1 main screen" title="1 main screen" /></a>
<a href='http://amrosama.com/2012/02/10/lyrics-dog/4-custom-search-2/' title='4 custom search'><img width="150" height="150" src="http://amrosama.com/wp-content/uploads/2012/03/4-custom-search1-150x150.png" class="attachment-thumbnail" alt="4 custom search" title="4 custom search" /></a>
<a href='http://amrosama.com/2012/02/10/lyrics-dog/3-lyrics/' title='3 lyrics'><img width="150" height="150" src="http://amrosama.com/wp-content/uploads/2012/03/3-lyrics-150x150.png" class="attachment-thumbnail" alt="3 lyrics" title="3 lyrics" /></a>

<div style="clear: both;"></div>
<p>I know there are tons of application that searches for lyrics and so on, but what makes this one different is that it saves the lyrics into the mp3 file tags so you can access these lyrics from your favorite mp3 player.</p>
<p>Update: Lyrics Dog has reached  265 total installs! and a total of 1,064 lyrics were fetched in 2 months! <img src='http://amrosama.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Update: I&#8217;m currently working on adding some new cool features like sharing lyrics and the web site for lyrics dog to show top songs, trends and other stuff like that.</p>
<h3> <a href="https://play.google.com/store/apps/details?id=com.lyricsdog" target="_blank">Download Lyrics Dog</a></h3>
<p>Please if you have any suggestion or a complain place it in the comments below that would make me very happy <img src='http://amrosama.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://amrosama.com/2012/02/10/lyrics-dog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beedy Eyes &#8211; Eyes following mouse movement</title>
		<link>http://amrosama.com/2011/08/22/beedy-eyes-eyes-following-mouse-movement/</link>
		<comments>http://amrosama.com/2011/08/22/beedy-eyes-eyes-following-mouse-movement/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 21:20:17 +0000</pubDate>
		<dc:creator>amrosama</dc:creator>
				<category><![CDATA[fun]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[border-radius]]></category>
		<category><![CDATA[eyes]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mousemove]]></category>
		<category><![CDATA[slope]]></category>

		<guid isPermaLink="false">http://amrosama.com/demo/?p=11</guid>
		<description><![CDATA[overview In this little tutorial I&#8217;m going to show you how to create a small jQuery code where 2 eyes follow mouse movement. Its basically a fetches the mouse position on screen and calculates the css top and left attributes that are appropriate for the eyeball by keeping it inside the eye container, theres a [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_32" class="wp-caption alignleft" style="width: 154px"><a href="http://amrosama.com/demo/wp-content/uploads/2011/08/beedy_eyes_preview.png"><img src="http://amrosama.com/demo/wp-content/uploads/2011/08/beedy_eyes_preview.png" alt="beedy eyes preview" title="beedy_eyes_preview" width="144" height="140" class="size-full wp-image-32" /></a><p class="wp-caption-text">beedy eyes</p></div><strong>overview</strong><br />
In this little tutorial I&#8217;m going to show you how to create a small jQuery code where 2 eyes follow mouse movement. Its basically a fetches the mouse position on screen and calculates the css top and left attributes that are appropriate for the eyeball by keeping it inside the eye container, theres a little math involved so its gonna be fun <img src='http://amrosama.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .<br />
<strong><a href="http://amrosama.com/demos/beedyeyes/" title="demo" target="_blank">Demo</a></strong><br />
<span id="more-11"></span></p>
<p><strong>download</strong></p>
<p>you can download it or fork it  from github <strong><a title="Download" href="https://github.com/amrosama2020/Beedy-Eyes" target="_blank">here</a> , </strong>or get it directly from <a href="http://amrosama.com/demo/wp-content/uploads/2011/08/amrosama2020-Beedy-Eyes-3708abd.zip" target="_blank">here</a>.</p>
<p><strong>HTML and CSS</strong></p>
<p>nothing weird or complex in the html, just two DIVs for the eyeballs and one DIV for the face with 2 eyes containers inside</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 /></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;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'eyeBall'</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'eyeBall_1'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'eyeBall'</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'eyeBall_2'</span> &gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'face'</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'eyeContainer'</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'1'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'eyeContainer'</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'2'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p>In css I used border radius to make the divs look rounded like a circle for both the eye container and face (outer container) and used absolute position for the eyeballs</p>
<div class="codecolorer-container css 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 /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.face</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.eyeContainer</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">25px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">25px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.eyeBall</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>How to</strong></p>
<p><img class="alignright size-full wp-image-42" title="explaination" src="http://amrosama.com/demo/wp-content/uploads/2011/08/explaination.png" alt="" width="227" height="144" /></p>
<p>The whole idea is about getting the correct left and top css attributes for the eye ball position, to do this we need to:</p>
<ol>
<li>get current mouse position and the position of the eye container center</li>
<li>calculate the distance between these two points</li>
<li>find the distance between the mouse position and the eye container radius, this is necessary to make the eye ball <em>inside</em> the eye container without going outside the border.</li>
<li>after finding the distance we can easily calculate the top and left of the point with simple math.</li>
</ol>
<div><strong>1.</strong> To get the mouse position we need to capture the mouse movement on document first using this simple piece of code</div>
<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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<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 />
&nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span>document<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; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> mousePosition <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'x'</span> <span style="color: #339933;">:</span> e.<span style="color: #660066;">pageX</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'y'</span> <span style="color: #339933;">:</span> e.<span style="color: #660066;">pageY</span><br />
&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: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</div>
<div>using jQuery offset we can find each eye container position on the document and add half of it&#8217;s width to get the exact center of the eye container and added 1 pixel for the mouse cursor width so it looks nice and centered.</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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.eyeContainer&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> i2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> eyeContainerPosition <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</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: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> eyePosition <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'x'</span> <span style="color: #339933;">:</span> eyeContainerPosition.<span style="color: #660066;">left</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'y'</span> <span style="color: #339933;">:</span> eyeContainerPosition.<span style="color: #660066;">top</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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: #339933;">+</span><span style="color: #CC0000;">1</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><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><strong>2. </strong>now we got the two points we can just get the distance between them using this simple formula <a href="http://amrosama.com/demo/wp-content/uploads/2011/08/dist.gif"><img class="alignnone size-full wp-image-43" title="dist" src="http://amrosama.com/demo/wp-content/uploads/2011/08/dist.gif" alt="" width="108" height="29" /></a> in javascript this means:</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 /></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;">function</span> getDistance<span style="color: #009900;">&#40;</span>loc1<span style="color: #339933;">,</span> loc2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>loc1.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> loc2.<span style="color: #660066;">x</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; &nbsp; &nbsp; &nbsp; &nbsp; Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>loc1.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> loc2.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>3. </strong>to find the distance between the mouse position and the first point on the eye container radius we minus eye container half diameter from the distance between the eye center and mouse.</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 /></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> toCenterdistance <span style="color: #339933;">=</span> getDistance<span style="color: #009900;">&#40;</span>eyePosition<span style="color: #339933;">,</span> mousePosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> targetDistance <span style="color: #339933;">=</span> toCenterdistance <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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></div></td></tr></tbody></table></div>
<p><strong>4. </strong>Till now we got the distance between the mouse position and the nearest point on the eye container radius, after googling around I found out that using the slope of the line we can get any point on the line given the distance in trigonometry  we can use this:</p>
<div class="codecolorer-container text 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">x = r cos (theta)<br />
y = r sin (theta)</div></td></tr></tbody></table></div>
<p>where <strong>r </strong>is the distance we already got, and <strong>theta</strong> is the angle; which can be found by getting the arctangent of the slope(y/x). in javascript this means:</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 /></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> slope <span style="color: #339933;">=</span> getSlope<span style="color: #009900;">&#40;</span>eyePosition<span style="color: #339933;">,</span> mousePosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">atan</span><span style="color: #009900;">&#40;</span>slope<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> targetDistance<span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">atan</span><span style="color: #009900;">&#40;</span>slope<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> targetDistance<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>this gets good results but still needs a little modification to work. the x and y values are relevant to the eye center to get the correct position we need to do the following</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 /></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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>eyePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">&gt;</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; x <span style="color: #339933;">+=</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
<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>eyePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">&lt;</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; x <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>x <span style="color: #339933;">+</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>now this will work fine and eyeball position will be correct and <strong>always</strong> on eye container radius, but what if the mouse cursor was inside the eye container itself?? this image explains it</p>
<p><a href="http://amrosama.com/demo/wp-content/uploads/2011/08/bad-position.png"><img class="alignnone size-full wp-image-44" title="bad position" src="http://amrosama.com/demo/wp-content/uploads/2011/08/bad-position.png" alt="" width="102" height="102" /></a></p>
<p>as you can see the eye ball should be on the tip of the mouse cursor but instead its on the eye container radius as its supposed to be, to fix this all we need to do is to check if the distance between the cursor and the eye container is less or equal to the eye container half diameter. so the final code for getting the left and top css attributes is</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 /></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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>toCenterdistance <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Math.<span style="color: #660066;">cos</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">atan</span><span style="color: #009900;">&#40;</span>slope<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> targetDistance<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>eyePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">&gt;</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">+=</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #339933;">;</span><br />
&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>eyePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">&lt;</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>x <span style="color: #339933;">+</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">atan</span><span style="color: #009900;">&#40;</span>slope<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> targetDistance<span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>eyePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">&gt;</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">+=</span> mousePosition.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&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>eyePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">&lt;</span> mousePosition.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>y <span style="color: #339933;">+</span> mousePosition.<span style="color: #660066;">y</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; x <span style="color: #339933;">-=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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: #339933;">;</span><br />
&nbsp; &nbsp; y <span style="color: #339933;">-=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; x <span style="color: #339933;">=</span> mousePosition.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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; y <span style="color: #339933;">=</span> mousePosition.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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 />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> element<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eyeBall_&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
element.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">'left'</span> <span style="color: #339933;">:</span> x <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">'top'</span> <span style="color: #339933;">:</span> y <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">,</span><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>&nbsp;</p>
<p>Well, thats all :{D . let me know if there&#8217;s an easier way or something to add in the comments below</p>
]]></content:encoded>
			<wfw:commentRss>http://amrosama.com/2011/08/22/beedy-eyes-eyes-following-mouse-movement/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

