How to resolve the algorithm Peano curve step by step in the AutoHotkey programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Peano curve step by step in the AutoHotkey programming language

Table of Contents

Problem Statement

Produce a graphical or ASCII-art representation of a Peano curve of at least order 3.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Peano curve step by step in the AutoHotkey programming language

Source code in the autohotkey programming language

gdip1()
PeanoX := A_ScreenWidth/2 - 100, PeanoY := A_ScreenHeight/2 - 100
Peano(PeanoX, PeanoY, 3**3, 5, 5, Arr:=[])
xmin := xmax := ymin := ymax := 0
for i, point in Arr
{
	xmin := A_Index = 1 ? point.x : xmin < point.x ? xmin : point.x
	xmax := point.x > xmax ? point.x : xmax
	ymin := A_Index = 1 ? point.y : ymin < point.y ? ymin : point.y
	ymax := point.y > ymax ? point.y : ymax
}
for i, point in Arr
	points .= point.x - xmin + PeanoX "," point.y - ymin + PeanoY "|"
points := Trim(points, "|")
Gdip_DrawLines(G, pPen, Points)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
return
; ---------------------------------------------------------------
Peano(x, y, lg, i1, i2, Arr) {
	if (lg =1 ) 
	{
		Arr[Arr.count()+1, "x"] := x
		Arr[Arr.count(), "y"] := y
		return
	}
	lg := lg/3
	Peano(x+(2*i1*lg)	, y+(2*i1*lg)		, lg	, i1	, i2	, Arr)
	Peano(x+((i1-i2+1)*lg)	, y+((i1+i2)*lg)	, lg	, i1	, 1-i2	, Arr)
	Peano(x+lg		, y+lg			, lg	, i1	, 1-i2	, Arr)
	Peano(x+((i1+i2)*lg)	, y+((i1-i2+1)*lg)	, lg	, 1-i1	, 1-i2	, Arr)
	Peano(x+(2*i2*lg)	, y+(2*(1-i2)*lg)	, lg	, i1	, i2	, Arr)
	Peano(x+((1+i2-i1)*lg)	, y+((2-i1-i2)*lg)	, lg	, i1	, i2	, Arr)
	Peano(x+(2*(1-i1)*lg)	, y+(2*(1-i1)*lg)	, lg	, i1	, i2	, Arr)
	Peano(x+((2-i1-i2)*lg)	, y+((1+i2-i1)*lg)	, lg	, 1-i1	, i2	, Arr)
	Peano(x+(2*(1-i2)*lg)	, y+(2*i2*lg)		, lg	, 1-i1	, i2	, Arr)
}
; ---------------------------------------------------------------
gdip1(){
	global
	If !pToken := Gdip_Startup()
	{
		MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
		ExitApp
	}
	OnExit, Exit
	Width := A_ScreenWidth, Height := A_ScreenHeight
	Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
	Gui, 1: Show, NA
	hwnd1 := WinExist()
	hbm := CreateDIBSection(Width, Height)
	hdc := CreateCompatibleDC()
	obm := SelectObject(hdc, hbm)
	G := Gdip_GraphicsFromHDC(hdc)
	Gdip_SetSmoothingMode(G, 4)
	pPen := Gdip_CreatePen(0xFFFF0000, 2)
}
; ---------------------------------------------------------------
gdip2(){
	global
	Gdip_DeleteBrush(pBrush)
	Gdip_DeletePen(pPen)
	SelectObject(hdc, obm)
	DeleteObject(hbm)
	DeleteDC(hdc)
	Gdip_DeleteGraphics(G)
}
; ---------------------------------------------------------------
Exit:
gdip2()
Gdip_Shutdown(pToken)
ExitApp
Return


  

You may also check:How to resolve the algorithm Execute HQ9+ step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Erdös-Selfridge categorization of primes step by step in the F# programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the Tcl programming language
You may also check:How to resolve the algorithm Input loop step by step in the Oforth programming language
You may also check:How to resolve the algorithm Comments step by step in the TXR programming language