moon.fsp - Frink Server Pages highlighter
[Try moon.fsp]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML LANG="en">
<HEAD>
<TITLE>Moon Locator</TITLE>
<META HTTP-EQUIV="Default-Style" CONTENT="Spaceship">
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
<LINK REL="StyleSheet" HREF="/frinkdocs/spaceship.css"
TYPE="text/css" TITLE="Spaceship">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/apeairy.css"
TYPE="text/css" TITLE="APE Airy">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style.css" TYPE="text/css"
TITLE="APE Classic">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style2.css" TYPE="text/css"
TITLE="Compact">
<LINK REL="icon" HREF="/images/futureboyicon.png" TYPE="image/png">
</HEAD>
<BODY <%= (! "$latitude
") ? "onLoad=\"requestLoc();\"" : "" %>
>
<H1>Moon Locator</H1>
<%
use ../
sun.frink
use ../
HTMLUtils.frink
North = +1
South = -1
West = +1
East = -1
if (! "
$latitude
")
{
println["""
<SCRIPT type="text/javascript">
function requestLoc()
{
navigator.geolocation.getCurrentPosition(populateLoc, errorLoc, {maximumAge:600000});
}
function populateLoc(position)
{
latField = document.getElementById("latitude");
latField.value = Math.abs(position.coords.latitude);
longField = document.getElementById("long");
longField.value = Math.abs(position.coords.longitude);
latHemiField = document.getElementById("latHemi");
if (position.coords.latitude < 0) // South?
latHemiField.selectedIndex = 1;
else
latHemiField.selectedIndex = 0;
longHemiField = document.getElementById("longHemi");
if (position.coords.longitude < 0) // West?
longHemiField.selectedIndex = 0;
else
longHemiField.selectedIndex = 1;
locFromNetworkField = document.getElementById("LocationFromNetwork");
locFromNetworkField.value = "1";
form1 = document.getElementById("form1");
form1.submit();
}
function errorLoc(error)
{
//alert(error);
}
</SCRIPT>
"""]
}
latitude = "
$latitude
" ? latitude : "39.58560"
long = "
$long
" ? long : "104.89598"
latHemi = "
$latHemi
" ? latHemi : "North"
longHemi = "
$longHemi
" ? longHemi : "West"
longHemis = ["West", "East"]
latHemis = ["North", "South"]
timezone = "
$timezone
" ? timezone : "Mountain"
locNet = "
$LocationFromNetwork
" ? "1" : ""
when = (when == "spec" ? "spec" : "now")
t = ((when == "spec") ? parseDate["
$date
$timezone
"] : now[])
fmt = ### yyyy-MM-dd HH:mm:ss ###
date = "
$date
" ? date : (now[] -> [fmt, timezone])
nowChecked = (when == "now" ? "CHECKED" : "")
specChecked = (when == "spec" ? "CHECKED" : "")
formatTime[t, now] :=
{
if now > t
return (now - t -> [0, "days", "hours", "min", "sec", 0]) + " ago"
else
return "in " + (t - now -> [0, "days", "hours", "min", "sec", 0])
}
%>
<FORM ACTION="moon.fsp" METHOD="POST" ID="form1" NAME="form1">
<TABLE>
<TR>
<TD>Latitude:
<TD><INPUT TYPE="text" NAME="latitude" ID="latitude" VALUE="$latitude
">
degrees
<TD>
<SELECT NAME="latHemi" ID="latHemi">
<% makeSelect[latHemis, latHemi] %>
</SELECT>
<TR>
<TD>Longitude:
<TD><INPUT TYPE="text" NAME="long" ID="long" VALUE="$long
">
degrees
<TD>
<SELECT NAME="longHemi" ID="longHemi">
<% makeSelect[longHemis, longHemi] %>
</SELECT>
<% if locNet
println["<TR><TD COLSPAN=\"4\">(Location obtained from browser.)"]
%>
<TR>
<TD>Timezone:
<TD COLSPAN="4">
<SELECT NAME="timezone" ID="timezone" onChange="this.form.submit();">
<% makeSelect[sort[timezones[]], timezone] %>
</SELECT>
</TD>
<TR>
<TD>Date:
<TD COLSPAN="4"><INPUT TYPE="RADIO" NAME="when" VALUE="now" ID="now" $nowChecked
onChecked="document.getElementById('date').disabled=true;"><LABEL FOR="now">Now</LABEL>
<BR><INPUT TYPE="RADIO" NAME="when" VALUE="spec" ID="spec" $specChecked
onChecked="document.getElementById('date').disabled=false;"><LABEL FOR="spec">Other date/time:</LABEL><INPUT TYPE="TEXT" NAME="date" ID="date" SIZE=20 VALUE="<%= HTMLEncode[date] %>
" onKeyUp="var item=document.getElementById('spec'); item.checked=true;">
</TABLE>
<INPUT TYPE="HIDDEN" ID="LocationFromNetwork" NAME="LocationFromNetwork" VALUE="$locNet
">
<INPUT TYPE="SUBMIT" VALUE="Recalculate">
</FORM>
<%
latNum = eval["$latitude
* $latHemi
"] degree
longNum = eval["$long
* $longHemi
"] degree
[azimuth, altitude] = refractedMoonAzimuthAltitude[t, latNum, longNum]
phaseAngle = moonPhaseAngle[t]
illum = moonIlluminatedFraction[t]
[az1, alt1] = refractedMoonAzimuthAltitude[t+5 s, latNum, longNum]
illum1 = moonIlluminatedFraction[t + 5 s]
inc = 5 s
distance = moonDistance[t]
distance1 = moonDistance[t+inc]
velocity = (distance1-distance) / inc
direction = velocity > 0 mph ? "receding" : "approaching"
velocity = abs[velocity]
limb = moonPositionAngleRelativeToZenith[t, latNum, longNum] mod circle
clockwiseLimb = 360 degrees - limb
moonset = moonset[t, latNum, longNum]
[setaz, setalt] = refractedMoonAzimuthAltitude[moonset, latNum, longNum]
moonrise = moonrise[t, latNum, longNum]
[riseaz, risealt] = refractedMoonAzimuthAltitude[moonrise, latNum, longNum]
moonTransit = moonTransit[t, latNum, longNum]
[transitAz, transitAlt] = refractedMoonAzimuthAltitude[moonTransit, latNum, longNum]
perigee = moonPerigee[t]
perigeeDist = moonDistance[perigee]
apogee = moonApogee[t]
apogeeDist = moonDistance[apogee]
sunMoonAngle = sunMoonAngularSeparation[t, latNum, longNum]
newMoon = newMoon[t]
if (newMoon < t)
{
prevNewMoon = newMoon
nextNewMoon = newMoon[t + lunarmonth]
} else
{
prevNewMoon = newMoon[t-lunarmonth]
nextNewMoon = newMoon
}
fullMoon = fullMoon[t]
if (fullMoon < t)
{
prevFullMoon = fullMoon
nextFullMoon = fullMoon[t + lunarmonth]
} else
{
prevFullMoon = fullMoon[t-lunarmonth]
nextFullMoon = fullMoon
}
%>
<P>
Time: <%= t -> timezone %>
</P>
<P>
From latitude <%= formatFix[abs[latNum], degrees, 5] + "° " + latitudeName[latNum] %>
,
longitude <%= formatFix[abs[longNum], degrees, 5] + "° " + longitudeName[longNum] %>
:
<P>
The moon is located <%= format[abs[altitude], degree, 4] %>
° <%= altitude > 0 degrees ? "above" : "below" %>
the horizon (<%= alt1 > altitude ? "rising" : "setting" %>
).
<BR>
True compass bearing:
<%= format[(azimuth + 180 degrees) mod circle, degree,4 ] %>
°
</P>
<P>
Illuminated fraction:
<%= format[illum, percent, 2 ] %>
%
(<%= illum1 > illum ? "waxing" : "waning" %>
).</P>
<P>
Angle of center of moon's bright limb: <BR><%= format[clockwiseLimb, "degrees", 1] %>
clockwise (<%= format[limb, "degrees", 1] %>
counterclockwise) from zenith.
</P>
<%
format = ### yyyy-MM-dd HH:mm:ss ###
println["<IMG SRC=\"drawmoon.fsp?date=" + URLEncode[t->[format,"UTC"], "UTF8"] + "&lat=" + (latNum -> degrees) + "&long=" + (longNum->degrees) +"\" WIDTH=100 HEIGHT=100>"]
%>
<P>
Sun-Moon angular separation: <%= format[sunMoonAngle, "degrees", 2] %>
</P>
<P>
Distance: <%= format[distance, "miles", 2] %>
, <%= direction %>
at <%= format[velocity, "mph", 3] %>
.
</P>
<TABLE BORDER=0>
<%
moonriseString = "<TR><TD>" + (moonrise < t ? "Previous" : "Next") + " moonrise:<TD> " + (moonrise -> timezone) + "<TD>(<I>" + formatTime[moonrise, t] + ")</I><TD>azimuth: " + formatFixed[(riseaz + 180 degrees) mod circle, degree, 4] + "°"
moonsetString = "<TR><TD>" + (moonset < t ? "Previous" : "Next") + " moonset:<TD> " + (moonset -> timezone) + "<TD>(<I>" + formatTime[moonset, t] + ")</I><TD>azimuth: " + formatFixed[(setaz + 180 degrees) mod circle, degree, 4] + "°"
transitString = "<TR><TD>" + (moonTransit < t ? "Previous" : "Next") + " transit:<TD> " + (moonTransit -> timezone) + "<TD>(<I>" + formatTime[moonTransit, t] + ")</I><TD>altitude: " + format[transitAlt, degrees, 4] + "°"
if moonrise < moonset
{
println[moonriseString]
println[transitString]
println[moonsetString]
if (moonset < t)
{
nextMoonrise = moonrise[t+12 hours, latNum, longNum]
println[moonriseString]
}
} else
{
println[moonsetString]
println[moonriseString]
println[transitString]
if (moonrise < t)
{
nextMoonset = moonset[t+12 hours, latNum, longNum]
[nextsetaz, nextsetalt] = refractedMoonAzimuthAltitude[nextMoonset, latNum, longNum]
nextMoonsetString = "<TR><TD>" + (nextMoonset < t ? "Previous" : "Next") + " nextMoonset:<TD> " + (nextMoonset -> timezone) + "<TD>(<I>" + formatTime[nextMoonset, t] + ")</I><TD>azimuth: " + formatFixed[(nextsetaz + 180 degrees) mod circle, degree, 4] + "°"
println[nextMoonsetString]
}
}
%>
</TABLE>
<HR>
<TABLE BORDER=0>
<%
if perigee < apogee
{
println["<TR><TD>" + (perigee < t ? "Previous" : "Next") + " perigee:<TD> " + (perigee -> timezone) + "<TD>(<I>" + formatTime[perigee, t] + ")<TD>" + format[perigeeDist,"miles",2] + "</I>"]
println["<TR><TD>" + (apogee < t ? "Previous" : "Next") + " apogee:<TD> " + (apogee -> timezone) + "<TD>(<I>" + formatTime[apogee, t] + ")<TD>" + format[apogeeDist,"miles",2] + "</I>"]
if (apogee < t)
{
nextPerigee = moonPerigee[t + lunarmonth]
nextPerigeeDist = moonDistance[nextPerigee]
println["<TR><TD>" + (nextPerigee < t ? "Previous" : "Next") + " perigee:<TD>" + (nextPerigee->timezone) + "<TD>(<I>" + formatTime[nextPerigee, t] + ")<TD>" + format[nextPerigeeDist,"miles",2] + "</I>"]
}
} else
{
println["<TR><TD>" + (apogee < t ? "Previous" : "Next") + " apogee:<TD> " + (apogee -> timezone)+ "<TD>(<I>" + formatTime[apogee, t] + ")<TD>" + format[apogeeDist,"miles",2] + "</I>"]
println["<TR><TD>" + (perigee < t ? "Previous" : "Next") + " perigee:<TD> " + (perigee -> timezone)+ "<TD>(<I>" + formatTime[perigee, t] + ")<TD>" + format[perigeeDist,"miles",2] + "</I>"]
if (perigee < t)
{
nextApogee = moonApogee[t + lunarmonth]
nextApogeeDist = moonDistance[nextApogee]
println["<TR><TD>" + (nextApogee < t ? "Previous" : "Next") + " apogee:<TD>" + (nextApogee->timezone)+ "<TD>(<I>" + formatTime[nextApogee, t] + ")<TD>" + format[nextApogeeDist,"miles",2] + "</I>"]
}
}
%>
</TABLE>
<HR>
<TABLE BORDER=0>
<TR><TD>Previous new moon:<TD><%=prevNewMoon->timezone%>
<TD><I><%=formatTime[prevNewMoon, t]%>
</I>
<TR><TD>Previous full moon:<TD><%=prevFullMoon->timezone%>
<TD><I><%=formatTime[prevFullMoon, t]%>
</I>
<TR><TD>Next new moon:<TD><%=nextNewMoon->timezone%>
<TD><I><%=formatTime[nextNewMoon, t]%>
</I>
<TR><TD>Next full moon:<TD><%=nextFullMoon->timezone%>
<TD><I><%=formatTime[nextFullMoon, t]%>
</I>
</TABLE>
<P>
<HR>
<P>
View source of <A HREF="/fsp/highlight.fsp?f=moon.fsp">This FSP
page</A> or the <A HREF="/fsp/highlight.fsp?f=drawmoon.fsp">page that draws the moon</A> or the <A HREF="/fsp/colorize.fsp?f=sun.frink">astronomical library</A> used by this code. Also see the <A HREF="sun.fsp">sun locator</A>.
</P>
<P>
<I><A HREF="mailto:eliasen@mindspring.com">Alan Eliasen</A></I> was born
<%= round[now[] - #1969-08-19 04:54 PM Mountain#, minute] -> ["days", "hours", "minutes"] %>
ago.
</P>
<P>
Powered by <A HREF="/frinkdocs/">Frink</A> and <A HREF="/frinkdocs/fspdocs.html">Frink Server Pages</A>.
</P>
</BODY>
</HTML>
[Try moon.fsp]
Alan Eliasen was born
20217 days, 15 hours, 56 minutes ago.
Back to Frink Server Pages
documentation.