|
děkuji, to je právě jedna z věcí co nechápu... zbytek kódu jsem nějak přelouskal, v Javě jsou proměnné definovány Var, to se dá taky vyzkoumat...problém je právě v tom cyklu, také nechápu jak to má fungovat a seriály o Javascriptu mi také moc nepomohly, jestli se chcete podívet na celý zdroják je zde, jedná se o výpočet fáze měsíce.
<!--
// INVJD -- Find year, month, day, corresponding to given JD#
// and store results in array.
function jyear(td) {
with(Math){
var z, f, a, alpha, b, c, d, e, mm;
td += 0.5;
z = floor(td);
f = td - z;
if (z < 2299161.0) {a = z; }
else {
alpha = floor((z - 1867216.25) / 36524.25);
a = z + 1 + alpha - floor(alpha / 4);
}
b = a + 1524;
c = floor((b - 122.1) / 365.25);
d = floor(365.25 * c);
e = floor((b - d) / 30.6001);
mm = floor((e < 14) ? (e - 1) : (e - 13));
return new Array(
floor((mm > 2) ? (c - 4716) : (c - 4715)),
mm,
floor(b - d - floor(30.6001 * e) + f)
);
}
}
/* JF2HMS -- Convert Julian date fraction into hour, minutes, and seconds,
returned as a three-element array. */
function jhms(j) {
with(Math){
var ij;
j += 0.5; /* Astronomical to civil */
ij = (j - floor(j)) * 86400.0;
return new Array(
floor(ij / 3600),
floor((ij / 60) % 60),
floor(ij % 60));
}
}
/* DTR -- Degrees to radians. */
function dtr(d)
{
with(Math){
return (d * PI) / 180.0;
}
}
/* FIXANGLE -- Range reduce angle in degrees. */
function fixangle(a)
{
with(Math){
return a - 360.0 * (floor((a) / 360.0));
}
}
/* PAD -- Pad a string to a given length with a given fill character. */
function pad(str, howlong, padwith) {
var s = str.toString();
while (s.length < howlong) {
s = padwith + s;
}
return s;
}
/* EDATE -- Edit date and time to application specific format. */
var Months = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
);
function edate(j) {
var date, time;
j += (30.0 / 86400); // Round to nearest minute
date = jyear(j);
time = jhms(j);
return Months[date[1] - 1] + " " + pad(date[2], 2, " ") + " " +
pad(time[0], 2, " ") + ":" + pad(time[1], 2, "0");
}
/* TRUEPHASE -- Given a K value used to determine the mean phase of
the new moon, and a phase selector (0.0, 0.25, 0.5,
0.75), obtain the true, corrected phase time. */
function dsin(x) {
with (Math){
return sin(dtr(x));
}
}
function dcos(x) {
with(Math){
return Math.cos(dtr(x));
}
}
function truephase(k, phase)
{
with(Math){
var t, t2, t3, pt, m, mprime, f,
SynMonth = 29.53058868; /* Synodic month (mean time from new to next new Moon) */
k += phase; /* Add phase to new moon time */
t = k / 1236.85; /* Time in Julian centuries since 1900 January 0.5 */
t2 = t * t; /* Square for frequent use */
t3 = t2 * t; /* Cube for frequent use */
pt = 2415020.75933 /* Mean time of phase */
+ SynMonth * k
+ 0.0001178 * t2
- 0.000000155 * t3
+ 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
m = 359.2242 /* Sun's mean anomaly */
+ 29.10535608 * k
- 0.0000333 * t2
- 0.00000347 * t3;
mprime = 306.0253 /* Moon's mean anomaly */
+ 385.81691806 * k
+ 0.0107306 * t2
+ 0.00001236 * t3;
f = 21.2964 /* Moon's argument of latitude */
+ 390.67050646 * k
- 0.0016528 * t2
- 0.00000239 * t3;
if ((phase < 0.01) || (Math.abs(phase - 0.5) < 0.01)) {
/* Corrections for New and Full Moon */
pt += (0.1734 - 0.000393 * t) * dsin(m)
+ 0.0021 * dsin(2 * m)
- 0.4068 * dsin(mprime)
+ 0.0161 * dsin(2 * mprime)
- 0.0004 * dsin(3 * mprime)
+ 0.0104 * dsin(2 * f)
- 0.0051 * dsin(m + mprime)
- 0.0074 * dsin(m - mprime)
+ 0.0004 * dsin(2 * f + m)
- 0.0004 * dsin(2 * f - m)
- 0.0006 * dsin(2 * f + mprime)
+ 0.0010 * dsin(2 * f - mprime)
+ 0.0005 * dsin(m + 2 * mprime);
} else if ((abs(phase - 0.25) < 0.01 || (abs(phase - 0.75) < 0.01))) {
pt += (0.1721 - 0.0004 * t) * dsin(m)
+ 0.0021 * dsin(2 * m)
- 0.6280 * dsin(mprime)
+ 0.0089 * dsin(2 * mprime)
- 0.0004 * dsin(3 * mprime)
+ 0.0079 * dsin(2 * f)
- 0.0119 * dsin(m + mprime)
- 0.0047 * dsin(m - mprime)
+ 0.0003 * dsin(2 * f + m)
- 0.0004 * dsin(2 * f - m)
- 0.0006 * dsin(2 * f + mprime)
+ 0.0021 * dsin(2 * f - mprime)
+ 0.0003 * dsin(m + 2 * mprime)
+ 0.0004 * dsin(m - 2 * mprime)
- 0.0003 * dsin(2 * m + mprime);
if (phase < 0.5)
/* First quarter correction */
pt += 0.0028 - 0.0004 * dcos(m) + 0.0003 * dcos(mprime);
else
/* Last quarter correction */
pt += -0.0028 + 0.0004 * dcos(m) - 0.0003 * dcos(mprime);
}
return pt;
}
}
// GEN -- Update the tables when an action button is pressed
function gen() {
with(Math){
var v, sk, kr, l, perigee, s, Itemlen = 36,
dat, evt, m = 0, epad, pchar, phnear,
pmin = Number.MAX_VALUE, pminx = 0,
pmax = Number.MIN_VALUE, pmaxx = 0,
yrange, centile, TOLERANCE = 0.01, k1, mtime, minx, phaset,
Pitemlen = 25;
window.status = "Calculating..";
year = document.calc.year.value;
sk = floor((year - 1999.97) * 13.2555);
dat = new Array();
evt = new Array();
phaset = new Array();
yrange = pmax - pmin;
// Tabulate new and full moons surrounding the year
k1 = floor((year - 1900) * 12.3685) - 4;
minx = 0;
for (l = 0; true; l++) {
mtime = truephase(k1, (l & 1) * 0.5);
date = jyear(mtime);
if (date[0] >= year) {
minx++;
}
phaset[minx] = mtime * ((l & 1) == 0 ? -1 : 1);
if (date[0] > year) {
minx++;
break;
}
k1 += l & 1;
}
// Generate Moon phase table
v = " New Full\n";
s = "";
for (l = 0; l < minx; l++) {
mp = phaset[l];
if (mp < 0) {
mp = - mp;
} else {
if (s.length == 0) {
s = pad(s, Pitemlen, " ");
}
}
s += " " + jyear(mp)[0] + " " + edate(mp);
if (s.length < Pitemlen) {
while (s.length < Pitemlen) {
s += " ";
}
} else {
v += s + "\n";
s = "";
}
}
if (s.length > 0) {
v += s + "\n";
}
document.calc.phases.value = v;
window.status = "Done.";
}
}
// -->
|