Microsoft Small Basic

Program Listing: XML180
GraphicsWindow.BackgroundColor="black"
GraphicsWindow.Title=("Moon Phase Calculator")
GraphicsWindow.Width=200
GraphicsWindow.Height=250
GraphicsWindow.PenColor="white"
GraphicsWindow.DrawLine(20,20,20,160)
GraphicsWindow.DrawLine(180,20,180,160)
GraphicsWindow.DrawLine(20,20,180,20)
GraphicsWindow.DrawLine(20,160,180,160)


If Clock.Month=1 Then
form=0
Else
form=form
EndIf
If Clock.Month=2 Then
form=31
Else
form=form
EndIf
If Clock.Month=3 Then
form=59.25
Else
form=form
EndIf
If Clock.Month=4 Then
form=90.25
Else
form=form
EndIf
If Clock.Month=5 Then
form=120.25
Else
form=form
EndIf
If Clock.Month=6 Then
form=151.25
Else
form=form
EndIf
If Clock.Month=7 Then
form=181.25
Else
form=form
EndIf
If Clock.Month=8 Then
form=212.25
Else
form=form
EndIf
If Clock.Month=9 Then
form=243.25
Else
form=form
EndIf
If Clock.Month=10 Then
form=273.25
Else
form=form
EndIf
If Clock.Month=11 Then
form=304.25
Else
form=form
EndIf
If Clock.Month=12 Then
form=334.25
Else
form=form
EndIf
date=clock.day
year=clock.Year*365.25
year=year-734000
total=date+form+year

newmoon=994.25
dayssince=total-newmoon
dayssincelunar=dayssince/29.35059


Decimals = 2
dayssincelunar = Math.Floor(dayssincelunar * Math.Power(10, Decimals)) / Math.Power(10, Decimals)
dayssincelunarcomplete=dayssincelunar-Math.Floor(dayssincelunar)

Sub NumberSplit
Number = Number * 1
DotPos = Text.GetIndexOf(Number ".")
If DotPos > 0 Then
Whole = Text.GetSubText(Number 1 DotPos-1)
Fractional = Text.GetSubTextToEnd(Number DotPos+1)
Else
Whole = Number
Fractional = ""
If Whole = 0 Then
If Number >= 0 Then
Whole = ""
Else
Whole = "-"
EndIf
EndIf




endif



endsub

Number = dayssincelunarcomplete
NumberSplit()

If Fractional >= 0 And Fractional <=4 Then
phase ="newmoon"
EndIf
If Fractional >=4 And Fractional <=20 Then
phase="waxing cresent"
EndIf
If Fractional >=23 And fractional <=28 Then
phase="first quater"
EndIf
If Fractional >=29 and Fractional <=54 Then
phase="waxing gibbous"
EndIf
If Fractional >=54 And Fractional <=61 Then
phase="full moon"
EndIf
If Fractional >=61 And Fractional <=71 Then
phase="waning gibbous"
EndIf
If Fractional >=71 And Fractional <=78 Then
phase="third quater"
EndIf
If Fractional>=78 And Fractional <=96Then
phase="waning cresent"
EndIf
If Fractional >=96 And Fractional <=100 Then
phase="new moon"
EndIf


If Fractional>50 Then
morethan50 = Fractional-50
morethan50fini=morethan50*2
morethan50finished=100-morethan50fini
numberdoubled=100-numberdoubled
lessthan50finished=0
endif

if Fractional <50 Then
lessthan50finished=Fractional*2
morethan50finished=0
EndIf

finished=morethan50finished+lessthan50finished

GraphicsWindow.DrawText(20,180,"Moon Illumination=")
GraphicsWindow.DrawText(140,180,finished)
GraphicsWindow.DrawText(157,180,"%")
GraphicsWindow.DrawText(35,220,"date=")
drawdate=Clock.Date
GraphicsWindow.DrawText(75,220,drawdate)
GraphicsWindow.DrawText(15,200,"Moon phase=")
GraphicsWindow.DrawText(100,200,phase)

image1="http://i1084.photobucket.com/albums/j417/ali8bongo/blackbackground.jpg"
image2="http://i1084.photobucket.com/albums/j417/ali8bongo/moonphase8copy.jpg"
image3="http://i1084.photobucket.com/albums/j417/ali8bongo/moonphase3.jpg"
image4="http://i1084.photobucket.com/albums/j417/ali8bongo/moonphase1.jpg"
image5="http://i1084.photobucket.com/albums/j417/ali8bongo/copyofmooncompletelyfinishedcopywithlesspixelsforsmallbasiccopy.jpg"
image6="http://i1084.photobucket.com/albums/j417/ali8bongo/moonphase7copy.jpg"
image7="http://i1084.photobucket.com/albums/j417/ali8bongo/moonphase5.jpg"
image8="http://i1084.photobucket.com/albums/j417/ali8bongo/moonphase10.jpg"
If phase="newmmon" Then
GraphicsWindow.DrawImage(image1,20,20)
EndIf
If phase="waxing cresent" Then
GraphicsWindow.DrawImage(image2,30,30)
EndIf
If phase="first quater" Then
GraphicsWindow.DrawImage(image3,30,30)
EndIf
If phase="waxing gibbous" Then
GraphicsWindow.DrawImage(image4,30,30)
EndIf
If phase="full moon" Then
GraphicsWindow.DrawImage(image5,30,30)
EndIf
If phase="waning gibbous" then
GraphicsWindow.DrawImage(image6,30,30)
EndIf
If phase="third quater" Then
GraphicsWindow.DrawImage(image7,30,30)
EndIf
If phase="waning cresent" Then
GraphicsWindow.DrawImage(image8,30,30)
EndIf