AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with math.
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Thu Jul 03, 2008 12:13 pm    Post subject: Reply with quote

it doesnt center, it centers the fourth point which is bottom right of where should be correct center position
----
nvm got it to work by changing to

Code:
MouseClick, Left, X*Step + MouseX + 50, Y*Step + MouseY + 50


thanks again
Back to top
View user's profile Send private message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Thu Jul 03, 2008 12:59 pm    Post subject: Reply with quote

ok, a few steps forward... Mad
how can it skip clicking if the point is on vertical line of center position?
i touched a bit and changed to this

Code:

F1::
MouseGetPos, MouseX, MouseY
Step := 50 ; the distance between one point and the next
X := -1, Y := -1
Loop
{
   mark := Mod(A_Index,2) ? "X" : "Y"
   sign := Mod(A_Index//2,2)*2-1
   Loop % Ceil(A_Index/2)
   {
 %mark% += sign
 if MouseX := X*Step + MouseX + 50
 break
 else if MouseY := Y*Step + MouseY + 50
 break
 else
 MouseClick, Left, X*Step + MouseX + 50, Y*Step + MouseY + 50, 1, 0

   }
   GetKeyState, state, F1, P
   if state = U
   break
   else
   continue
}
return

esc::reload


whats the problem here? it should skip the ones on vertical line.. hmm..
Back to top
View user's profile Send private message
argneo



Joined: 14 Sep 2007
Posts: 136

PostPosted: Thu Jul 03, 2008 1:38 pm    Post subject: Reply with quote

Code:
Esc::ExitApp

F1::
{
rdir:=2
udir:=3
ldir:=3
ddir:=2
MouseGetPos, x, y
x:=x-50
y:=y-50
Click %x% %y%
loop
  {
     loop %ddir%
       {
       y:=y+50
       Click %x% %y%
       }
    ddir:=ddir+2
    loop %rdir%
      {
      x:=x+50
      Click %x% %y%
      }
    rdir:=rdir+2
    loop %udir%
      {
      y:=y-50
      Click %x% %y%
      }
    udir:=udir+2
    loop %ldir%
      {
      x:=x-50
      Click %x% %y%
      }
    ldir:=ldir+2
  }
}return


With this you have access to each side...
just add a conditional before the "Click" and that should do the trick.
_________________
WoW
Back to top
View user's profile Send private message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Thu Jul 03, 2008 1:45 pm    Post subject: Reply with quote

any idea to skip dots vertical to center position?
Back to top
View user's profile Send private message
argneo



Joined: 14 Sep 2007
Posts: 136

PostPosted: Thu Jul 03, 2008 1:47 pm    Post subject: Reply with quote

Code:
(x=0)?continue:Click %x% %y%


something like that...
_________________
WoW
Back to top
View user's profile Send private message
argneo



Joined: 14 Sep 2007
Posts: 136

PostPosted: Thu Jul 03, 2008 2:03 pm    Post subject: Reply with quote

Code:
SetBatchLines, -1
Esc::ExitApp

F1::
{
rdir:=2
udir:=3
ldir:=3
ddir:=2
MouseGetPos, x, y
xfactor:=x
x:=x-50
y:=y-50
if (x!=xfactor)
   Click %x% %y%
loop
  {
     loop %ddir%
      {
      y:=y+50
      if (x!=xfactor)
         Click %x% %y%
      }
    ddir:=ddir+2
    loop %rdir%
      {
      x:=x+50
      if (x!=xfactor)
         Click %x% %y%
      }
    rdir:=rdir+2
    loop %udir%
      {
      y:=y-50
      if (x!=xfactor)
         Click %x% %y%
      }
    udir:=udir+2
    loop %ldir%
      {
      x:=x-50
      if (x!=xfactor)
         Click %x% %y%
      }
    ldir:=ldir+2
  }
}return

_________________
WoW
Back to top
View user's profile Send private message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Thu Jul 03, 2008 2:53 pm    Post subject: Reply with quote

ok i also added skipping for dots verticaly to center in y coordinate

now my goal is almost there..
i want it to hold lbutton down at the current position, then mousemove to an inner point, offset by 50,50 from the current position then release there.
so it is going to drag range of 50,50 toward center position from current position, each time when it gets to new position.


below doesnt work

Code:
if X > centerX, Y > centerY
MouseClickDrag, left, X, Y, -50, -50 , 0, R

else if X > centerX, Y < centerY
MouseClickDrag, left, X, Y, -50, +50 , 0, R

else if X < centerX, Y > centerY
MouseClickDrag, left, X, Y, +50, -50 , 0, R

else if X < centerX, Y < centerY
MouseClickDrag, left, X, Y, +50, +50 , 0, R
Back to top
View user's profile Send private message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Fri Jul 04, 2008 5:43 am    Post subject: Reply with quote

hmm.. still cant get it to work :S
Back to top
View user's profile Send private message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Sat Jul 05, 2008 12:04 pm    Post subject: Reply with quote

ok finally got it to work, thanks to everyone who has supported.

Code:
Esc::
reload
return

$F1::
MouseGetPos, CenterX, CenterY
rdir:=2
udir:=3
ldir:=3
ddir:=2
MouseGetPos, x, y
xfactor:=x
yfactor:=y
x:=x-60
y:=y-60
MouseClickDrag, left,-200, -200, 200, 200, 0, R
MouseClick, right,centerx,centery,1,0
MouseClickDrag, left,-200, 0, 200, 200, 0, R
MouseClick, right,centerx,centery,1,0
MouseClickDrag, left, 0, 0, 200, 200, 0, R
MouseClick, right,centerx,centery,1,0
MouseClickDrag, left, 0, -200, 200, 200, 0, R
MouseClick, right,centerx,centery,1,0
MouseMove, X, Y, 0
MouseClickDrag, left, 0, 0, 100, 100, 0, R
MouseClick, right,centerx,centery,1,0
loop
{
     
   loop %ddir%
   {
      y:=y+60
      if (x!=xfactor && y!=yfactor)
      GoSub, Drag

      GetKeyState, state, F1, P
      if state = U
      return
         else if (x > 900 || x < 100 || y > 600 || y < 100)
         return
         else continue
         } ;;dir
ddir:=ddir+2




   loop %rdir%
   {
      x:=x+60
      if (x!=xfactor && y!=yfactor)
      GoSub, Drag

      GetKeyState, state, F1, P
      if state = U
      return
         else if (x > 900 || x < 100 || y > 600 || y < 100)
         return
         else continue
      }
rdir:=rdir+2


   loop %udir%
   {
      y:=y-60
      if (x!=xfactor && y!=yfactor)
      GoSub, Drag

      GetKeyState, state, F1, P
      if state = U
      return
         else if (x > 900 || x < 100 || y > 600 || y < 100)
         return
         else continue
      }
udir:=udir+2


   loop %ldir%
   {

      x:=x-60
      if (x!=xfactor && y!=yfactor)
      GoSub, Drag

      GetKeyState, state, F1, P
      if state = U
      return
         else if (x > 900 || x < 100 || y > 600 || y < 100)
         return
         else continue
         }
ldir:=ldir+2


}return

Drag:
if (x>centerx && y>centery)
{
MouseMove, X, Y, 0
MouseClickDrag, left, 0, 0, -130, -100, 0, R
MouseClick, right,centerx,centery,1,0
}
else if (x>centerx && y<centery)
{
MouseMove, X, Y, 0
MouseClickDrag, left, 0, 0, -130, 100, 0, R
MouseClick, right,centerx,centery,1,0
}
else if (x<centerx && y>centery)
{
MouseMove, X, Y, 0
MouseClickDrag, left, 0, 0, 130, -100, 0, R
MouseClick, right,centerx,centery,1,0
}
else if (x<centerx && y<centery)
{
MouseMove, X, Y, 0
MouseClickDrag, left, 0, 0, 130, 100, 0, R
MouseClick, right,centerx,centery,1,0
}
return
Back to top
View user's profile Send private message
Wouther



Joined: 01 May 2007
Posts: 79
Location: The Netherlands

PostPosted: Sun Jul 06, 2008 1:48 pm    Post subject: Reply with quote

Though many have already provided solutions, I wanted to contribute something too. It was fun to do. The result is a function that uses math to calculate the coordinates of a point on the square spiral (couldn't think of a better name Razz) and returns them. Because it does not add values to previous coordinates, it can calculate every point without having to go through numerous iterations of a loop. (of course it does need a loop to draw a full spiral) Also, you can specify the starting direction, the size of the gap between lines and the direction of the rotation. Cool

Below is the function with an example. Open a new window in paint and watch it draw! Wink (press Escape to exit)
Code:
SetBatchLines, -1

WinWaitActive, Untitled
Sleep, 1000
WinGetActiveStats, t, w, h, x, y
MouseMove, w/2, h/2, 0
Send, {LButton down}
Loop
{
   r := SquareSpiral(A_Index, 50, 2, -1)
   StringSplit, r, r, `,
   MouseMove, w/2 + r1, h/2 + r2, 0
   Sleep, 100
}


Return


Escape::
Send, {LButton up}
ExitApp
Return

;SquareSpiral
;   Information:
;   Description   Returns coordinates of points on a square spiral.
;   Author        Wouther
;
;   Parameters:
;   n   The number of the point. (obligatory)
;   s   Distance between lines. (default is 1 px)
;   d   Starting direction. Right is 1, down is 2, left is 3 and up is 4. (default is right)
;   r   Direction of rotation. Counterclockwise is -1 and Clockwise = 1. (default is counterclockwise)
;
;   Returns:
;   x,y   Comma-seperated coordinates of the 'n'-th point.
SquareSpiral(n, s = 1, d = 1, r = -1)
{
   f := Mod(n, 4)

   x := s*Ceil(n/4)
   y := s*Ceil(n/4)

   x *= (f = 1 || f = 2) ? -1 : 1
   y *= (f = 2 || f = 3) ? -1 : 1

   y -= (f = 1) ? s : 0

   m := (d = 3 || d = 4) ? -1*r : r
   a := (d = 1 || d = 3) ? "y" : "x"
   %a% += (f = 1) ? m*s

   Return x . "," . y
}
Furthermore, because it's a function returning the coordinates, the part of calculating and the actual script are seperated.
_________________
Printing css/html-formatted text
Back to top
View user's profile Send private message
GodlyMario



Joined: 02 Jul 2008
Posts: 39

PostPosted: Sun Jul 06, 2008 2:56 pm    Post subject: Reply with quote

cool, mine works a bit slow in full screen window, was wondering its because of the long code. ill try editing yours and see if that would work better. thanks for it Smile
Back to top
View user's profile Send private message
Wouther



Joined: 01 May 2007
Posts: 79
Location: The Netherlands

PostPosted: Sun Jul 06, 2008 5:31 pm    Post subject: Reply with quote

You could try removing the 'Sleep, 100' in the loop. Razz I placed it there because when the square spiral got very big (almost my entire screen) and if you set the gap very small, The Gimp (probably also Paint, I don't know) couldn't handle the speed and sometimes skipped one point, resulting in diagonal lines through the spiral. Wink
_________________
Printing css/html-formatted text
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group