 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
rodfell
Joined: 05 Oct 2007 Posts: 30 Location: Bundaberg (Bundy), Qld, Australia
|
Posted: Wed Feb 06, 2008 12:23 pm Post subject: moon phase |
|
|
fairly accurate and simple moon phase calculator. the code could be shortened but i wrote it like this so it is easier to modify | Code: | time=%a_nowutc%
envsub, time, 20000101000000, seconds ;number of seconds this "millenium" (since jan 1 2000)
daysthismill:=time/86400 ;number of days this "millenium"
dayssinceFM1:=daysthismill-20.362954 ;number of days since first full moon this "millenium"
numlunarcycles:=dayssinceFM1/29.5305888531 ;number of lunar cycles this "millenium"
thislunarcycle:=numlunarcycles-floor(numlunarcycles) ;how far through this cycle are we (0 to 1)
howfarfromNM:=abs(thislunarcycle-0.5) ;how far away are we from mid-cycle (new moon = 0, full moon = 0.5) (0-0.5)
scale100:=round(howfarfromNM*200) ;scale to 0-100 (integer)
gui +AlwaysOnTop
gui, add, progress, w200 h40 ,%scale100%
gui, show,w220 h60 , Moon phase |
|
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 533
|
Posted: Wed Feb 06, 2008 2:21 pm Post subject: |
|
|
I dont understand how does it display the moon phases
(Crescent, Half Moon, Full Moon) _________________ check out my site
www.eliteknifesquad.com
 |
|
| Back to top |
|
 |
Rhys
Joined: 17 Apr 2007 Posts: 702 Location: Florida
|
Posted: Wed Feb 06, 2008 2:55 pm Post subject: |
|
|
Cool idea! However, I agree that outputting to a progress bar is confusing. I assume that if the bar is empty, it's a new moon, and if it's 100%, it's full? _________________ [Join IRC!]
 |
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 533
|
Posted: Wed Feb 06, 2008 11:40 pm Post subject: |
|
|
Yeah i think so too
i think he should your use pictures of the moon instead _________________ check out my site
www.eliteknifesquad.com
 |
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 533
|
Posted: Wed Feb 06, 2008 11:43 pm Post subject: |
|
|
Also im just getting slivers of blue in the progress bar
not a 100 percent full or nothing _________________ check out my site
www.eliteknifesquad.com
 |
|
| Back to top |
|
 |
Rhys
Joined: 17 Apr 2007 Posts: 702 Location: Florida
|
Posted: Thu Feb 07, 2008 1:45 am Post subject: |
|
|
We're very close to a new moon, so it should be around 0%. I actually whipped up a GUI-based script with pictures of moon phases based on this calculation, but I was off on my phase-pics and I ended up getting a full moon instead of a new one  _________________ [Join IRC!]
 |
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 533
|
Posted: Thu Feb 07, 2008 1:59 am Post subject: |
|
|
but see
the progress bar keeps getting bigger
not smaller _________________ check out my site
www.eliteknifesquad.com
 |
|
| Back to top |
|
 |
Rhys
Joined: 17 Apr 2007 Posts: 702 Location: Florida
|
Posted: Thu Feb 07, 2008 2:00 am Post subject: |
|
|
I think it will get bigger until there's a full moon, then smaller again until the new moon where it will start over.
Edit: I'll post it up in a day or two, it's at work. _________________ [Join IRC!]
 |
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 533
|
Posted: Thu Feb 07, 2008 2:00 am Post subject: |
|
|
Also Rhys
please fix you script
i would really like this _________________ check out my site
www.eliteknifesquad.com
 |
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 533
|
Posted: Thu Feb 07, 2008 2:01 am Post subject: |
|
|
Oh ok
also see two posts above]
Edit:
just saw your edit _________________ check out my site
www.eliteknifesquad.com
 |
|
| Back to top |
|
 |
Rhys
Joined: 17 Apr 2007 Posts: 702 Location: Florida
|
Posted: Thu Feb 07, 2008 3:33 am Post subject: |
|
|
OK, here's my script - Grab the zip here to have the images:
Note - Images come from here | Code: | #SingleInstance, Force
#NoEnv
#NoTrayIcon
Settimer, ClickMoon, 1800000
Gui, add, pic, h100 w100 gClickMoon,Phases\1.gif
Gui, Color, Black
Gui, -MaximizeBox ;Doesn't seem to work
Gui, Show, ,Lunar Phase
Loop, 14
{
Splash:=14 + A_Index
GuiControl, , Static1, Phases\%splash%.gif
Sleep, 50
}
GoSub, GetPhase
GoSub, MoonMe
Return
GetPhase:
time=%a_nowutc%
envsub, time, 20000101000000, seconds ;number of seconds this "millenium" (since jan 1 2000)
daysthismill:=time/86400 ;number of days this "millenium"
dayssinceFM1:=daysthismill-20.362954 ;number of days since first full moon this "millenium"
numlunarcycles:=dayssinceFM1/29.5305888531 ;number of lunar cycles this "millenium"
thislunarcycle:=numlunarcycles-floor(numlunarcycles) ;how far through this cycle are we (0 to 1)
phase:=ceil(28 * thislunarcycle)
Return
MoonMe:
Rolled:=False
Loop,
{
Splash++
If (Splash = 29)
{
Splash=1
Rolled:=True
}
GuiControl, , Static1, Phases\%Splash%.gif
Sleep, 50
If ((Splash = Phase) AND (Rolled = True))
Break
}
Return
ClickMoon:
GoSub, GetPhase
GoSub, MoonMe
Return
GuiClose:
ExitApp |
_________________ [Join IRC!]
 |
|
| Back to top |
|
 |
rodfell
Joined: 05 Oct 2007 Posts: 30 Location: Bundaberg (Bundy), Qld, Australia
|
Posted: Thu Feb 07, 2008 12:09 pm Post subject: |
|
|
it's a new moon. there's no moon to see so there's nothing on the progress bar. it will gradually change to 100% over the next 14 days as we approach the full mooon. it will then gradually decline back to 0%. sorry for the confusion. i've added the moon phase to the title bar | Code: | time=%a_nowutc%
envsub, time, 20000101000000, seconds ;number of seconds this "millenium" (since jan 1 2000)
daysthismill:=time/86400 ;number of days this "millenium"
dayssinceFM1:=daysthismill-20.362954 ;number of days since first full moon this "millenium"
numlunarcycles:=dayssinceFM1/29.5305888531 ;number of lunar cycles this "millenium"
thislunarcycle:=numlunarcycles-floor(numlunarcycles) ;how far through this cycle are we (0 to 1)
howfarfromNM:=abs(thislunarcycle-0.5) ;how far away are we from mid-cycle (new moon = 0, full moon = 0.5) (0-0.5)
scale100:=round(howfarfromNM*200) ;scale to 0-100 (integer)
if thislunarcycle between 0 and 0.0625
phase=Full Moon
if thislunarcycle between 0.0625 and 0.1875
phase=Waning Gibbous
if thislunarcycle between 0.1875 and 0.3125
phase=Last Quarter
if thislunarcycle between 0.3125 and 0.4375
phase=Waning Crescent
if thislunarcycle between 0.4375 and 0.5625
phase=New Moon
if thislunarcycle between 0.5625 and 0.6875
phase=Waxing Crescent
if thislunarcycle between 0.6875 and 0.8125
phase=First Quarter
if thislunarcycle between 0.8125 and 0.9375
phase=Waxing Gibbous
if thislunarcycle between 0.9375 and 1
phase=Full Moon
gui +AlwaysOnTop
gui, add, progress, w200 h40 ,%scale100%
gui, show,w220 h60 , %phase%
return
GuiClose:
ExitApp |
Last edited by rodfell on Fri Feb 08, 2008 12:39 am; edited 1 time in total |
|
| Back to top |
|
 |
rodfell
Joined: 05 Oct 2007 Posts: 30 Location: Bundaberg (Bundy), Qld, Australia
|
Posted: Thu Feb 07, 2008 2:55 pm Post subject: |
|
|
added photos as per work from rhys. labelled progress bar for clarity. changed lunar cycle from (full moon to full moon) to (new moon to new mooon) which makes image collection a simpler calculation. Updates every hour
| Code: |
#persistent
settimer,moon, 3600000
moon:
time=%a_nowutc%
lunarmonth=29.5305888531
envsub, time, 20000101000000, seconds ;number of seconds this "millenium" (since jan 1 2000)
daysthismill:=time/86400 ;number of days this "millenium"
dayssinceNM1:=daysthismill-5.59766 ;number of days since first new moon this "millenium"
numlunarcycles:=dayssinceNM1/lunarmonth ;number of lunar cycles this "millenium"
thislunarcycle:=numlunarcycles-floor(numlunarcycles) ;how far through this cycle are we (0 to 1)
howfarfromNM:=0.5-abs(thislunarcycle-0.5) ;how far away are we from new moon (full moon = 0.5, new moon = 0) (0-0.5)
scale100:=round(howfarfromNM*200) ;scale to 0-100 (integer)
moongif:=ceil(29*thislunarcycle) ;calculate image number (1-29)
UrlDownloadToFile, http://stardate.org/nightsky/moon/moon%moongif%.gif, %A_AppDataCommon%/moon%moongif%.jpg ;download image
;images on website number 1-13 waxing moon , 14 full moon, 15-29 waning moon
if thislunarcycle between 0 and 0.0625 ;8 standard moon phases
phase=New Moon
if thislunarcycle between 0.0625 and 0.1875
phase=Waxing Crescent
if thislunarcycle between 0.1875 and 0.3125
phase=First Quarter
if thislunarcycle between 0.3125 and 0.4375
phase=Waxing Gibbous
if thislunarcycle between 0.4375 and 0.5625
phase=Full Moon
if thislunarcycle between 0.5625 and 0.6875
phase=Waning Gibbous
if thislunarcycle between 0.6875 and 0.8125
phase=Last Quarter
if thislunarcycle between 0.8125 and 0.9375
phase=Waning Crescent
if thislunarcycle between 0.9375 and 1
phase=New Moon
gui, destroy
gui +AlwaysOnTop
gui, add, text,x5 y15, %phase%
gui, add, progress, w100 h20 x5 y50 ,%scale100%
gui, add, text,x5 y70, %scale100%`% of full
Gui, add, picture, h100 w100 x5 y100,%A_AppDataCommon%/moon%moongif%.jpg
gui, add, text,x5 y200, Appearance
gui, show,w110 h220 , Moon Phase
return
GuiClose:
ExitApp |
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2474 Location: Australia, Qld
|
Posted: Mon Feb 11, 2008 1:46 am Post subject: |
|
|
I've made some additions to Rhys' script to reduce (hopefully remove) flicker.
| Code: | #SingleInstance, Force
#NoEnv
#NoTrayIcon
OnMessage(0x14, "WM_ERASEBKGND")
Settimer, ClickMoon, 1800000
Gui, -MaximizeBox
Gui, add, pic, h100 w100 gClickMoon,Phases\1.gif
Gui, Show, ,Lunar Phase
Loop, 14
{
Splash:=14 + A_Index
GuiControl, , Static1, *w100 *h100 Phases\%splash%.gif
Sleep, 50
}
GoSub, GetPhase
GoSub, MoonMe
Return
WM_ERASEBKGND(wParam)
{
if A_Gui = 1
{
Gui, +LastFound
hwnd := WinExist()
GuiControlGet, pic, Pos, Static1
; these are sometimes 0 when the background is erased!
; (it seems to be erased while the picture is changing)
picW := 100
picH := 100
hdc := DllCall("GetDC", "uint", hwnd)
; Exclude the picture control from the clipping region.
DllCall("ExcludeClipRect", "uint", hdc
, "int", picX, "int", picY, "int", picX+picW, "int", picY+picH)
; Draw a black rectangle over the whole GUI.
VarSetCapacity(rect, 16)
DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
DllCall("FillRect", "uint", hdc
, "uint", &rect
, "uint", DllCall("GetStockObject", "int", 0x4))
DllCall("ReleaseDC", "uint", hwnd, "uint", hdc)
return 1
}
}
GetPhase:
time=%a_nowutc%
envsub, time, 20000101000000, seconds ;number of seconds this "millenium" (since jan 1 2000)
daysthismill:=time/86400 ;number of days this "millenium"
dayssinceFM1:=daysthismill-20.362954 ;number of days since first full moon this "millenium"
numlunarcycles:=dayssinceFM1/29.5305888531 ;number of lunar cycles this "millenium"
thislunarcycle:=numlunarcycles-floor(numlunarcycles) ;how far through this cycle are we (0 to 1)
phase:=ceil(28 * thislunarcycle)
Return
MoonMe:
Rolled:=False
Loop,
{
Splash++
If (Splash = 29)
{
Splash=1
Rolled:=True
}
GuiControl, , Static1, *w100 *h100 Phases\%Splash%.gif
Sleep, 50
If ((Splash = Phase) AND (Rolled = True))
Break
}
Return
ClickMoon:
GoSub, GetPhase
GoSub, MoonMe
Return
GuiClose:
ExitApp
| At first I tried simply adding WS_CLIPCHILDREN (0x2000000). That didn't work, so I overrode WM_ERASEBKGND to exclude the picture control from the GUI's clipping region, then paint the GUI black. Somehow when I added the WM_ERASEBKGND handler, GuiControl would shrink the pictures down to normal size, so I added *w100 *h100. |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 411 Location: Galil, Israel
|
Posted: Tue Feb 12, 2008 12:50 am Post subject: |
|
|
just ran,
resulting in day 20 of moon phase...
but pretty sure we in day 6...
perhaps is off 1/4 lunar month (?)
or maybe I'm looking at some other planet instead of moon (which is possible.) _________________ Joyce Jamce |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|