Jump to content


Photo

the variable between two points


  • Please log in to reply
2 replies to this topic

#1 Colton530

Colton530

    GMC Member

  • GMC Member
  • 415 posts

Posted 03 March 2012 - 08:44 AM

ok so basically I been at this for 2 hours and I'm stumped.


I have 2 variables on the x axis' of 32 and 48 (so 32 is 0% and 48 is 100%)

If I have my mouse is between the two x axis' mouse_x will of course be a number between the two variable's x axis'.

how can I get the percentage between the 2 x axis' judging by where mouse_x is?

Edited by Colton530, 04 March 2012 - 12:11 AM.

  • 0

#2 rude guss

rude guss

    GMC Member

  • GMC Member
  • 235 posts

Posted 03 March 2012 - 09:27 AM

var1 = 32;
var2 = 48;

percentage = 0;

if (mouse_x>=var1 && mouse_x<=var2)
{
    precentage = (mouse_x-var1)/(var2-var1); //this is a number between 0.0 - 1.0
}
Code only works if var1 < var2. Could make it work for any combination but im too lazy.

Edited by rude guss, 03 March 2012 - 09:28 AM.

  • 0

#3 Colton530

Colton530

    GMC Member

  • GMC Member
  • 415 posts

Posted 04 March 2012 - 12:06 AM

Thank you so much, it worked. Lol, there goes hours for nothing. :P
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users