Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 07-23-2004, 06:25 AM JavaScript: distance
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Hey, can anyone please give me some help regarding the following matter:

I use the following code to display how far a users mouse has travelled:

dist = Math.abs(oldX - mio.mouse.x()) + Math.abs(oldY - mio.mouse.y());
dkm+=dist;
km.innerHTML = dkm +" pixels";
oldX = mio.mouse.x();
oldY = mio.mouse.y();

It works fine, however it dsplays the distance in pixels... is there any way I can convert the pixels into metres, centimatres or even inches. Please.

Thank you for any help.
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
 
Register now for full access!
Old 07-23-2004, 10:01 AM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
This should work.


inchesperpx = 1/72; // should be altered to whatever the correct value is
acc = 2; // number of decimal places in reading

dist = Math.abs(oldX - mio.mouse.x()) + Math.abs(oldY - mio.mouse.y());
dpx+=dist;
dinches = Math.round(dpx*inchesperpx*Math.pow(10,acc))/Math.pow(10,acc);
inches.innerHTML = dinches +" inches";
oldX = mio.mouse.x();
oldY = mio.mouse.y();


Rufo.

Last edited by Kyrnt; 07-23-2004 at 05:56 PM..
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-23-2004, 10:47 AM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
mmmm, having a little trouble getting that to work... think it could be to do with the km in my original code, I will try and change it... and what's the deciaml thing all about?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-23-2004, 10:51 AM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Still a few gremlins in the system... the code that calls that function goes as follows:

<script>

function reset() {
dkm=0;
km.innerHTML = dkm +" pixels";
}

</script>

Please can you tell me how I would have to change that accordingly to fit with the new code, thank you for excellent help so far by the way.
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-23-2004, 01:20 PM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
It should be changed to this:


<script>

function reset() {
dpx = 0;
dinches = 0;
inches.innerHTML = "0 inches";
}

</script>


The 'acc' thing is so your distance doesn't say something like "42.1982582572192481 inches". It rounds the measurement off to however many decimal places you want.

Last edited by Kyrnt; 07-23-2004 at 05:56 PM..
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-23-2004, 04:21 PM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Thanks, and also there's this onload function thing:

var oldX=0, oldY=0, dkm = 0;
oldX = mio.mouse.x();
oldY = mio.mouse.y();

What do I do to that? I tried changing the dkm to dinches but it didn't work...
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-25-2004, 11:16 AM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
var oldX=0, oldY=0, dpx = 0;
oldX = mio.mouse.x();
oldY = mio.mouse.y();

It's dpx that needs resetting to 0, not dinches.
__________________

Please login or register to view this content. Registration is FREE
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-26-2004, 06:50 AM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Wahoooooooo! It worked. Thank you so much Rufo! By the way, if you'd like to see what it's become you can find my creation on this page: http://www.surfinstan.com/downloads.htm it's called How Far Does Your Mouse Travel?

It's really quite interesting. Thanks again!
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-26-2004, 03:39 PM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
And also... if I wanted to create it counting cm instead, do I just have to change the numbers in the following code:

inchesperpx = 1/72;

I know everything else will still say inches, but does that matter? JavaScript doesn't recognise 'inches' as a measurment does it? Just some letters right?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-27-2004, 02:42 PM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
Just alter inchesperpx to something like 1/32, and change the script so it says "cm" wherever it previously said "inches".

Rufo.
__________________

Please login or register to view this content. Registration is FREE
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-27-2004, 03:15 PM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
That's what I thought, cheers dude! Did you see the finished thing?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-27-2004, 08:02 PM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
Yes, got it running in the background now.

You may want to take a look at Mouse Odomter - similar kind of program.
__________________

Please login or register to view this content. Registration is FREE
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-28-2004, 04:22 AM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
That's kinda cool. do you think mine has the cpability of developing into something like that?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 07-29-2004, 06:42 AM
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Oh and another little thing for you Rufo (or anyone else who looks at this thread) how would I change it so it counted key strokes?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Reply     « Reply to JavaScript: distance
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36433 seconds with 12 queries