Last active
August 9, 2024 09:01
-
-
Save jNizM/796387269b3f22fa3539864f9a1cfdd6 to your computer and use it in GitHub Desktop.
[AHK] nonsense with gdi+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires AutoHotkey v2.0 | |
#DllLoad "GdiPlus.dll" | |
#DllLoad "shlwapi.dll" | |
s := Map("w", 800, "h", 600, "a", 0, "b", 0, "hue", 0, "x0", 0, "x1", 0, "y1", 0, "y2", 0) | |
NumPut("UInt", 1, SI := Buffer(24, 0)) | |
if (DllCall("GdiPlus\GdiplusStartup", "Ptr*", &pToken := 0, "Ptr", SI.Ptr, "Ptr", 0, "UInt")) | |
throw OSError("GdiPlus failed") | |
GDIP := Gui("+LastFound") | |
GDIP.BackColor := "000000" | |
GDIP.OnEvent("Close", CloseGui) | |
GDIP.Show("W" s["w"] " H" s["h"]) | |
DllCall("GdiPlus\GdipCreateFromHWND", "Ptr", GDIP.hWnd, "Ptr*", &pGraphics := 0) | |
DllCall("GdiPlus\GdipCreateBitmapFromGraphics", "Int", s["w"], "Int", s["h"], "Ptr", pGraphics, "Ptr*", &pBitmap := 0) | |
DllCall("GdiPlus\GdipGetImageGraphicsContext", "Ptr", pBitmap, "Ptr*", &pGraphicsContext := 0) | |
DllCall("GdiPlus\GdipSetSmoothingMode", "Ptr", pGraphicsContext, "Int", 2) | |
DllCall("GdiPlus\GdipCreatePen1", "UInt", 0xFFFFFFFF, "Float", 1, "Int", 2, "Ptr*", &pPen := 0) | |
DllCall("GdiPlus\GdipGraphicsClear", "Ptr", pGraphicsContext, "Int", 0x7F000000) | |
loop | |
{ | |
DllCall("GdiPlus\GdipSetPenColor", "Ptr", pPen, "UInt", "0xCC" ColorHLSToRGB(s["hue"], 120, 240)) | |
s["x0"] := s["w"] / 5 + ((s["w"] - s["w"] / 5) - s["w"] / 5) * ((sin(s["a"]) - -1) / 2) | |
s["y0"] := s["h"] / 5 + ((s["h"] - s["h"] / 5) - s["h"] / 5) * (((cos(s["a"]) * 1.5) - -1) / 2) | |
s["x1"] := s["w"] / 5 + ((s["w"] - s["w"] / 5) - s["w"] / 5) * ((sin(s["b"]) - -1) / 2) | |
s["y1"] := s["h"] / 5 + ((s["h"] - s["h"] / 5) - s["h"] / 5) * (((cos(s["b"])) - -1) / 2) | |
DllCall("GdiPlus\GdipDrawLine", "Ptr", pGraphicsContext, "Ptr", pPen, "Float", s["x0"], "Float", s["y0"], "Float", s["x1"], "Float", s["y1"]) | |
s["a"] += 0.04, s["b"] += 0.05, s["hue"] += 1, s["hue"] := (s["hue"] > 239) ? mod(s["hue"], 239) : s["hue"] | |
DllCall("Gdiplus\GdipDrawImage", "Ptr", pGraphics, "Ptr", pBitmap, "Float", 0, "Float", 0) | |
} until (s["a"] > 24) | |
CloseGui(*) | |
{ | |
DllCall("GdiPlus\GdipDeletePen", "Ptr", pPen) | |
DllCall("GdiPlus\GdipDeleteGraphics", "Ptr", pGraphicsContext) | |
DllCall("Gdiplus\GdipDisposeImage", "Ptr", pBitmap) | |
DllCall("GdiPlus\GdipDeleteGraphics", "Ptr", pGraphics) | |
DllCall("GdiPlus\GdiplusShutdown", "Ptr", pToken) | |
} | |
ColorHLSToRGB(hue, lum, sat) | |
{ | |
clr := DllCall("shlwapi\ColorHLSToRGB", "UShort", hue, "UShort", lum, "UShort", sat) | |
return Format("{:06X}", ((clr & 0xff00) | ((clr & 0xff) << 16) | ((clr & 0xff0000) >> 16))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires AutoHotkey v2.0 | |
OnExit ExitFunc | |
#DllLoad "GdiPlus.dll" | |
#DllLoad "shlwapi.dll" | |
pi := ATan(1) * 4 | |
pi2 := pi * 2 | |
rad := 360 / pi2 | |
num := 25 | |
step := 20 | |
maxrad := num * step - 15 | |
w := maxrad | |
h := maxrad | |
theta := 0 | |
hue := 0 | |
NumPut("UInt", 1, SI := Buffer(24, 0)) | |
if (DllCall("GdiPlus\GdiplusStartup", "Ptr*", &pToken := 0, "Ptr", SI.Ptr, "Ptr", 0, "UInt")) | |
throw OSError("GdiPlus failed") | |
GDIP := Gui("+LastFound") | |
GDIP.BackColor := "000000" | |
GDIP.OnEvent("Close", ExitFunc) | |
GDIP.Show("W" w " H" h) | |
DllCall("GdiPlus\GdipCreateFromHWND", "Ptr", GDIP.hWnd, "Ptr*", &pGraphics := 0) | |
DllCall("GdiPlus\GdipCreateBitmapFromGraphics", "Int", w, "Int", h, "Ptr", pGraphics, "Ptr*", &pBitmap := 0) | |
DllCall("GdiPlus\GdipGetImageGraphicsContext", "Ptr", pBitmap, "Ptr*", &pGraphicsContext := 0) | |
DllCall("GdiPlus\GdipSetSmoothingMode", "Ptr", pGraphicsContext, "Int", 2) | |
DllCall("GdiPlus\GdipCreatePen1", "UInt", 0xFFFFFFFF, "Float", 3, "Int", 2, "Ptr*", &pPen := 0) | |
/* | |
poor solution with try bacause of 0xc0000005 exception when closing the gui while running. never happend with v1 | |
see: https://www.autohotkey.com/docs/v2/lib/DllCall.htm#error | |
Error: The function was called but it aborted with a fatal exception. Exception.Extra contains the exception code. | |
For example, 0xC0000005 means "access violation". | |
In such cases, the thread is aborted (if try is not used), but any asterisk variables are still updated. | |
*/ | |
loop | |
{ | |
try DllCall("GdiPlus\GdipGraphicsClear", "Ptr", pGraphicsContext, "Int", 0x7F000000) | |
loop num | |
{ | |
i := A_Index - 1 | |
sz := i * step | |
offset := maxrad / 2 - sz / 2 | |
arcend := (pi + (pi2 - pi) * ((sin(theta + (pi2 / num * i)) - -1) / 2) - pi) * rad | |
try DllCall("GdiPlus\GdipSetPenColor", "Ptr", pPen, "UInt", "0xFF" ColorHLSToRGB(hue + i, 120, 240)) | |
try DllCall("GdiPlus\GdipDrawArc", "Ptr", pGraphicsContext, "Ptr", pPen, "Float", offset, "Float", offset, "Float", sz, "Float", sz, "Float", 0, "Float", arcend) | |
try DllCall("GdiPlus\GdipDrawArc", "Ptr", pGraphicsContext, "Ptr", pPen, "Float", offset, "Float", offset, "Float", sz, "Float", sz, "Float", 180, "Float", arcend) | |
} | |
theta += 0.0523 | |
theta := (theta > pi2) ? mod(theta, pi2) : theta | |
hue += 0.5 | |
hue := (hue > 239) ? mod(hue, 239) : hue | |
try DllCall("Gdiplus\GdipDrawImage", "Ptr", pGraphics, "Ptr", pBitmap, "Float", 0, "Float", 0) | |
Sleep 10 | |
} | |
ExitFunc(*) | |
{ | |
try DllCall("GdiPlus\GdipDeletePen", "Ptr", pPen) | |
try DllCall("GdiPlus\GdipDeleteGraphics", "Ptr", pGraphicsContext) | |
try DllCall("Gdiplus\GdipDisposeImage", "Ptr", pBitmap) | |
try DllCall("GdiPlus\GdipDeleteGraphics", "Ptr", pGraphics) | |
try DllCall("GdiPlus\GdiplusShutdown", "Ptr", pToken) | |
} | |
ColorHLSToRGB(hue, lum, sat) | |
{ | |
clr := DllCall("shlwapi\ColorHLSToRGB", "UShort", hue, "UShort", lum, "UShort", sat) | |
return Format("{:06X}", ((clr & 0xff00) | ((clr & 0xff) << 16) | ((clr & 0xff0000) >> 16))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment