Jump to content

# X and Y Coordinates

## Recommended Posts

Okay, this is for my autoit script, but is hardly relevant to AutoIt

Im trying to move an image at a diagnal to the position 30, 50 on the screen

How would I do this..

like

For \$i = 1 to 100

ControlMove(\$MyImage, \$ImagePos[0] + 1, \$ImagePos[1] + 1)

Next

This will not work, because it will only step 100 times, so if it is something like moving the image to 500, 700 then it will only do a 7th of the movement... How would I go about making it move the full length... Sorry if this is kinda difficult for you to understand, but im trying my best to explain....

here is a diagram:

Im trying to move X to Y. How would i make X Move in that exact path until it hits Y?

I think someone partially answered this question a while ago, but it was'nt really what i was looking for..

Edited by CHRIS95219

#### Share this post

##### Share on other sites

Do
ControlMove(\$MyImage, \$ImagePos[0] + 1, \$ImagePos[1] + 1)
\$ImagePos[0] += 1
\$ImagePos[1] += 1
Until (\$ImagePos[0] = \$yourX) and (\$ImagePos[1] = \$yourY)

Of course, this only moves in a 45 degree angle (as of now).

Edited by greenmachine

#### Share this post

##### Share on other sites

This is where algebra and geometry help you...

Figure out the slope by using the start point and the end point and add appropriately... Post the start point and we'll get you all fixed up.

EDIT: On second thought, maybe I have no idea what you're asking for... :-/

Edited by Oxin8

#### Share this post

##### Share on other sites

use @desktopwidth and @desktophieght

get your position, subtract to get the difference

the idea is

\$ImagePos[0] + \$i .... not \$ImagePos[0] + 1

Question

is this a control or a Window ??

better read more on ControlMove() you syntax is not right

ControlMove ( "title", "text", controlID, x, y [, width [, height]] )

8)

Edited by Valuater

#### Share this post

##### Share on other sites

yeah, i no... i was doin it real quick to hurry and ask my question...

thanks GM. and everyone else...

Edited by CHRIS95219

#### Share this post

##### Share on other sites

Its a control.... a Pic inside my gui.

#### Share this post

##### Share on other sites

use @desktopwidth and @desktophieght

get your position, subtract to get the difference

the idea is

\$ImagePos[0] + \$i .... not \$ImagePos[0] + 1

Question

is this a control or a Window ??

better read more on ControlMove() you syntax is not right

ControlMove ( "title", "text", controlID, x, y [, width [, height]] )

8)

but if u do image[0] + \$i

tput the image at the top of the window, then move... i want it to move from its current position. The code GM Gave me worked perfect.

btw, sorry for the triple posts, lol.

Oh, also, is their anyway to slow down that movement without using the Sleep() function?

Edited by CHRIS95219

#### Share this post

##### Share on other sites

By the way, about my code... you might want to change the "and" in the do/until loop to an "or", unless your pic starts out so X and Y are proportionate to the final location...

In other words, if you're trying to move it to 500, 700, you need to have the pic start at say (200, 400) - it would then move 300 pixels at a 45 degree angle to meet 500, 700. If you want to use a different angle, sin and cos are going to be your friends.

@Larry - gah, so slow.

Edited by greenmachine

#### Share this post

##### Share on other sites

okay, im confused on the math... could someone please imlement it into this code...

Func SpriteMove(\$Sprite, \$EndX, \$EndY)

Do
\$ImagePos = ControlGetPos("", "", \$Sprite)
ControlMove("", "", \$Sprite, \$ImagePos[0] + \$xadd, \$ImagePos[1] + \$yadd)
\$ImagePos[0] += 1
\$ImagePos[1] += 1
Until (\$ImagePos[0] = \$EndX) and (\$ImagePos[1] = \$EndY)
Return 0
EndFunc
Edited by CHRIS95219

#### Share this post

##### Share on other sites

I used mousemove as my example, I figure you can change it to suit your needs.

SpriteMove(0, 500, 500)
Func SpriteMove(\$Sprite, \$EndX, \$EndY)
\$CurrentPos = MouseGetPos ()
\$xadd = (\$EndX - \$CurrentPos[0])/100; 100 movements
\$yadd = (\$EndY - \$CurrentPos[1])/100; 100 movements
Do
;\$ImagePos = ControlGetPos("", "", \$Sprite)
;ControlMove("", "", \$Sprite, \$ImagePos[0] + \$xadd, \$ImagePos[1] + \$yadd)
MouseMove (\$CurrentPos[0] + \$xadd, \$CurrentPos[1] + \$xadd)
\$CurrentPos[0] += \$xadd
\$CurrentPos[1] += \$yadd
TrayTip ("pos", \$CurrentPos[0] & @CRLF & \$CurrentPos[1], 1)
Until (Int (\$CurrentPos[0]) = \$EndX) And (Int (\$CurrentPos[1]) = \$EndY)
Return 0
EndFunc

It's going to look a lot like Larry's in terms of math, but that's because all correct math answers look alike.

There are also more efficient methods, but I was just continuing from my initial post.

Edited by greenmachine

#### Share this post

##### Share on other sites

I used mousemove as my example, I figure you can change it to suit your needs.

SpriteMove(0, 500, 500)
Func SpriteMove(\$Sprite, \$EndX, \$EndY)
\$CurrentPos = MouseGetPos ()
\$xadd = (\$EndX - \$CurrentPos[0])/100; 100 movements
\$yadd = (\$EndY - \$CurrentPos[1])/100; 100 movements
Do
;\$ImagePos = ControlGetPos("", "", \$Sprite)
;ControlMove("", "", \$Sprite, \$ImagePos[0] + \$xadd, \$ImagePos[1] + \$yadd)
MouseMove (\$CurrentPos[0] + \$xadd, \$CurrentPos[1] + \$xadd)
\$CurrentPos[0] += \$xadd
\$CurrentPos[1] += \$yadd
TrayTip ("pos", \$CurrentPos[0] & @CRLF & \$CurrentPos[1], 1)
Until (Int (\$CurrentPos[0]) = \$EndX) And (Int (\$CurrentPos[1]) = \$EndY)
Return 0
EndFunc

It's going to look a lot like Larry's in terms of math, but that's because all correct math answers look alike.

There are also more efficient methods, but I was just continuing from my initial post.

It does'nt stop at 500, 500. it kept going.... whent passed 1000.....

This is weird, for some numbers it works, but for others, it does'nt.

Thanks alot though!

Edited by CHRIS95219

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

×

• Wiki

• Back

• Git

## Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.