If anyone has produced anything similar in AHK, or has any interesting links regarding producing dynamic images in AHK (i.e. images that are changing and not static), then please post some links. Thanks.
Code: Select all
;Solar System by jeeswg
;based on Gdip.Tutorial.2-Draw.Outlined.Shapes.ahk
;requires Gdip.ahk or Gdip_All.ahk
#SingleInstance, Force
#NoEnv
vMakePlanetsEquidistant := 0
vYearOffset := 0.25
vYearOffset := 0.01
vSleepMSec := 10
vIncludePluto := 1
vIncludeSun := 1
vIncludeMoon := 1
vPlanetColours := 1
vDrawOrbits := 1
;==============================
;Retrograde and prograde motion - Wikipedia
;https://en.wikipedia.org/wiki/Retrograde_and_prograde_motion
;All eight planets in the Solar System orbit the Sun
;in the direction that the Sun is rotating, which is
;counterclockwise when viewed from above the Sun's north pole.
;Is the Sun yellow or white? · Ask an Astronomer
;http://askanastronomer.org/stars/faq/2015/11/06/is-the-sun-yellow-or-white/
;Moon - Wikipedia
;https://en.wikipedia.org/wiki/Moon
;Dwarf planet - Wikipedia
;https://en.wikipedia.org/wiki/Dwarf_planet
;Pluto - Wikipedia
;https://en.wikipedia.org/wiki/Pluto
;Planet - Wikipedia
;https://en.wikipedia.org/wiki/Planet
;1 Name
;2 Equatorial diameter [h]
;3 Mass [h]
;4 Semi-major axis (AU)
;5 Orbital period (years) [h]
vText := "
(
Mercury 0.382 0.06 0.39 0.24
Venus 0.949 0.82 0.72 0.62
Earth 1.00 1.00 1.00 1.00
Mars 0.532 0.11 1.52 1.88
Jupiter 11.209 317.8 5.20 11.86
Saturn 9.449 95.2 9.54 29.46
Uranus 4.007 14.6 19.22 84.01
Neptune 3.883 17.2 30.06 164.8
)"
if vIncludePluto
vText .= "`nPluto 0.22 0.00218 39.48 248.09"
;Moon (orbital period) = 27.32 / 365.25 = 0.074798
;Moon 0.273 0.012300 0.00257 0.07
oArray := {}
Loop, Parse, vText, `n
oArray[A_Index] := StrSplit(A_LoopField, "`t")
;MsgBox, % oArray[4, 5] ;Mars: 1.88
if vMakePlanetsEquidistant
Loop, % oArray.Length()
oArray[A_Index, 4] := A_Index*4
;==============================
SetBatchLines, -1
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 +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pPenBlk1 := Gdip_CreatePen(0xff000000, 1) ;thickness 1
pPenBlk2 := Gdip_CreatePen(0xff000000, 2) ;thickness 2
;pBrushRed := Gdip_BrushCreateSolid(0xffff0000)
pBrushBlk := Gdip_BrushCreateSolid(0xff000000)
pBrushSun := Gdip_BrushCreateSolid(vPlanetColours?0xffffffff:0xff000000)
pBrushMoon := Gdip_BrushCreateSolid(vPlanetColours?0xff797373:0xff000000)
;planet colours: 8 planets + Pluto
vListRGB := "5A5A5A,D79537,3C6581,ED7D58,E4DFCC,D8B87B,C8EEF1,436AFF,B3AA9B"
if vPlanetColours
Loop, Parse, vListRGB, % ","
pBrush%A_Index% := Gdip_BrushCreateSolid(0xff000000+Format("{:i}", "0x" A_LoopField))
else
Loop, Parse, vListRGB, % ","
pBrush%A_Index% := Gdip_BrushCreateSolid(0xff000000)
vImgCtrX := A_ScreenWidth/2
vImgCtrY := A_ScreenHeight/2
vYears := 0
Loop
{
Gdip_GraphicsClear(G)
Loop, % oArray.Length()
{
vRadius := oArray[A_Index].4 * 10
if vDrawOrbits
Gdip_DrawEllipse(G, pPenBlk1, vImgCtrX-vRadius, vImgCtrY-vRadius, vRadius*2, vRadius*2)
}
vYears += vYearOffset
if vIncludeSun
Gdip_FillEllipse(G, pBrushSun, vImgCtrX-vRadius2, vImgCtrY-vRadius2, vRadius2*2, vRadius2*2)
Loop, % oArray.Length()
{
vRadius := oArray[A_Index].4 * 10
vPeriod := oArray[A_Index].5
;angle = (Mod(years (elapsed), years (orbit duration)) / years (orbit duration)) * 360
vAngle := (Mod(vYears, vPeriod)/vPeriod) * 2 * 3.141592653589793
vPosX := Sin(vAngle+3.141592653589793) * vRadius
vPosY := Cos(vAngle+3.141592653589793) * vRadius
;vRadius2 := oArray[A_Index].2 * 4
vRadius2 := 6
;Gdip_FillEllipse(G, pBrushRed, vImgCtrX-vRadius2, vImgCtrY-vRadius-vRadius2, vRadius2*2, vRadius2*2)
;Gdip_DrawEllipse(G, pPenBlk2, vImgCtrX-vRadius2, vImgCtrY-vRadius-vRadius2, vRadius2*2, vRadius2*2)
;Gdip_FillEllipse(G, pBrushBlk, vImgCtrX-vRadius2, vImgCtrY-vRadius-vRadius2, vRadius2*2, vRadius2*2)
;Gdip_FillEllipse(G, pBrushBlk, vImgCtrX+vPosX-vRadius2, vImgCtrY+vPosY-vRadius2, vRadius2*2, vRadius2*2)
Gdip_FillEllipse(G, pBrush%A_Index%, vImgCtrX+vPosX-vRadius2, vImgCtrY+vPosY-vRadius2, vRadius2*2, vRadius2*2)
if (A_Index = 3) && vIncludeMoon
{
vEarthCtrX := vImgCtrX+vPosX
vEarthCtrY := vImgCtrY+vPosY
vRadius := 10
vPeriod := 0.07
vAngle := (Mod(vYears, vPeriod)/vPeriod) * 2 * 3.141592653589793
vPosX := Sin(vAngle+3.141592653589793) * vRadius
vPosY := Cos(vAngle+3.141592653589793) * vRadius
Gdip_FillEllipse(G, pBrushMoon, vEarthCtrX+vPosX-vRadius2, vEarthCtrY+vPosY-vRadius2, vRadius2*2, vRadius2*2)
}
}
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
Sleep, % vSleepMSec
}
return
Exit:
Gdip_DeletePen(pPenBlk1)
Gdip_DeletePen(pPenBlk2)
;Gdip_DeleteBrush(pBrushRed)
Gdip_DeleteBrush(pBrushBlk)
Gdip_DeleteBrush(pBrushSun)
Gdip_DeleteBrush(pBrushMoon)
Loop, 9
Gdip_DeleteBrush(pBrush%A_Index%)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
return
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
Fun with GDIPlus (GDI+) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=6071
Gdip_All and Gdip tutorial scripts:
GDI+ standard library 1.45 by tic - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=6517
GitHub - tariqporter/Gdip: GDI+ library for Autohotkey
https://github.com/tariqporter/Gdip