Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Some help with math involved with mouse in box
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: Tue Apr 06, 2010 9:52 pm   Post subject: Some help with math involved with mouse in box

Ok, so I was playing around with math, trying to find a way to see if the mouse is in the screen width and height, instead of useing mX> 0 and mX < maxx and mY > 0 and mY < maxy, so I came up with this first part, and what it does is return 1 if the mouse x and y is >0. What I am having trouble with is making the inverse to this so that I can get 1 if mouse x and y < then there max. Also it would be great if anyone posted another way they do this. Any help? Smile

Turing:


var x, y, b : int
loop
    Mouse.Where (x, y, b)
    put "The mouse is in the box: ", ((succ (x) - sqrt (x * x)) * (succ (y) - sqrt (y * y)) = 1)
    loop
        exit when hasch
    end loop
    Input.Flush
end loop



Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Tue Apr 06, 2010 10:17 pm   Post subject: Re: Some help with math involved with mouse in box

I'm not sure there's actually a way to do that (at least, not using succ(x))... It works for below and left of the window since the number returned by succ(x) is of the opposite sign to sqrt(x^2). But when you're above the window, both numbers are positive, meaning that it will always return 1...

Also:
Turing:

sqrt(x * x)


may I introduce you to abs, otherwise known as the absolute value function?
copthesaint




PostPosted: Tue Apr 06, 2010 11:24 pm   Post subject: Re: Some help with math involved with mouse in box

There is a way, just went back to it again, and finished it.

Turing:
var x, y, b : int
loop
    Mouse.Where (x, y, b)
    put "The mouse is in the box: ", ((succ (x) - sqrt (x * x)) * (succ (y) - sqrt (y * y)) * (succ (maxx - x) - sqrt ((maxx - x) * (maxx - x))) * (succ (maxy - y) - sqrt ((maxy - y) * (maxy - y)))
        = (-1 * Window.GetActive))
    loop
        exit when hasch
    end loop
    Input.Flush
end loop


Well that was fun, lol. Now to find another way of doing this!
Edit: also I know abs, but I like the way I do it, because its better for visually looking at the code for me, but off course I would change that to abs later when figured everything out.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: