-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmoonphase.cs
68 lines (59 loc) · 2.13 KB
/
moonphase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Linq;
using demo_helper;
using CosineKitty;
namespace moonphase
{
class Program
{
static string QuarterName(int quarter)
{
switch (quarter)
{
case 0: return "New Moon";
case 1: return "First Quarter";
case 2: return "Full Moon";
case 3: return "Third Quarter";
default: return "INVALID QUARTER";
}
}
static int Main(string[] args)
{
AstroTime time;
switch (args.Length)
{
case 0:
time = new AstroTime(DateTime.Now);
break;
case 1:
time = DemoHelper.ParseTime("moonphase", args[0]);
break;
default:
Console.WriteLine("USAGE: moonphase [date]");
return 1;
}
/*
Calculate the Moon's ecliptic phase angle,
which ranges from 0 to 360 degrees.
0 = new moon,
90 = first quarter,
180 = full moon,
270 = third quarter.
*/
double phase = Astronomy.MoonPhase(time);
Console.WriteLine("{0} : Moon's ecliptic phase angle = {1:F3} degrees.", time, phase);
/*
Calculate the percentage of the Moon's disc that is illuminated
from the Earth's point of view.
*/
IllumInfo illum = Astronomy.Illumination(Body.Moon, time);
Console.WriteLine("{0} : Moon's illuminated fraction = {1:F2}%.", time, 100.0 * illum.phase_fraction);
/* Find the next 10 lunar quarter phases. */
Console.WriteLine();
Console.WriteLine("The next 10 lunar quarters are:");
foreach (MoonQuarterInfo mq in Astronomy.MoonQuartersAfter(time).Take(10))
Console.WriteLine("{0} : {1}", mq.time, QuarterName(mq.quarter));
return 0;
}
}
}