AutoHotkey Community

It is currently May 25th, 2012, 11:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: moon phase
PostPosted: February 6th, 2008, 12:23 pm 
Offline

Joined: October 5th, 2007, 2:21 am
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2008, 2:21 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
I dont understand how does it display the moon phases

(Crescent, Half Moon, Full Moon)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2008, 2:55 pm 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
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!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2008, 11:40 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
Yeah i think so too

i think he should your use pictures of the moon instead


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2008, 11:43 pm 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
Also im just getting slivers of blue in the progress bar


not a 100 percent full or nothing


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 1:45 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
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 :x

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 1:59 am 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
but see

the progress bar keeps getting bigger

not smaller


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 2:00 am 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
Also Rhys

please fix you script

i would really like this


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 2:00 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
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!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 2:01 am 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
Oh ok

also see two posts above]


Edit:


just saw your edit


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 3:33 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
OK, here's my script - Grab the zip hereto 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!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 12:09 pm 
Offline

Joined: October 5th, 2007, 2:21 am
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia
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 February 8th, 2008, 12:39 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2008, 2:55 pm 
Offline

Joined: October 5th, 2007, 2:21 am
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2008, 1:46 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2008, 12:50 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: infogulch, Opal Monkey, tidbit and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group