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

Username:   Password: 
 RegisterRegister   
 need help on hot to get a line to point to the mouse
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
josh_65665




PostPosted: 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:  2909 Time(s)

good.jpg


Sponsor
Sponsor
Sponsor
sponsor
gitoxa




PostPosted: 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




PostPosted: 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




PostPosted: 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:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Or to solve for the length of C:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

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.

Turing:

c = sqrt( a**2 + b**2)


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




PostPosted: 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. Very Happy
gitoxa




PostPosted: 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 Razz About your code, you should take the setscreen out of the loop. There's no point in running it over and over again.
Asherel




PostPosted: 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




PostPosted: 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 Razz 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. Smile

Did I understand right this time? Razz
Sponsor
Sponsor
Sponsor
sponsor
Asherel




PostPosted: 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.

Turing:

var mouse_x, mouse_y : int := 100

Draw.FillOval (mouse_x, mouse_y, 15, 15, red)

Draw.Line (0, 0, mouse_x - 15, mouse_y - 15, black)


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




PostPosted: 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




PostPosted: 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




PostPosted: 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:  132 Time(s)

mathisfun.JPG


josh_65665




PostPosted: 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




PostPosted: 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.

Turing:

setscreen("offscreenonly")
const LENGTH := 125
var mouse_x, mouse_y, btn, point_x, point_y : int
var angle : real
point_x := 0
point_y := 0
loop
Mouse.Where(mouse_x,mouse_y,btn)
angle := arccosd(abs(mouse_x-point_x)/ Math.Distance(mouse_x,mouse_y,point_x,point_y))
drawline(point_x,point_y,point_x+round(cosd(angle)*LENGTH), point_y+round(sind(angle)*LENGTH), 7)
View.Update
cls
end loop


If you need clarification of how this actually works I will be happy to explain the Trig behind it.
josh_65665




PostPosted: Sun May 04, 2008 10:45 am   Post subject: sure

sure id be grateful for an explanation on that it works great
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 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: