Posted: Sat May 03, 2008 11:54 am Post subject: need help on hot to get a line to point to the mouse
can anyone help me id be greatful thanks for all the help
if i were to use draw line command from point a to mouse location i would get a line from point a to the mouse but i want to do this without the line connecting to the mouse
it should look something like this and the lines will point to where your mouse is
good.jpg
Description:
Filesize:
7.04 KB
Viewed:
3448 Time(s)
Sponsor Sponsor
gitoxa
Posted: Sat May 03, 2008 5:42 pm Post subject: RE:need help on hot to get a line to point to the mouse
Use the pythagorean theorm, and ratios of the distances of the lines (the one the length of the line you want, and the length of the line from the point to the mouse.) Using that ratio, you can determine the side lengths.
josh_65665
Posted: Sat May 03, 2008 6:08 pm Post subject: RE:need help on hot to get a line to point to the mouse
how do i do that lol
Asherel
Posted: Sat May 03, 2008 6:51 pm Post subject: Re: need help on hot to get a line to point to the mouse
The Pythagorean Theorem is to find the side lengths of a right triangle. You have your three sides, A, B, C, where C is usually your Hypotenuse.
To find the length of the Hypotenuse, you need to solve for C. This meaning, that the square of C is equal to the sum of the squares of A and B.
The formula:
Or to solve for the length of C:
So, in Turing aspects, the formula will look like this. However, I will not give you the variable names, numbers, just the formula to use.
So, you will need to find the length of the line where it meets the mouse, and have it go before it. So if you know the distance of the start of the arrow to the distance of the mouse, you can then manipulate the line into going just before.
Hopefully this will be helpful.
Newguy
Posted: Sat May 03, 2008 7:02 pm Post subject: Re: need help on hot to get a line to point to the mouse
You guys are over thinking it. Simplify. In turing there is a function called "mousewhere". It is quite easy to do this.
Quote:
var mouse_x, mouse_y, button : int
loop
View.Update
setscreen ("offscreenonly") % Makes it stop flickering
cls % Clears the screen for the next frame - sort of
mousewhere (mouse_x, mouse_y, button) % finds where the mouse is in the windows and stores its position as mouse_x, mouse_y, and button
drawline (0, 0, mouse_x, mouse_y, black) % Draws a line from 0, 0 to mouse_x and mouse_y
end loop
It is also quite easy to make it draw to mouse only when the button is pressed by:
Quote:
var mouse_x, mouse_y, button : int
loop
View.Update
setscreen ("offscreenonly") % Makes it stop flickering
cls % Clears the screen for the next frame - sort of
mousewhere (mouse_x, mouse_y, button) % finds where the mouse is in the windows and stores its position as mouse_x, mouse_y, and button
if button = 1 then % Checks if button is pressed and then proceeds to drawline
drawline (0, 0, mouse_x, mouse_y, black) % Draws a line from 0, 0 to mouse_x and mouse_y
end if
end loop
Hope that solves your problem.
gitoxa
Posted: Sat May 03, 2008 7:12 pm Post subject: RE:need help on hot to get a line to point to the mouse
Quote:
You guys are over thinking it. Simplify. In turing there is a function called "mousewhere". It is quite easy to do this.
Please read over his question again, then tell us we're over thinking it.
You're doing the first part of the solution, the easy part. You also shouldn't write code for people. Tell them what commands and/or concepts may be of use to them, and let them do it.
Last thing About your code, you should take the setscreen out of the loop. There's no point in running it over and over again.
Asherel
Posted: Sat May 03, 2008 7:24 pm Post subject: RE:need help on hot to get a line to point to the mouse
I don't believe that he asked to draw it on his own, but have it automatically draw it towards the mouse, regardless of where he puts it.
Therefore he will need a line start point but have the line trace the mouse's x and y position but minus a few away to make sure it is not touching the mouse.
Newguy
Posted: Sat May 03, 2008 7:34 pm Post subject: Re: RE:need help on hot to get a line to point to the mouse
gitoxa @ Sat May 03, 2008 7:12 pm wrote:
Quote:
You guys are over thinking it. Simplify. In turing there is a function called "mousewhere". It is quite easy to do this.
Please read over his question again, then tell us we're over thinking it.
You're doing the first part of the solution, the easy part. You also shouldn't write code for people. Tell them what commands and/or concepts may be of use to them, and let them do it.
Last thing About your code, you should take the setscreen out of the loop. There's no point in running it over and over again.
Then I guess do what ahserel said. Put -10 to mouse_x and mouse_y or some other number. I didn't get what he meant.
Did I understand right this time?
Sponsor Sponsor
Asherel
Posted: Sat May 03, 2008 7:46 pm Post subject: Re: need help on hot to get a line to point to the mouse
So, if you were going to do, you would have to make it minus away from your original position of the mouse. Thus, manipulating the x2, and y2 positions of the mouse.
This will draw the line from (0,0) to 15 positions away, the gap won't look big on the screen.
Take a look at the code provided, and let us know if that is what you wanted.
gitoxa
Posted: Sat May 03, 2008 8:28 pm Post subject: Re: need help on hot to get a line to point to the mouse
Seriously, is english that hard to read?
He even gave a diagram of what he wanted. Don't give advice unless you know it works. And if you think it does, try it out.
code:
var x, y, b : int
loop
mousewhere (x, y, b)
Draw.FillOval (x, y, 15, 15, red)
Draw.Line (0, 0, x - 15, y - 15, black)
delay (5)
cls
end loop
zomg super awesome kawaii!
It works flawlessly
josh_65665
Posted: Sat May 03, 2008 8:35 pm Post subject: ?
these are not working the line needs to stay a certain lenth and has to point to mouse x,y please if someone knows how to do this post it il be greatful
gitoxa
Posted: Sat May 03, 2008 8:47 pm Post subject: Re: need help on hot to get a line to point to the mouse
My first post, along with Asherel's first explaining the pythagorean theorm are all the info you need.
9,000 hours in mspaint.
mathisfun.JPG
Description:
Filesize:
16.17 KB
Viewed:
139 Time(s)
josh_65665
Posted: Sat May 03, 2008 9:28 pm Post subject: ...
thats a nice visual aid thanks for making it but im afraid i dont understand it
cavetroll
Posted: Sun May 04, 2008 1:49 am Post subject: Re: need help on hot to get a line to point to the mouse
Can't you just use simple trig?
I mean you know it is a right angle triangle between the two points so it's simple SOH CAH TOA. You can use the SIN or COSINE ratios to calculate the angle.
Here is a quick example of how it can be done.