Fun with GDIPlus (GDI+)

Post your working scripts, libraries and tools
User avatar
nnnik
Posts: 4470
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fun with GDIPlus (GDI+)

21 Jan 2016, 14:31

I wrote this script.
It records your Mouse movement and prints it on a Picture.
(This was actually a request in the IRC)

Code: Select all

#Persistent
	#SingleInstance, force
	OnExit, Exit
	CoordMode,Mouse,Screen
	SetBatchLines,-1
	If !FileExist("Settings.ini")
	{	
		GrowthSpeed  := 5   ;How fast circles grow bigger  
		CheckInterval:= 5    ;Time in Milliseconds between checking the Mouse and redrawing the Picture
		SaveInterval := 130000 ;Time in Milliseconds between a Save
		RecolorSpeed := 10  ;How fast the color changes
		IniWrite,%GrowthSpeed%,Settings.ini,General,GrowthSpeed
		IniWrite,%CheckInterval%,Settings.ini,General,CheckInterval
		IniWrite,%SaveInterval%,Settings.ini,General,SaveInterval
		IniWrite,%RecolorSpeed%,Settings.ini,General,RecolorSpeed
		FileAppend,
		(
This Readme provides the basic information, needed to control the screen recording tool.
The Program will create a file named README.txt and Settings.ini.
The Settings can be found and changed in the Settings.ini

Values:
GrowthSpeed - Controls how fast circles grow.
Larger values mean circles grow faster.
Smaller values mean circles grow slower.

CheckInterval - Controls how accurate the Mouse should be recorded.
Sets the time in milliseconds between each drawing command.
Larger values mean less accurate results and less ressource usage.
Smaller values mean more accurate results and more ressource usage.

SaveInterval - Controls how often a picture is saved in Milliseconds.
I guess that one is self explinatory.

RecolorSpeed - Controls how fast it changes it's color.
Larger values mean that the color changes faster.
Smaller values mean that the color changes slower.
		),README.txt
	}
	Else
	{
		IniRead,GrowthSpeed,Settings.ini,General,GrowthSpeed
		IniRead,CheckInterval,Settings.ini,General,CheckInterval
		IniRead,SaveInterval,Settings.ini,General,SaveInterval
		IniRead,RecolorSpeed,Settings.ini,General,RecolorSpeed
	}
	pToken   := Gdip_Startup()
	pBitmap  := Gdip_CreateBitmap(A_ScreenWidth+2,A_ScreenHeight+2)
	pGraphics:= Gdip_GraphicsFromImage(pBitmap)
	pBkgnd   := Gdip_BrushCreateSolid(0xFF000000)
	Gdip_FillRectangle(pGraphics, pBkgnd, 0, 0, A_ScreenWidth+2, A_ScreenHeight+2)
	Gdip_DeleteBrush(pBkgnd)

	MouseGetPos,OldX,OldY
	PictureNr := 0
	LastChange:= A_TickCount
	LastUpdate:= A_TickCount-(1500/RecolorSpeed)*2
	Unchanged := 1
	
	FileRemoveDir,Pictures,1
	FileCreateDir,Pictures

	SetTimer,Redraw,% CheckInterval  
	SetTimer,Resave,% SaveInterval
Return



Redraw:
	MouseGetPos,x,y
	if  !((x=OldX)&&(y=OldY))
	{
		UpdateBrushAndPen()
		If ((Size:=(A_TickCount-LastChange)*GrowthSpeed/100000)>2)
			Gdip_FillEllipse(pGraphics, pBrush, OldX-Size, OldY-Size, Size*2, Size*2)
		Gdip_DrawLine(pGraphics, pPen, OldX+1, OldY+1, x+1, y+1)
		OldX      := X
		OldY      := Y
		LastChange:= A_TickCount
	}
return

Resave:
	If ((Size:=(A_TickCount-LastChange)/1000)>2)
	{
		UpdateBrushAndPen()
		Gdip_FillEllipse(pGraphics, pBrush, OldX-Size, OldY-Size, Size*2, Size*2)
	}
	Gdip_SaveBitmapToFile(pBitmap,"Pictures/PicNr" . PictureNr++ . ".png",100)
return

Exit:
	Gdip_DeletePen(pPen)
	Gdip_DeleteBrush(pBrush)
	Gdip_DeleteGraphics(pGraphics)
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken)
ExitApp




UpdateBrushAndPen()
{
	global pBrush,pPen,LastUpdate,RecolorSpeed
	static R:=255,G:=0,B:=0
	If ((A_TickCount-LastUpdate)*RecolorSpeed/1500>1)
	{
		Gdip_DeletePen(pPen)
		Gdip_DeleteBrush(pBrush)
		Loop % floor((A_TickCount-LastUpdate)*RecolorSpeed/1500)
		{
			nR := (R+1)*(G+1)/(B+1)
			nG := (G+1)*(B+1)/(R+1)
			nB := (B+1)*(R+1)/(G+1)
			nAV:= nR + nG + nB
			nR := nR/nAV
			nG := nG/nAV
			nB := nB/nAV
			wAV:= R+G+B
			wR := R/wAV
			wG := G/wAV	
			wB := B/wAV
			R := nR*5+wR*250
			G := nG*5+wG*250
			B := nB*5+wB*250	
		}
		LastUpdate := A_TickCount
		pPen 	:= Gdip_CreatePen(Gdip_ToARGB(255, R, G, B), 2)
		pBrush  := Gdip_BrushCreateSolid(Gdip_ToARGB(255, R, G, B))
	}
}
PicNr13.png
Recommends AHK Studio
User avatar
jNizM
Posts: 2662
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Fun with GDIPlus (GDI+)

11 Aug 2016, 02:53

Renew code & screenshots:
- Wave
- Exuberant Wave
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2662
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Fun with GDIPlus (GDI+)

11 Aug 2016, 06:34

Cyclope Monkey (by Jerome Herr)

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

; ===============================================================================================================================

global w   := 800
global h   := 600
global a   := 0
global b   := 0
global hue := 0

; ===============================================================================================================================

hSHLWAPI := DllCall("LoadLibrary", "Str", "shlwapi.dll", "Ptr")
hGDIPLUS := DllCall("LoadLibrary", "Str", "GdiPlus.dll", "Ptr")
VarSetCapacity(SI, 24, 0), Numput(1, SI, 0, "Int")
DllCall("GdiPlus.dll\GdiplusStartup", "UPtr*", pToken, "Ptr", &SI, "Ptr", 0)

; ===============================================================================================================================

Gui, +LastFound +hwndhGDIPFun
Gui, Show, w%w% h%h%

DllCall("GdiPlus.dll\GdipCreateFromHWND", "Ptr", hGDIPFun, "Ptr*", pGraphics)
DllCall("GdiPlus.dll\GdipCreateBitmapFromGraphics", "Int", w, "Int", h, "Ptr", pGraphics, "Ptr*", pBitmap)
DllCall("Gdiplus.dll\GdipGetImageGraphicsContext", "Ptr", pBitmap, "Ptr*", pGraphicsCtxt)
DllCall("Gdiplus.dll\GdipSetSmoothingMode", "Ptr", pGraphicsCtxt, "Int", 2)
DllCall("Gdiplus.dll\GdipCreatePen1", "UInt", 0xFFFFFFFF, "Float", 1, "Int", 2, "Ptr*", pPen)
DllCall("GdiPlus.dll\GdipGraphicsClear", "Ptr", pGraphicsCtxt, "UInt", 0x7F000000)

loop
{
    DllCall("GdiPlus.dll\GdipSetPenColor", "Ptr", pPen, "UInt", "0xCC" ColorHLSToRGB(hue, 120, 240))
    , x0 := w / 5 + ((w - w / 5) - w / 5) * ((sin(a) - -1) / 2)
    , y0 := h / 5 + ((h - h / 5) - h / 5) * (((cos(a) * 1.5) - -1) / 2)
    , x1 := w / 5 + ((w - w / 5) - w / 5) * ((sin(b) - -1) / 2)
    , y1 := h / 5 + ((h - h / 5) - h / 5) * (((cos(b)) - -1) / 2)
    , DllCall("GdiPlus.dll\GdipDrawLine", "ptr", pGraphicsCtxt, "ptr", pPen, "float", x0, "float", y0, "float", x1, "float", y1)
    , a += 0.04, b += 0.05, hue += 1, hue := (hue > 239) ? mod(hue, 239) : hue
    , DllCall("Gdiplus.dll\GdipDrawImage", "Ptr", pGraphics, "Ptr", pBitmap, "Float", 0, "Float", 0)
} until (a > 24)
return

; ===============================================================================================================================

ColorHLSToRGB(hue, lum, sat)
{
    clr := DllCall("shlwapi.dll\ColorHLSToRGB", "UShort", hue, "UShort", lum, "UShort", sat)
    return Format("{:06X}", ((clr & 0xff00) | ((clr & 0xff) << 16) | ((clr & 0xff0000) >> 16)))
}

; ===============================================================================================================================

GuiClose:
GuiEscape:
    DllCall("GdiPlus.dll\GdipDeletePen", "Ptr", pPen)
    DllCall("GdiPlus.dll\GdipDeleteGraphics", "Ptr", pGraphicsCtxt)
    DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", pBitmap)
    DllCall("GdiPlus.dll\GdipDeleteGraphics", "Ptr", pGraphics)
    DllCall("GdiPlus.dll\GdiplusShutdown", "Ptr", pToken)
    DllCall("FreeLibrary", "Ptr", hGDIPLUS)
    DllCall("FreeLibrary", "Ptr", hSHLWAPI)
    ExitApp
return
Image
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Fun with GDIPlus (GDI+)

26 Jul 2017, 20:36

Some links. Cheers.

By me:
graphics: Solar System - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=34790
graphics: rainbow colours - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=34837
[it has a Gdip version, allowing you to create an image based on a list of pixels]
graphics: create bmp files from scratch - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=34952

By other people:
Laughing Man - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=30718
[GDI+][Class] Particle System 2.0 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26485
GDI_GrayscaleBitmap() - Converts GDI bitmap to Greyscale - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/8279 ... greyscale/
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
joedf
Posts: 7759
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Fun with GDIPlus (GDI+)

20 Dec 2017, 17:56

Neat! :+1:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 20 guests