Compass Rose

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Allen
Posts: 20
Joined: 29 Jan 2019, 10:01

Compass Rose

22 Feb 2020, 16:42

Anyone who can help,

I need to display a circle as a 'compass rose' an allow a 'click' on it to record a bearing.
I have searched the forums for 'circle' and 'compass', but cannot find anything relevant that will give me a start in the right direction.

Please can anyone help by showing me a basic idea to draw a circle and label the basic compass points around it?

Many thanks,

Allen
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: Compass Rose

22 Feb 2020, 20:23

You can draw a smooth circle using the GDI+ Library.

Alternatively, here's a quick self-contained approach:

Code: Select all

Gui, Add, Progress, BackgroundBlack x130 y130 w3 h3
Points := PointsOnCircle(100, 5, 130, 30)
for Each, P in Points
	Gui, Add, Progress, % "BackgroundBlack x" P.x " y" P.y " w3 h3"
Gui, Font, s12
Gui, Add, Text, x125 y5, N
Gui, Add, Text, xp y235, S
Gui, Add, Text, x10 y120, W
Gui, Add, Text, x240 yp, E
Gui, Show
return

PointsOnCircle(r := 200, degInc := 5, topX := 100, topY := 0)
{
	static radPerDeg := 3.14159265359 / 180
	points := []

	angle := 0
	cx := 0
	cy := r
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		points.Push({x: cx + r * Sin(angle) + topX, y: cy - r * Cos(angle) + topY})
	}
	return points
}

GuiClose:
ExitApp
Change the second line to the following to make it more of a solid circle (changes degree increment from 5 to 1):

Code: Select all

Points := PointsOnCircle(100, 1, 130, 30)
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: Compass Rose

22 Feb 2020, 20:35

This version has an inner "circle" marking every 45 degrees:

Code: Select all

Gui, Add, Progress, BackgroundRed x130 y130 w3 h3
Points := PointsOnCircle(100, 1, 130, 30)
for Each, P in Points
	Gui, Add, Progress, % "BackgroundBlack x" P.x " y" P.y " w3 h3"
Points := PointsOnCircle(90, 45, 130, 40)
for Each, P in Points
	Gui, Add, Progress, % "BackgroundRed x" P.x " y" P.y " w3 h3"
Gui, Font, s12 cBlue
Gui, Add, Text, x125 y5, N
Gui, Add, Text, xp y235, S
Gui, Add, Text, x10 y120, W
Gui, Add, Text, x240 yp, E
Gui, Show
return

PointsOnCircle(r := 200, degInc := 5, topX := 100, topY := 0)
{
	static radPerDeg := 3.14159265359 / 180
	points := []

	angle := 0
	cx := 0
	cy := r
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		points.Push({x: cx + r * Sin(angle) + topX, y: cy - r * Cos(angle) + topY})
	}
	return points
}

GuiClose:
ExitApp
Allen
Posts: 20
Joined: 29 Jan 2019, 10:01

Re: Compass Rose

23 Feb 2020, 05:10

Hi boiler,

Many thanks - that has pointed me in the right direction, and given me a basis on which to work.

I appreciate your help,
Yours sincerely,
Allen

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: SimmoF and 233 guests