Box Spiral posible? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
masheen
Posts: 295
Joined: 06 Dec 2016, 14:10

Box Spiral posible?

23 May 2017, 21:47

Hi, Anybody know how to do this spiral?
Image
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Box Spiral posible?

24 May 2017, 07:53

You need to elaborate. Are you wanting the mouse cursor to move using that path, or just have it displayed as an image?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

24 May 2017, 10:05

Try this:

Code: Select all

#NoEnv
#SingleInstance, Force

    pToken := Gdip_Startup()
    OnExit, Exit
    Gui, -Caption +AlwaysOnTop +hwndhGui +E0x80000
    Gui, Show
    DrawSpiral(12, 3, 30)

Return

Esc:: ExitApp


;-------------------------------------------------------------------------------
DrawSpiral(NumLegs, LineWidth, LineLength) { ; using Gdip
;-------------------------------------------------------------------------------
    global
    Width := 1920, Height := 1080
    hBM := CreateDIBSection(Width, Height)
    hDC := CreateCompatibleDC()
    oBM := SelectObject(hDC, hBM)
    Graphics := Gdip_GraphicsFromHDC(hDC)
    pPen := Gdip_CreatePen(0xFF000000, LineWidth)
    x2 := A_ScreenWidth  // 2
    y2 := A_ScreenHeight // 2

    Loop, % NumLegs {
        dx := !Mod(A_Index, 2) - 2* !Mod(A_Index, 4)        ; cycle 0, +1, 0, -1
        dy :=  Mod(A_Index, 2) - 2* (Mod(A_Index, 4) = 1)   ; cycle -1, 0, +1, 0
        x1 := x2, y1 := y2
        x2 := x1 + LineLength * dx * A_Index
        y2 := y2 + LineLength * dy * A_Index
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, Width, Height)
}



;-------------------------------------------------------------------------------
Exit:
;-------------------------------------------------------------------------------
    Gdip_DeleteBrush(pBrush)
    Gdip_DeletePen(pPen)
    SelectObject(hDC, oBM)
    DeleteObject(hBM)
    DeleteDC(hDC)
    Gdip_DeleteGraphics(Graphics)
    Gdip_Shutdown(pToken)

ExitApp
I hope that helps.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Box Spiral posible?

24 May 2017, 10:17

wolf_II wrote:Try this:

Code: Select all

#NoEnv
#SingleInstance, Force

    pToken := Gdip_Startup()  ; <<======================= getting an error ~ "non existing function" ...
    OnExit, Exit
    Gui, -Caption +AlwaysOnTop +hwndhGui +E0x80000
    Gui, Show
    DrawSpiral(12, 3, 30)

Return

Esc:: ExitApp


;-------------------------------------------------------------------------------
DrawSpiral(NumLegs, LineWidth, LineLength) { ; using Gdip
;-------------------------------------------------------------------------------
    global
    Width := 1920, Height := 1080
    hBM := CreateDIBSection(Width, Height)
    hDC := CreateCompatibleDC()
    oBM := SelectObject(hDC, hBM)
    Graphics := Gdip_GraphicsFromHDC(hDC)
    pPen := Gdip_CreatePen(0xFF000000, LineWidth)
    x2 := A_ScreenWidth  // 2
    y2 := A_ScreenHeight // 2

    Loop, % NumLegs {
        dx := !Mod(A_Index, 2) - 2* !Mod(A_Index, 4)        ; cycle 0, +1, 0, -1
        dy :=  Mod(A_Index, 2) - 2* (Mod(A_Index, 4) = 1)   ; cycle -1, 0, +1, 0
        x1 := x2, y1 := y2
        x2 := x1 + LineLength * dx * A_Index
        y2 := y2 + LineLength * dy * A_Index
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, Width, Height)
}



;-------------------------------------------------------------------------------
Exit:
;-------------------------------------------------------------------------------
    Gdip_DeleteBrush(pBrush)
    Gdip_DeletePen(pPen)
    SelectObject(hDC, oBM)
    DeleteObject(hBM)
    DeleteDC(hDC)
    Gdip_DeleteGraphics(Graphics)
    Gdip_Shutdown(pToken)

ExitApp
I hope that helps.
I'm getting this error ~ "non existing function" Gdip_Startup()
So, what are the system/scripts requirements? AHK 1.x.x ?? An UDF???
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

24 May 2017, 10:47

@BoBo: I have the file Gdip_all.ahk inside my C:\Users\<name>\Documents\AutoHotkey\Lib folder.
Sorry, I forgot to mention that.

This is the file I use: (I don't want to look for the download link right now)

Code: Select all

; removed
Edit: code removed, see my second reply to BoBo further down.
Last edited by wolf_II on 25 May 2017, 03:19, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Box Spiral posible?

24 May 2017, 13:32

wolf_II wrote:Try this:
Very nice one wolf_II :bravo:
:terms: You are missing some pixels in the corners though, try this,

Code: Select all

;-------------------------------------------------------------------------------
DrawSpiral(NumLegs, LineWidth, LineLength) { ; using Gdip
;-------------------------------------------------------------------------------
    global
    Width := 1920, Height := 1080
    hBM := CreateDIBSection(Width, Height)
    hDC := CreateCompatibleDC()
    oBM := SelectObject(hDC, hBM)
    Graphics := Gdip_GraphicsFromHDC(hDC)
    pPen := Gdip_CreatePen(0xFF000000, LineWidth)
    x2 := A_ScreenWidth  // 2
    y2 := A_ScreenHeight // 2
    Loop, % NumLegs {
        
		dx := !Mod(A_Index, 2) - 2* !Mod(A_Index, 4)        ; cycle 0, +1, 0, -1
        dy :=  Mod(A_Index, 2) - 2* (Mod(A_Index, 4) = 1)   ; cycle -1, 0, +1, 0
        x1 := x2 - dx*LineWidth/2, y1 := y2 - dy*LineWidth/2
        x2 := x1 + LineLength * dx * A_Index + dx
        y2 := y2 + LineLength * dy * A_Index + dy
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, Width, Height)
}
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

24 May 2017, 14:16

@Helgef: Thank you, that is brilliant!

I have cleaned up the code inside the function to only contain "functional" code, and reduced the number of global variables it uses.
I have also added an aesthetic enhancement, the first leg is now 1.5x the length as before.

Code: Select all

#NoEnv
#SingleInstance, Force

    pToken := Gdip_Startup()
    hBM := CreateDIBSection(A_ScreenWidth, A_ScreenWidth)
    hDC := CreateCompatibleDC()
    oBM := SelectObject(hDC, hBM)
    Graphics := Gdip_GraphicsFromHDC(hDC)
    OnExit, Exit

    Gui, -Caption +AlwaysOnTop +hwndhGui +E0x80000
    Gui, Show
    DrawSpiral(12, 3, 30)

Return

Esc:: ExitApp



;-------------------------------------------------------------------------------
DrawSpiral(NumLegs, LineWidth, LineLength) { ; using Gdip
;-------------------------------------------------------------------------------
    global hGui, hDC, Graphics

    pPen := Gdip_CreatePen(0xFF000000, LineWidth)
    x2 := A_ScreenWidth // 2
    y2 := A_ScreenHeight // 2
    Gdip_DrawLine(Graphics, pPen, x2, y2+LineLength/2, x2, y2)

    Loop, % NumLegs {
		dx := !Mod(A_Index, 2) - 2* !Mod(A_Index, 4)        ; cycle 0, +1, 0, -1
        dy :=  Mod(A_Index, 2) - 2* (Mod(A_Index, 4) = 1)   ; cycle -1, 0, +1, 0
        x1 := x2 - dx*LineWidth/2, y1 := y2 - dy*LineWidth/2
        x2 := x1 + LineLength * dx * A_Index + dx
        y2 := y2 + LineLength * dy * A_Index + dy
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, A_ScreenWidth, A_ScreenWidth)
}



;-------------------------------------------------------------------------------
Exit:
;-------------------------------------------------------------------------------
    Gdip_DeletePen(pPen)
    SelectObject(hDC, oBM)
    DeleteObject(hBM)
    DeleteDC(hDC)
    Gdip_DeleteGraphics(Graphics)
    Gdip_Shutdown(pToken)

ExitApp

Alternative for cycling repeatedly through the values 0, +1, 0, -1 which I prefer for its readability. The Mod()'s from before are awful.

Code: Select all

    ...
    HalfPi := 2 * ATan(1)
    Loop, % NumLegs {
        dx := -Cos(A_Index * HalfPi)           ; cycle 0, +1, 0, -1
        dy := -Sin(A_Index * HalfPi)           ; cycle -1, 0, +1, 0
        ...
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Box Spiral posible?

24 May 2017, 16:17

That's an improvement :thumbup:
There is a slight problem for LineWidth:=1, here is a quick-fix, also, another alternative for the cycling,

Code: Select all

;-------------------------------------------------------------------------------
DrawSpiral(NumLegs, LineWidth, LineLength) { ; using Gdip
;-------------------------------------------------------------------------------
    global hGui, hDC, Graphics

    pPen := Gdip_CreatePen(0xFF000000, LineWidth)
    x2 := A_ScreenWidth // 2
    y2 := A_ScreenHeight // 2
    Gdip_DrawLine(Graphics, pPen, x2, y2+LineLength/2, x2, y2)
	dxy:= LineWidth==1 ; Special case.
    Loop, % NumLegs {
		dx := [ 0, 1, 0,-1][i:=mod(A_Index-1,4)+1]
        dy := [-1, 0, 1, 0][i]
        x1 := x2 - dx*(LineWidth/2 - dxy), y1 := y2 - dy*(LineWidth/2 - dxy)
        x2 := x1 + LineLength * dx * A_Index + dx*(1-dxy)
        y2 := y2 + LineLength * dy * A_Index + dy*(1-dxy)
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, A_ScreenWidth, A_ScreenWidth)
}
I like the cos/sin cycling, nifty!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

24 May 2017, 16:47

@Helgef: Very good!

One more thing concerning pPen: As Gdip_CreatePen is called inside the function, maybe pPen should also be global in order to be deleted on exit?

Code: Select all

    global hGui, hDC, Graphics, pPen
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Box Spiral posible?

24 May 2017, 16:53

Maybe just delete it inside the function, when done with it?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

24 May 2017, 17:19

Yes, that makes even more sense when a script wants to call DrawSpiral more than once.
Example with more parameters (cx,cy = x,y coords of the center; ARGB = pen colour):

Code: Select all

#NoEnv
#SingleInstance, Force

    pToken := Gdip_Startup()
    hBM := CreateDIBSection(A_ScreenWidth, A_ScreenWidth)
    hDC := CreateCompatibleDC()
    oBM := SelectObject(hDC, hBM)
    Graphics := Gdip_GraphicsFromHDC(hDC)
    OnExit, Exit

    Gui, -Caption +AlwaysOnTop +hwndhGui +E0x80000
    Gui, Show
    DrawBoxSpiral(800, 300, 12, 1, 30, 0xFF0000FF)
    DrawBoxSpiral(400, 400, 20, 5, 10, 0xFFFF0000)

Return

Esc:: ExitApp



;-------------------------------------------------------------------------------
DrawBoxSpiral(cx, cy, NumLegs, LineWidth, LineLength, ARGB) { ; using Gdip
;-------------------------------------------------------------------------------
    global hGui, hDC, Graphics

    x2 := cx, y2 := cy ; support x,y coordinates of the center
    pPen := Gdip_CreatePen(ARGB, LineWidth)
    Gdip_DrawLine(Graphics, pPen, x2, y2+LineLength/2, x2, y2)
	dxy := LineWidth==1 ; Special case.

    Loop, % NumLegs {
		dx := [ 0, 1, 0,-1][i:=mod(A_Index-1,4)+1]
        dy := [-1, 0, 1, 0][i]
        x1 := x2 - dx*(LineWidth/2 - dxy), y1 := y2 - dy*(LineWidth/2 - dxy)
        x2 := x1 + LineLength * dx * A_Index + dx*(1-dxy)
        y2 := y2 + LineLength * dy * A_Index + dy*(1-dxy)
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, A_ScreenWidth, A_ScreenWidth)
    Gdip_DeletePen(pPen)
}



;-------------------------------------------------------------------------------
Exit:
;-------------------------------------------------------------------------------
    SelectObject(hDC, oBM)
    DeleteObject(hBM)
    DeleteDC(hDC)
    Gdip_DeleteGraphics(Graphics)
    Gdip_Shutdown(pToken)

ExitApp
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Box Spiral posible?

24 May 2017, 17:35

:thumbup:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

25 May 2017, 03:14

BoBo wrote:I'm getting this error ~ "non existing function" Gdip_Startup()
So, what are the system/scripts requirements? AHK 1.x.x ?? An UDF???
My earlier reply was lazy and incomplete. Please allow me try to improve:

You can find the original thread here: https://autohotkey.com/board/topic/2944 ... 45-by-tic/
The link to Gdip_All.ahk is here: https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk (taken from the original thread above)
I have a copy of this file inside the folder C:\Users\<name>\Documents\AutoHotkey\Lib like I said, but I also have a second copy of it there called Gdip.ahk.
The second copy (without _All in the name) is the crucial part of what makes the script work without any #Include lines.
If you want, you can copy the file Gdip_All.ahk anywhere you want, call it anything you like and add an appropriate #Include-line in the script.

I hope that clears things up a bit more.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Box Spiral posible?

25 May 2017, 04:35

I noticed a bug: The line UpdateLayeredWindow(hGui, hDC, 0, 0, A_ScreenWidth, A_ScreenWidth) contains A_ScreenWidth twice.
I have also added some comments:

Code: Select all

; https://autohotkey.com/boards/viewtopic.php?p=149932#p149932

#NoEnv
#SingleInstance, Force

    pToken := Gdip_Startup()
    hBM := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)
    hDC := CreateCompatibleDC()
    oBM := SelectObject(hDC, hBM)
    Graphics := Gdip_GraphicsFromHDC(hDC)
    OnExit, Exit

    Gui, -Caption +AlwaysOnTop +hwndhGui +E0x80000
    Gui, Show

    DrawBoxSpiral(1200, 400, 20, 5, 10, 0xFFFF0000)
    DrawBoxSpiral( 800, 300, 12, 3, 20, 0xFF00FF00)
    DrawBoxSpiral( 400, 500, 16, 1, 30, 0xFF0000FF)

Return

Esc:: ExitApp



;-------------------------------------------------------------------------------
DrawBoxSpiral(cx, cy, NumLegs, LineWidth, LineLength, ARGB) { ; using Gdip
;-------------------------------------------------------------------------------
    ; cx, cy:       x,y coordinates of the center
    ; NumLegs:      number of legs to draw
    ; LineWidth:    width of the lines in pixel
    ; LineLength:   length increment between consecutive legs
    ; ARGB:         pen colour (alpha, Red, Green, Blue)
    ;---------------------------------------------------------------------------
    global hGui, hDC, Graphics

    x2 := cx, y2 := cy
    pPen := Gdip_CreatePen(ARGB, LineWidth)
    Gdip_DrawLine(Graphics, pPen, x2, y2 + LineLength/2, x2, y2)
	dxy := (LineWidth == 1) ; special case

    Loop, % NumLegs {
		dx := [ 0, 1, 0,-1][i := Mod(A_Index - 1, 4) + 1]
        dy := [-1, 0, 1, 0][i]
        x1 := x2 - dx * (LineWidth/2 - dxy)
        y1 := y2 - dy * (LineWidth/2 - dxy)
        x2 := x1 + LineLength * dx * A_Index + dx * (1 - dxy)
        y2 := y2 + LineLength * dy * A_Index + dy * (1 - dxy)
        Gdip_DrawLine(Graphics, pPen, x1, y1, x2, y2)
    }
    UpdateLayeredWindow(hGui, hDC, 0, 0, A_ScreenWidth, A_ScreenHeight)
    Gdip_DeletePen(pPen)
}



;-------------------------------------------------------------------------------
Exit: ; clean up
;-------------------------------------------------------------------------------
    SelectObject(hDC, oBM)
    DeleteObject(hBM)
    DeleteDC(hDC)
    Gdip_DeleteGraphics(Graphics)
    Gdip_Shutdown(pToken)

ExitApp
Edit: :facepalm: :oops: ROFL, I managed to miss the fact that the bug was in there twice. Thanks Helgef :thumbup:
Last edited by wolf_II on 25 May 2017, 05:01, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Box Spiral posible?

25 May 2017, 04:40

hBM := CreateDIBSection(A_ScreenWidth, A_ScreenWidth) ?
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Box Spiral posible?  Topic is solved

25 May 2017, 05:39

Image

Using points ( I prefer when drawing lines ) and path ( gives many additional possibilities for the same amount of work ! )

I included all functions so even without gdip lib it should work.There are a lot of path functions I collected for those interested in them ( thanks Learning One ! )

Code: Select all

; Many thanks to Tic for gdip library
; https://autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic
;  for 64bit windows use gdip_all.ahk  
;  https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk

SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1
onexit bye

If !pToken := Gdip_Startup()
  {
    MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
  }
Gui, 1:  -Caption +E0x80000 +LastFound +OwnDialogs +Owner +hwndhwnd +alwaysontop
Gui, 1: Show, NA

w:=h:=200

hbm := CreateDIBSection(w,h)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
pGraphics := Gdip_GraphicsFromHDC(hdc)

Gdip_SetSmoothingMode(pGraphics,4)
Gdip_SetInterpolationMode(pGraphics,7)
Gdip_GraphicsClear(pGraphics,0x40000000)

gosub get_points

pPen:=Gdip_CreatePen(0xffff8000,4)

pPath:=Gdip_CreatePath_(0)
Gdip_AddPathCurve(pPath, Points)
Gdip_DrawPath(pGraphics, pPen, pPath)

Gdip_DeletePen(pPen)
Gdip_DeletePath(Path)

UpdateLayeredWindow(hwnd, hdc,(a_screenwidth-w)//2,(a_screenheight-h)//2,w,h)
OnMessage(0x201,"WM_LBUTTONDOWN")
return


get_points:
  l:=7 , changex:=0 , x:=100 ,y:=100 ,s:=0
  points .= 100 "," 100 "| "
  Loop 20
    {
      s++
      sign:= regexmatch(s,"3|4")?-1 : 1
      s:=s>4 ? 1 : s

      t:=!t
      If t
          x:=x+l*A_Index*sign
      Else
          y:=y+l*A_Index*sign
      points .= x "," y "|"
    }
return

WM_LBUTTONDOWN(wParam,lParam,msg,hwnd){

    x := lParam & 0xFFFF
    y := lParam >> 16

    ;tooltip x=%x% y=%y% mousebutton
    PostMessage, 0xA1, 2
  }


esc::
bye:

  SelectObject(hdc, obm)
  DeleteObject(hbm)
  DeleteDC(hdc)
  Gdip_DeleteGraphics(pGraphics)
  Gdip_Shutdown(pToken)
  ExitApp


  Gdip_SetLineJoin(pPen, linejoin=2) ;LineJoinMiter = 0,LineJoinBevel = 1,LineJoinRound = 2,LineJoinMiterClipped = 3
  {
    return DllCall("gdiplus\GdipSetPenLineJoin", "Uint", pPen, "uInt", linejoin)
  }


Gdip_AddPathCurve(pPath, Points) {
    StringSplit, Points, Points, |
    VarSetCapacity(PointF, 8*Points0)
    Loop, %Points0%
      {
        StringSplit, Coord, Points%A_Index%, `,
        NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
      }
    return DllCall("gdiplus\GdipAddPathCurve", "uint", pPath, "uint", &PointF, "int", Points0)
  }

Gdip_CreatePath_(BrushMode=0)
  {
    DllCall("gdiplus\GdipCreatePath", "int", BrushMode, "uint*", pPath)
    return pPath
  }


;#####################################################################################
; GraphicsPath functions added by Learning one
;#####################################################################################

; Function              Gdip_AddPathBeziers
; Description           Adds a sequence of connected Bézier splines to the current figure of this path.
;
; pPath                 Pointer to the GraphicsPath
; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
;
; return                status enumeration. 0 = success

; Notes                 The first spline is constructed from the first point through the fourth point in the array and uses the second and third points as control points. Each subsequent spline in the sequence needs exactly three more points: the ending point of the previous spline is used as the starting point, the next two points in the sequence are control points, and the third point is the ending point.

Gdip_AddPathBeziers(pPath, Points) {
    StringSplit, Points, Points, |
    VarSetCapacity(PointF, 8*Points0)
    Loop, %Points0%
      {
        StringSplit, Coord, Points%A_Index%, `,
        NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
      }
    return DllCall("gdiplus\GdipAddPathBeziers", "uint", pPath, "uint", &PointF, "int", Points0)
  }

Gdip_AddPathBezier(pPath, x1, y1, x2, y2, x3, y3, x4, y4) {	; Adds a Bézier spline to the current figure of this path
    return DllCall("gdiplus\GdipAddPathBezier", "uint", pPath
            , "float", x1, "float", y1, "float", x2, "float", y2
            , "float", x3, "float", y3, "float", x4, "float", y4)
  }

; Function              Gdip_AddPathLines
; Description           Adds a sequence of connected lines to the current figure of this path.
;
; pPath                 Pointer to the GraphicsPath
; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
;
; return                status enumeration. 0 = success

Gdip_AddPathLines(pPath, Points) {
    StringSplit, Points, Points, |
    VarSetCapacity(PointF, 8*Points0)
    Loop, %Points0%
      {
        StringSplit, Coord, Points%A_Index%, `,
        NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
      }
    return DllCall("gdiplus\GdipAddPathLine2", "uint", pPath, "uint", &PointF, "int", Points0)
  }

Gdip_AddPathLine(pPath, x1, y1, x2, y2) {
    return DllCall("gdiplus\GdipAddPathLine", "uint", pPath
            , "float", x1, "float", y1, "float", x2, "float", y2)
  }

Gdip_AddPathArc(pPath, x, y, w, h, StartAngle, SweepAngle) {
    return DllCall("gdiplus\GdipAddPathArc", "uint", pPath, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  }

Gdip_AddPathPie(pPath, x, y, w, h, StartAngle, SweepAngle) {
    return DllCall("gdiplus\GdipAddPathPie", "uint", pPath, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  }

Gdip_StartPathFigure(pPath) {	; Starts a new figure without closing the current figure. Subsequent points added to this path are added to the new figure.
    return DllCall("gdiplus\GdipStartPathFigure", "uint", pPath)
  }

Gdip_ClosePathFigure(pPath) {	; Closes the current figure of this path.
    return DllCall("gdiplus\GdipClosePathFigure", "uint", pPath)
  }

; Function              Gdip_DrawPath
; Description           draws a sequence of lines and curves defined by a GraphicsPath object
;
; pGraphics             Pointer to the Graphics of a bitmap
; pPen                  Pointer to a pen
; pPath                 Pointer to a Path
;
; return                status enumeration. 0 = success

Gdip_DrawPath(pGraphics, pPen, pPath) {
    return DllCall("gdiplus\GdipDrawPath", "uint", pGraphics, "uint", pPen, "uint", pPath)
  }

Gdip_WidenPath(pPath, pPen, Matrix=0, Flatness=1) {	; Replaces this path with curves that enclose the area that is filled when this path is drawn by a specified pen. This method also flattens the path.
    return DllCall("gdiplus\GdipWidenPath", "uint", pPath, "uint", pPen, "uint", Matrix, "float", Flatness)
  }

Gdip_ClonePath(pPath) {
    DllCall("gdiplus\GdipClonePath", "uint", pPath, "uint*", pPathClone)
    return pPathClone
  }


Gdip_Startup()
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("LoadLibrary", "str", "gdiplus")
	VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
	DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
	return pToken
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	hdc2 := hdc ? hdc : GetDC()
	VarSetCapacity(bi, 40, 0)
	
	NumPut(w, bi, 4, "uint")
	, NumPut(h, bi, 8, "uint")
	, NumPut(40, bi, 0, "uint")
	, NumPut(1, bi, 12, "ushort")
	, NumPut(0, bi, 16, "uInt")
	, NumPut(bpp, bi, 14, "ushort")
	
	hbm := DllCall("CreateDIBSection"
					, Ptr, hdc2
					, Ptr, &bi
					, "uint", 0
					, A_PtrSize ? "UPtr*" : "uint*", ppvBits
					, Ptr, 0
					, "uint", 0, Ptr)

	if !hdc
		ReleaseDC(hdc2)
	return hbm
}
GetDC(hwnd=0)
{
	return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
}
ReleaseDC(hdc, hwnd=0)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
}
CreateCompatibleDC(hdc=0)
{
   return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
SelectObject(hdc, hgdiobj)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
}
Gdip_GraphicsFromHDC(hdc)
{
    DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
    return pGraphics
}
Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
{
   return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
}
Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
{
   return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
}
Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
{
    return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
}
Gdip_CreatePen(ARGB, w)
{
   DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
   return pPen
}
Gdip_DeletePen(pPen)
{
   return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
}
Gdip_DeletePath(Path)
{
	return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
}
UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if ((x != "") && (y != ""))
		VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")

	if (w = "") ||(h = "")
		WinGetPos,,, w, h, ahk_id %hwnd%
   
	return DllCall("UpdateLayeredWindow"
					, Ptr, hwnd
					, Ptr, 0
					, Ptr, ((x = "") && (y = "")) ? 0 : &pt
					, "int64*", w|h<<32
					, Ptr, hdc
					, "int64*", 0
					, "uint", 0
					, "UInt*", Alpha<<16|1<<24
					, "uint", 2)
}
DeleteObject(hObject)
{
   return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
}
DeleteDC(hdc)
{
   return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
}
Gdip_DeleteGraphics(pGraphics)
{
   return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
}
Gdip_Shutdown(pToken)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
	if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
		DllCall("FreeLibrary", Ptr, hModule)
	return 0
}
Gdip_CreatePath(BrushMode=0)
{
	DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
	return Path
}
Gdip_BrushCreateSolid(ARGB=0xff000000)
{
	DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
	return pBrush
}
Gdip_FillPath(pGraphics, pBrush, Path)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
}
Gdip_DeleteBrush(pBrush)
{
   return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
}
Gdip_FontFamilyCreate(Font)
{
	Ptr := A_PtrSize ? "UPtr" : "UInt"
	
	if (!A_IsUnicode)
	{
		nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
		VarSetCapacity(wFont, nSize*2)
		DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
	}
	
	DllCall("gdiplus\GdipCreateFontFamilyFromName"
					, Ptr, A_IsUnicode ? &Font : &wFont
					, "uint", 0
					, A_PtrSize ? "UPtr*" : "UInt*", hFamily)
	
	return hFamily
}
Gdip_StringFormatCreate(Format=0, Lang=0)
{
   DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
   return hFormat
}
Gdip_SetStringFormatAlign(hFormat, Align)
{
   return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
}
Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
{
	return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
}
CreateRectF(ByRef RectF, x, y, w, h)
{
   VarSetCapacity(RectF, 16)
   NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
}
Gdip_DeleteFontFamily(hFamily)
{
   return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
}
Gdip_DeleteStringFormat(hFormat)
{
   return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
}

Attachments
spiral path points.ahk
(12.24 KiB) Downloaded 21 times
User avatar
masheen
Posts: 295
Joined: 06 Dec 2016, 14:10

Re: Box Spiral posible?

25 May 2017, 19:45

Thx to all, you help
Big thx for this:
noname wrote:

Code: Select all

get_points:
  l:=7 , changex:=0 , x:=100 ,y:=100 ,s:=0
  points .= 100 "," 100 "| "
  Loop 20
    {
      s++
      sign:= regexmatch(s,"3|4")?-1 : 1
      s:=s>4 ? 1 : s

      t:=!t
      If t
          x:=x+l*A_Index*sign
      Else
          y:=y+l*A_Index*sign
      points .= x "," y "|"
    }
return
finaly i have
Code:

Code: Select all

x = 440 ; Center X
y = 440 ; Center Y

Loop 16{  ; 36
	n++	
	t:=!t
	if mod(n, 2)
		s:= s=1 ?-1 : 1
	loop %n%{
		if t
			y := y+20*s  ;10
		else
				x := x+35*s ; 17
		Sleep 1
		ControlClick2(x,y,win) 
	}
}
ExitApp
my question was wrong, i need this
Image

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], inseption86, jaka1, LuckyJoe, Rohwedder and 346 guests