Files
astronomy/demo/csharp/moonphase/moonphase.cs
Don Cross 6abce518f6 C#: added iterator helper functions
Added the following iterator functions that wrap
search/next pairs of functions:

    GlobalSolarEclipsesAfter
    LocalSolarEclipsesAfter
    LunarApsidesAfter
    LunarEclipsesAfter
    MoonNodesAfter
    MoonQuartersAfter
    PlanetApsidesAfter
    TransitsAfter

I updated the following C# demos:

    moonphase.cs     ==> MoonQuartersAfter
    lunar_eclipse.cs ==> LunarEclipsesAfter

Fixed an issue in the C# Markdown generator
so that it can now handle generic types like
`IEnumerable<MoonQuarterInfo>`.
2022-05-07 13:02:42 -04:00

69 lines
2.1 KiB
C#

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;
}
}
}